Merge lp:~ted/snapcraft/cmdline-exec into lp:~snappy-dev/snapcraft/core

Proposed by Ted Gould
Status: Merged
Approved by: Sergio Schvezov
Approved revision: 174
Merged at revision: 183
Proposed branch: lp:~ted/snapcraft/cmdline-exec
Merge into: lp:~snappy-dev/snapcraft/core
Diff against target: 82 lines (+36/-2)
2 files modified
snapcraft/plugins/python2_project.py (+18/-1)
snapcraft/plugins/python3_project.py (+18/-1)
To merge this branch: bzr merge lp:~ted/snapcraft/cmdline-exec
Reviewer Review Type Date Requested Status
Sergio Schvezov Approve
Ted Gould Pending
Review via email: mp+271698@code.launchpad.net

This proposal supersedes a proposal from 2015-09-18.

Commit message

Wrap setup.py calls to configure the shebang writer

To post a comment you must log in.
lp:~ted/snapcraft/cmdline-exec updated
173. By Ted Gould

Merge trunk

174. By Ted Gould

Import tempfile

Revision history for this message
Sergio Schvezov (sergiusens) wrote :

works like a charm, I'll follow up with a 'config' update branch.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'snapcraft/plugins/python2_project.py'
2--- snapcraft/plugins/python2_project.py 2015-09-17 15:03:38 +0000
3+++ snapcraft/plugins/python2_project.py 2015-09-18 18:06:30 +0000
4@@ -15,6 +15,7 @@
5 # along with this program. If not, see <http://www.gnu.org/licenses/>.
6
7 import os
8+import tempfile
9
10 import snapcraft
11
12@@ -33,12 +34,28 @@
13 # and be in the PYTHONPATH. It's harmless if setuptools isn't
14 # used.
15 os.makedirs(self.dist_packages_dir, exist_ok=True)
16+ setuptemp = self.copy_setup()
17
18 return self.run(
19- ['python2', 'setup.py', 'install', '--install-layout=deb',
20+ ['python2', setuptemp.name, 'install', '--install-layout=deb',
21 '--prefix={}/usr'.format(self.installdir)])
22
23 @property
24 def dist_packages_dir(self):
25 return os.path.join(
26 self.installdir, 'usr', 'lib', 'python2.7', 'dist-packages')
27+
28+ # Takes the setup.py file and puts a couple little gems on the
29+ # front to make things work better.
30+ def copy_setup(self):
31+ setupout = tempfile.NamedTemporaryFile(mode='w+')
32+
33+ setupout.write('import sys\n')
34+ setupout.write('sys.executable = "usr/bin/python2"\n\n')
35+
36+ with open('setup.py', 'r') as f:
37+ for line in f:
38+ setupout.write(line)
39+
40+ setupout.flush()
41+ return setupout
42
43=== modified file 'snapcraft/plugins/python3_project.py'
44--- snapcraft/plugins/python3_project.py 2015-09-18 03:23:38 +0000
45+++ snapcraft/plugins/python3_project.py 2015-09-18 18:06:30 +0000
46@@ -15,6 +15,7 @@
47 # along with this program. If not, see <http://www.gnu.org/licenses/>.
48
49 import os
50+import tempfile
51
52 import snapcraft
53
54@@ -37,11 +38,27 @@
55 # and be in the PYTHONPATH. It's harmless if setuptools isn't
56 # used.
57 os.makedirs(self.dist_packages_dir, exist_ok=True)
58+ setuptemp = self.copy_setup()
59 return self.run(
60- ['python3', 'setup.py', 'install', '--install-layout=deb',
61+ ['python3', setuptemp.name, 'install', '--install-layout=deb',
62 '--prefix=%s/usr' % self.installdir])
63
64 @property
65 def dist_packages_dir(self):
66 return os.path.join(
67 self.installdir, 'usr', 'lib', 'python3', 'dist-packages')
68+
69+ # Takes the setup.py file and puts a couple little gems on the
70+ # front to make things work better.
71+ def copy_setup(self):
72+ setupout = tempfile.NamedTemporaryFile(mode='w+')
73+
74+ setupout.write('import sys\n')
75+ setupout.write('sys.executable = "usr/bin/python3"\n\n')
76+
77+ with open('setup.py', 'r') as f:
78+ for line in f:
79+ setupout.write(line)
80+
81+ setupout.flush()
82+ return setupout

Subscribers

People subscribed via source and target branches

to all changes: