Merge lp:~gary/zc.buildout/python-support-9-relative-paths into lp:~gary/zc.buildout/python-support

Proposed by Gary Poster
Status: Merged
Merged at revision: not available
Proposed branch: lp:~gary/zc.buildout/python-support-9-relative-paths
Merge into: lp:~gary/zc.buildout/python-support
Diff against target: 211 lines (+96/-11)
5 files modified
src/zc/buildout/bootstrap.txt (+1/-1)
src/zc/buildout/buildout.py (+9/-1)
src/zc/buildout/buildout.txt (+80/-3)
src/zc/buildout/easy_install.py (+2/-2)
src/zc/buildout/easy_install.txt (+4/-4)
To merge this branch: bzr merge lp:~gary/zc.buildout/python-support-9-relative-paths
Reviewer Review Type Date Requested Status
Francis J. Lacoste (community) Approve
Review via email: mp+23696@code.launchpad.net

Description of the change

This change introduces the ``relative-paths`` option, which Jim Fulton added to zc.recipe.egg and I carried over to z3c.recipe.scripts, to buildout proper. It affects the creation of the buildout script, as the test shows.

I am proposing it for merging into python-support, which is the zc.buildout fork I am currently maintaining for Launchpad.

To post a comment you must log in.
Revision history for this message
Francis J. Lacoste (flacoste) wrote :

Looks good but there are two things I don't understand.

1) From where the unzip and use-dependancy-links documentation comes from?

2) Why do you need to move import site to after the path = sys.path[0] initialization.

And I don't see any implementation related to relative-paths? Is the diff missing something?

Revision history for this message
Francis J. Lacoste (flacoste) :
review: Needs Information
Revision history for this message
Gary Poster (gary) wrote :

> Looks good but there are two things I don't understand.
>
> 1) From where the unzip and use-dependancy-links documentation comes from?

This is a darn good question. I looked into it a bit and I don't have a full answer.

The documentation comes from previous branches in this work--maybe as far back as python-support-2. The question in my mind is...why was this not merged before? I don't know. You can see it is a part of the previous branches in lines 2417-2435 of http://bazaar.launchpad.net/%7Egary/zc.buildout/python-support-8-support-subprocess/annotate/head%3A/src/zc/buildout/buildout.txt . It should have been merged long before.

Jim has not merged the pertinent branch, so I don't see how it could be some re-insertion.

The only thing I can figure is that it is some bzr + svn oddity.

In any case, the documentation should in fact be there, and it is not duplicated. It's a good change, even if it shouldn't really be here.

>
> 2) Why do you need to move import site to after the path = sys.path[0]
> initialization.

It's a safety measure. One of the main points of the site module is to manipulate the path. Let's get the path we want as soon as possible, before the site module has its way with the path.

> And I don't see any implementation related to relative-paths? Is the diff
> missing something?

No. The implementation has...four parts, I would say.

1) We set the default value here (line 21 in the diff as of this writing: ``'relative-paths': 'false',``

2) We take the value in consideration for the only script that buildout generates itself, bin/buildout, in this branch (lines 29-39 of the current diff).

3) We offer recipes a ``relative_paths`` argument to the ``scripts`` and ``site_package_safe_scripts`` functions provided by zc.buildout.easy_install. This was already done.

4) Recipes that generate files that might have paths should use the ``relative_paths`` argument described above. zc.recipe.egg and z3c.recipe.scripts already do this. Other recipes do not (e.g., z3c.recipe.i18n).

Therefore, the big change we have here is that buildout actually starts to recognize the option in itself that zc.recipe.egg had already been looking for.

