Merge lp:~ted/snapcraft/multi-python-version into lp:~snappy-dev/snapcraft/core

Proposed by Ted Gould on 2015-09-18
Status: Merged
Approved by: Sergio Schvezov on 2015-09-22
Approved revision: 184
Merged at revision: 199
Proposed branch: lp:~ted/snapcraft/multi-python-version
Merge into: lp:~snappy-dev/snapcraft/core
Diff against target: 107 lines (+38/-6)
5 files modified
snapcraft/__init__.py (+9/-0)
snapcraft/common.py (+11/-0)
snapcraft/plugins/python2.py (+7/-3)
snapcraft/plugins/python2_project.py (+5/-1)
snapcraft/plugins/python3.py (+6/-2)
To merge this branch: bzr merge lp:~ted/snapcraft/multi-python-version
Reviewer Review Type Date Requested Status
Sergio Schvezov 2015-09-18 Approve on 2015-09-22
Review via email: mp+271716@code.launchpad.net

Commit Message

Choose the python path based on the version installed

Description of the Change

So many versions of Python, so little time.

To post a comment you must log in.
184. By Ted Gould on 2015-09-18

Merging trunk

Sergio Schvezov (sergiusens) wrote :

Looks good, the only thing missing is that one of the pythonX modules is missing the logic.

It's there for python2, python2-project and python3 but not python3-project.

Also raises a question about the long term plan for these plugins and the duplication they are creating, right now it is just a means to avoid a STAGE_PACKAGE dep ;-)

review: Needs Fixing
Ted Gould (ted) wrote :

The reason that python3-project is missing the logic is because it doesn't need it :-) The only path for it is "python3" not the full version. Cool fix in the updated version of Python, but doesn't seem to work for the others.

Sergio Schvezov (sergiusens) wrote :

This is awesome!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'snapcraft/__init__.py'
2--- snapcraft/__init__.py 2015-09-17 14:14:14 +0000
3+++ snapcraft/__init__.py 2015-09-18 21:52:07 +0000
4@@ -65,8 +65,17 @@
5 cwd = self.builddir
6 if True:
7 print(' '.join(cmd))
8+ self.makedirs(cwd)
9 return snapcraft.common.run(cmd, cwd=cwd, **kwargs)
10
11+ def run_output(self, cmd, cwd=None, **kwargs):
12+ if cwd is None:
13+ cwd = self.builddir
14+ if True:
15+ print(' '.join(cmd))
16+ self.makedirs(cwd)
17+ return snapcraft.common.run_output(cmd, cwd=cwd, **kwargs)
18+
19 def isurl(self, url):
20 return snapcraft.common.isurl(url)
21
22
23=== modified file 'snapcraft/common.py'
24--- snapcraft/common.py 2015-09-17 18:02:05 +0000
25+++ snapcraft/common.py 2015-09-18 21:52:07 +0000
26@@ -49,6 +49,17 @@
27 return subprocess.call(['/bin/sh', f.name] + cmd, **kwargs) == 0
28
29
30+def run_output(cmd, **kwargs):
31+ assert isinstance(cmd, list), "run command must be a list"
32+ # FIXME: This is gross to keep writing this, even when env is the same
33+ with tempfile.NamedTemporaryFile(mode='w+') as f:
34+ f.write(assemble_env())
35+ f.write('\n')
36+ f.write('exec $*')
37+ f.flush()
38+ return subprocess.check_output(['/bin/sh', f.name] + cmd, **kwargs).decode('utf8').strip()
39+
40+
41 def fatal():
42 sys.exit(1)
43
44
45=== modified file 'snapcraft/plugins/python2.py'
46--- snapcraft/plugins/python2.py 2015-09-17 15:14:49 +0000
47+++ snapcraft/plugins/python2.py 2015-09-18 21:52:07 +0000
48@@ -44,7 +44,7 @@
49
50 def env(self, root):
51 return ["PYTHONPATH=%s" % os.path.join(
52- root, 'usr', 'lib', 'python2.7', 'dist-packages')]
53+ root, 'usr', 'lib', self.python_version, 'dist-packages')]
54
55 def pull(self):
56 # A nice idea here would be to be asking setup tools
57@@ -52,8 +52,12 @@
58 # prefix sadly
59
60 if self.requirements and not (self.run(
61- ['ln', '-s', os.path.join(self.installdir, 'usr', 'lib', 'python2.7', 'dist-packages'), os.path.join(self.installdir, 'usr', 'lib', 'python2.7', 'site-packages')]) and self.run(
62+ ['ln', '-s', os.path.join(self.installdir, 'usr', 'lib', self.python_version, 'dist-packages'), os.path.join(self.installdir, 'usr', 'lib', self.python_version, 'site-packages')]) and self.run(
63 ['python2', os.path.join(self.installdir, 'usr', 'bin', 'easy_install'), '--prefix', os.path.join(self.installdir, 'usr'), 'pip']) and self.run(
64- ['python2', os.path.join(self.installdir, 'usr', 'bin', 'pip2'), 'install', '--target', os.path.join(self.installdir, 'usr', 'lib', 'python2.7', 'site-packages'), '--requirement', os.path.join(os.getcwd(), self.requirements)])):
65+ ['python2', os.path.join(self.installdir, 'usr', 'bin', 'pip2'), 'install', '--target', os.path.join(self.installdir, 'usr', 'lib', self.python_version, 'site-packages'), '--requirement', os.path.join(os.getcwd(), self.requirements)])):
66 return False
67 return True
68+
69+ @property
70+ def python_version(self):
71+ return self.run_output(['pyversions', '-i'])
72
73=== modified file 'snapcraft/plugins/python2_project.py'
74--- snapcraft/plugins/python2_project.py 2015-09-18 18:06:01 +0000
75+++ snapcraft/plugins/python2_project.py 2015-09-18 21:52:07 +0000
76@@ -43,7 +43,11 @@
77 @property
78 def dist_packages_dir(self):
79 return os.path.join(
80- self.installdir, 'usr', 'lib', 'python2.7', 'dist-packages')
81+ self.installdir, 'usr', 'lib', self.python_version, 'dist-packages')
82+
83+ @property
84+ def python_version(self):
85+ return self.run_output(['pyversions', '-i'])
86
87 # Takes the setup.py file and puts a couple little gems on the
88 # front to make things work better.
89
90=== modified file 'snapcraft/plugins/python3.py'
91--- snapcraft/plugins/python3.py 2015-09-17 15:14:49 +0000
92+++ snapcraft/plugins/python3.py 2015-09-18 21:52:07 +0000
93@@ -54,8 +54,12 @@
94 # prefix sadly
95
96 if self.requirements and not (self.run(
97- ['ln', '-s', os.path.join(self.installdir, 'usr', 'lib', 'python3', 'dist-packages'), os.path.join(self.installdir, 'usr', 'lib', 'python3.4', 'site-packages')]) and self.run(
98+ ['ln', '-s', os.path.join(self.installdir, 'usr', 'lib', 'python3', 'dist-packages'), os.path.join(self.installdir, 'usr', 'lib', self.python_version, 'site-packages')]) and self.run(
99 ['python3', os.path.join(self.installdir, 'usr', 'bin', 'easy_install3'), '--prefix', os.path.join(self.installdir, 'usr'), 'pip']) and self.run(
100- ['python3', os.path.join(self.installdir, 'usr', 'bin', 'pip3'), 'install', '--target', os.path.join(self.installdir, 'usr', 'lib', 'python3.4', 'site-packages'), '--requirement', os.path.join(os.getcwd(), self.requirements)])):
101+ ['python3', os.path.join(self.installdir, 'usr', 'bin', 'pip3'), 'install', '--target', os.path.join(self.installdir, 'usr', 'lib', self.python_version, 'site-packages'), '--requirement', os.path.join(os.getcwd(), self.requirements)])):
102 return False
103 return True
104+
105+ @property
106+ def python_version(self):
107+ return self.run_output(['py3versions', '-i'])

Subscribers

People subscribed via source and target branches

to all changes: