~longsleep/snapcraft/snapcraft-debs-plugin

« back to all changes in this revision

Viewing changes to snapcraft/plugins/python3_project.py

  • Committer: Snappy Tarmac
  • Author(s): Ted Gould
  • Date: 2015-09-18 21:02:50 UTC
  • mfrom: (168.2.6 cmdline-exec)
  • Revision ID: snappy_tarmac-20150918210250-7ipgnonaah5262le
Wrap setup.py calls to configure the shebang writer by ted approved by sergiusens

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
16
 
17
17
import os
 
18
import tempfile
18
19
 
19
20
import snapcraft
20
21
 
37
38
        # and be in the PYTHONPATH. It's harmless if setuptools isn't
38
39
        # used.
39
40
        os.makedirs(self.dist_packages_dir, exist_ok=True)
 
41
        setuptemp = self.copy_setup()
40
42
        return self.run(
41
 
            ['python3', 'setup.py', 'install', '--install-layout=deb',
 
43
            ['python3', setuptemp.name, 'install', '--install-layout=deb',
42
44
             '--prefix=%s/usr' % self.installdir])
43
45
 
44
46
    @property
45
47
    def dist_packages_dir(self):
46
48
        return os.path.join(
47
49
            self.installdir, 'usr', 'lib', 'python3', 'dist-packages')
 
50
 
 
51
    # Takes the setup.py file and puts a couple little gems on the
 
52
    # front to make things work better.
 
53
    def copy_setup(self):
 
54
        setupout = tempfile.NamedTemporaryFile(mode='w+')
 
55
 
 
56
        setupout.write('import sys\n')
 
57
        setupout.write('sys.executable = "usr/bin/python3"\n\n')
 
58
 
 
59
        with open('setup.py', 'r') as f:
 
60
            for line in f:
 
61
                setupout.write(line)
 
62
 
 
63
        setupout.flush()
 
64
        return setupout