Revision history for this message
Francis J. Lacoste (flacoste) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/zc/buildout/bootstrap.txt'
2--- src/zc/buildout/bootstrap.txt 2010-02-13 00:39:20 +0000
3+++ src/zc/buildout/bootstrap.txt 2010-04-19 19:29:12 +0000
4@@ -47,7 +47,7 @@
5 X...
6 d zc.buildout-...egg
7
8-Now trying the `--version` option, that let you define a version for
9+Now we will try the `--version` option, which lets you define a version for
10 `zc.buildout`. If not provided, bootstrap will look for the latest one.
11
12 Let's try with an unknown version::
13
14=== modified file 'src/zc/buildout/buildout.py'
15--- src/zc/buildout/buildout.py 2010-03-19 19:14:02 +0000
16+++ src/zc/buildout/buildout.py 2010-04-19 19:29:12 +0000
17@@ -129,6 +129,7 @@
18 'parts-directory': 'parts',
19 'prefer-final': 'false',
20 'python': 'buildout',
21+ 'relative-paths': 'false',
22 'socket-timeout': '',
23 'unzip': 'false',
24 'use-dependency-links': 'true',
25@@ -411,9 +412,16 @@
26 partsdir = os.path.join(options['parts-directory'], 'buildout')
27 if not os.path.exists(partsdir):
28 os.mkdir(partsdir)
29+ # (Honor the relative-paths option.)
30+ relative_paths = options.get('relative-paths', 'false')
31+ if relative_paths == 'true':
32+ relative_paths = options['directory']
33+ else:
34+ assert relative_paths == 'false'
35+ relative_paths = ''
36 zc.buildout.easy_install.sitepackage_safe_scripts(
37 options['bin-directory'], ws, options['executable'], partsdir,
38- reqs=['zc.buildout'])
39+ reqs=['zc.buildout'], relative_paths=relative_paths)
40
41 init = bootstrap
42
43
44=== modified file 'src/zc/buildout/buildout.txt'
45--- src/zc/buildout/buildout.txt 2010-03-19 18:12:23 +0000
46+++ src/zc/buildout/buildout.txt 2010-04-19 19:29:12 +0000
47@@ -767,8 +767,9 @@
48 DEFAULT_VALUE
49 python= buildout
50 DEFAULT_VALUE
51+ relative-paths= false
52+ DEFAULT_VALUE
53 socket-timeout=
54- DEFAULT_VALUE
55 unzip= false
56 DEFAULT_VALUE
57 use-dependency-links= true
58@@ -2286,6 +2287,7 @@
59 parts-directory = /sample-buildout/parts
60 prefer-final = false
61 python = buildout
62+ relative-paths = false
63 socket-timeout =
64 unzip = false
65 use-dependency-links = true
66@@ -2349,6 +2351,33 @@
67 Python executable. By default, the buildout section defines the
68 default Python as the Python used to run the buildout.
69
70+relative-paths
71+ The paths generated by zc.buildout are absolute by default, and this
72+ option is ``false``. However, if you set this value to be ``true``,
73+ bin/buildout will be generated with code that makes the paths relative.
74+ Some recipes, such as zc.recipe.egg and z3c.recipe.scripts, honor this
75+ value as well.
76+
77+unzip
78+ By default, zc.buildout doesn't unzip zip-safe eggs ("unzip = false").
79+ This follows the policy followed by setuptools itself. Experience shows
80+ this policy to to be inconvenient. Zipped eggs make debugging more
81+ difficult and often import more slowly. You can include an unzip option in
82+ the buildout section to change the default unzipping policy ("unzip =
83+ true").
84+
85+use-dependency-links
86+ By default buildout will obey the setuptools dependency_links metadata
87+ when it looks for dependencies. This behavior can be controlled with
88+ the use-dependency-links buildout option::
89+
90+ [buildout]
91+ ...
92+ use-dependency-links = false
93+
94+ The option defaults to true. If you set it to false, then dependency
95+ links are only looked for in the locations specified by find-links.
96+
97 verbosity
98 A log-level adjustment. Typically, this is set via the -q and -v
99 command-line options.
100@@ -2395,8 +2424,56 @@
101 directory if the original buildout had develop eggs for either
102 buildout or setuptools.)
103
104-Note that the buildout script was installed but not run. To run
105-the buildout, we'd have to run the installed buildout script.
106+If relative-paths is ``true``, the buildout script uses relative paths.
107+
108+ >>> write(sample_bootstrapped, 'setup.cfg',
109+ ... '''
110+ ... [buildout]
111+ ... relative-paths = true
112+ ... parts =
113+ ... ''')
114+
115+ >>> print system(buildout
116+ ... +' -c'+os.path.join(sample_bootstrapped, 'setup.cfg')
117+ ... +' bootstrap'),
118+ Generated script '/sample-bootstrapped/bin/buildout'.
119+
120+ >>> buildout_script = join(sample_bootstrapped, 'bin', 'buildout')
121+ >>> import sys
122+ >>> if sys.platform.startswith('win'):
123+ ... buildout_script += '-script.py'
124+ >>> print open(buildout_script).read() # doctest: +ELLIPSIS
125+ #!... -S
126+ <BLANKLINE>
127+ import os
128+ <BLANKLINE>
129+ join = os.path.join
130+ base = os.path.dirname(os.path.abspath(os.path.realpath(__file__)))
131+ base = os.path.dirname(base)
132+ <BLANKLINE>
133+ import sys
134+ sys.path[0:0] = [
135+ join(base, 'parts/buildout'),
136+ ]
137+ <BLANKLINE>
138+ <BLANKLINE>
139+ import os
140+ path = sys.path[0]
141+ if os.environ.get('PYTHONPATH'):
142+ path = os.pathsep.join([path, os.environ['PYTHONPATH']])
143+ os.environ['PYTHONPATH'] = path
144+ import site # imports custom buildout-generated site.py
145+ <BLANKLINE>
146+ import zc.buildout.buildout
147+ <BLANKLINE>
148+ if __name__ == '__main__':
149+ zc.buildout.buildout.main()
150+ <BLANKLINE>
151+
152+
153+Note that, in the above two examples, the buildout script was installed
154+but not run. To run the buildout, we'd have to run the installed
155+buildout script.
156
157 If we have an existing buildout that already has a buildout.cfg, we'll
158 normally use the bootstrap command instead of init. It will complain
159
160=== modified file 'src/zc/buildout/easy_install.py'
161--- src/zc/buildout/easy_install.py 2010-03-19 19:14:02 +0000
162+++ src/zc/buildout/easy_install.py 2010-04-19 19:29:12 +0000
163@@ -1199,12 +1199,12 @@
164 return generated
165
166 _script_initialization_template = '''
167-import site # imports custom buildout-generated site.py
168 import os
169-path = %(site_py_dest)r
170+path = sys.path[0]
171 if os.environ.get('PYTHONPATH'):
172 path = os.pathsep.join([path, os.environ['PYTHONPATH']])
173 os.environ['PYTHONPATH'] = path
174+import site # imports custom buildout-generated site.py
175 %(script_initialization)s'''
176
177 # Utilities for the script generation functions.
178
179=== modified file 'src/zc/buildout/easy_install.txt'
180--- src/zc/buildout/easy_install.txt 2010-03-11 02:49:36 +0000
181+++ src/zc/buildout/easy_install.txt 2010-04-19 19:29:12 +0000
182@@ -1498,12 +1498,12 @@
183 ]
184 <BLANKLINE>
185 <BLANKLINE>
186- import site # imports custom buildout-generated site.py
187 import os
188- path = '/interpreter/parts/interpreter'
189+ path = sys.path[0]
190 if os.environ.get('PYTHONPATH'):
191 path = os.pathsep.join([path, os.environ['PYTHONPATH']])
192 os.environ['PYTHONPATH'] = path
193+ import site # imports custom buildout-generated site.py
194 <BLANKLINE>
195 import eggrecipedemo
196 <BLANKLINE>
197@@ -1542,12 +1542,12 @@
198 '/interpreter/parts/interpreter',
199 ]
200 <BLANKLINE>
201- import site # imports custom buildout-generated site.py
202 import os
203- path = '/interpreter/parts/interpreter'
204+ path = sys.path[0]
205 if os.environ.get('PYTHONPATH'):
206 path = os.pathsep.join([path, os.environ['PYTHONPATH']])
207 os.environ['PYTHONPATH'] = path
208+ import site # imports custom buildout-generated site.py
209 import os
210 os.chdir("foo")
211 <BLANKLINE>

Subscribers

People subscribed via source and target branches

to all changes: