Commit 8564e325 authored by Jim Fulton's avatar Jim Fulton

Fixed: initialization code wasn't included in interpeter scripts.

parent 0ea7257d
...@@ -4,7 +4,9 @@ Change History ...@@ -4,7 +4,9 @@ Change History
2.0.0b1 (2013-01-??) 2.0.0b1 (2013-01-??)
==================== ====================
Fixed: Macro inheritance bug, https://github.com/buildout/buildout/pull/37 Fixed: initialization code wasn't included in interpeter scripts.
Fixed: macro inheritance bug, https://github.com/buildout/buildout/pull/37
2.0.0a7 (2013-01-12) 2.0.0a7 (2013-01-12)
==================== ====================
......
...@@ -922,7 +922,7 @@ def scripts(reqs, working_set, executable, dest=None, ...@@ -922,7 +922,7 @@ def scripts(reqs, working_set, executable, dest=None,
if interpreter: if interpreter:
sname = os.path.join(dest, interpreter) sname = os.path.join(dest, interpreter)
spath, rpsetup = _relative_path_and_setup(sname, path, relative_paths) spath, rpsetup = _relative_path_and_setup(sname, path, relative_paths)
generated.extend(_pyscript(spath, sname, rpsetup)) generated.extend(_pyscript(spath, sname, rpsetup, initialization))
return generated return generated
...@@ -1043,7 +1043,9 @@ def _create_script(contents, dest): ...@@ -1043,7 +1043,9 @@ def _create_script(contents, dest):
win32_exe = win32_exe[:-7] # remove "-script" win32_exe = win32_exe[:-7] # remove "-script"
win32_exe = win32_exe + '.exe' # add ".exe" win32_exe = win32_exe + '.exe' # add ".exe"
new_data = pkg_resources.resource_string('setuptools', 'cli.exe') new_data = pkg_resources.resource_string('setuptools', 'cli.exe')
if not os.path.exists(win32_exe) or (open(win32_exe, 'rb').read() != new_data): if (not os.path.exists(win32_exe) or
(open(win32_exe, 'rb').read() != new_data)
):
# Only write it if it's different. # Only write it if it's different.
open(win32_exe, 'wb').write(new_data) open(win32_exe, 'wb').write(new_data)
generated.append(win32_exe) generated.append(win32_exe)
...@@ -1096,7 +1098,7 @@ sys.path[0:0] = [ ...@@ -1096,7 +1098,7 @@ sys.path[0:0] = [
%(original_content)s''' %(original_content)s'''
def _pyscript(path, dest, rsetup): def _pyscript(path, dest, rsetup, initialization=''):
generated = [] generated = []
script = dest script = dest
if is_win32: if is_win32:
...@@ -1108,6 +1110,7 @@ def _pyscript(path, dest, rsetup): ...@@ -1108,6 +1110,7 @@ def _pyscript(path, dest, rsetup):
python = python, python = python,
path = path, path = path,
relative_paths_setup = rsetup, relative_paths_setup = rsetup,
initialization=initialization,
) )
changed = not (os.path.exists(dest) and open(dest).read() == contents) changed = not (os.path.exists(dest) and open(dest).read() == contents)
...@@ -1138,6 +1141,7 @@ import sys ...@@ -1138,6 +1141,7 @@ import sys
sys.path[0:0] = [ sys.path[0:0] = [
%(path)s, %(path)s,
] ]
%(initialization)s
_interactive = True _interactive = True
if len(sys.argv) > 1: if len(sys.argv) > 1:
......
...@@ -755,7 +755,8 @@ You can also pass script initialization code: ...@@ -755,7 +755,8 @@ You can also pass script initialization code:
>>> scripts = zc.buildout.easy_install.scripts( >>> scripts = zc.buildout.easy_install.scripts(
... ['demo'], ws, sys.executable, bin, dict(demo='run'), ... ['demo'], ws, sys.executable, bin, dict(demo='run'),
... arguments='1, 2', ... arguments='1, 2',
... initialization='import os\nos.chdir("foo")') ... initialization='import os\nos.chdir("foo")',
... interpreter='py')
>>> cat(bin, 'run') # doctest: +NORMALIZE_WHITESPACE >>> cat(bin, 'run') # doctest: +NORMALIZE_WHITESPACE
#!/usr/local/bin/python2.7 #!/usr/local/bin/python2.7
...@@ -773,6 +774,25 @@ You can also pass script initialization code: ...@@ -773,6 +774,25 @@ You can also pass script initialization code:
if __name__ == '__main__': if __name__ == '__main__':
sys.exit(eggrecipedemo.main(1, 2)) sys.exit(eggrecipedemo.main(1, 2))
It will be included in interpreters too:
>>> cat(bin, 'py') # doctest: +NORMALIZE_WHITESPACE +ELLIPSIS
#!/Users/jim/bin/python3.3
<BLANKLINE>
import sys
<BLANKLINE>
sys.path[0:0] = [
'/sample-install/demo-0.3-py3.3.egg',
'/sample-install/demoneeded-1.1-py3.3.egg',
]
<BLANKLINE>
import os
os.chdir("foo")
<BLANKLINE>
<BLANKLINE>
_interactive = True
...
Relative paths Relative paths
-------------- --------------
...@@ -829,7 +849,7 @@ Of course, running the script works: ...@@ -829,7 +849,7 @@ Of course, running the script works:
We specified an interpreter and its paths are adjusted too: We specified an interpreter and its paths are adjusted too:
>>> cat(bo, 'bin', 'py') >>> cat(bo, 'bin', 'py') # doctest: +NORMALIZE_WHITESPACE
#!/usr/local/bin/python2.7 #!/usr/local/bin/python2.7
<BLANKLINE> <BLANKLINE>
import os import os
......
...@@ -506,6 +506,7 @@ to be included in generated scripts: ...@@ -506,6 +506,7 @@ to be included in generated scripts:
... ${buildout:directory}/spam ... ${buildout:directory}/spam
... initialization = a = (1, 2 ... initialization = a = (1, 2
... 3, 4) ... 3, 4)
... interpreter = py
... arguments = a, 2 ... arguments = a, 2
... """ % dict(server=link_server)) ... """ % dict(server=link_server))
...@@ -513,6 +514,7 @@ to be included in generated scripts: ...@@ -513,6 +514,7 @@ to be included in generated scripts:
Uninstalling demo. Uninstalling demo.
Installing demo. Installing demo.
Generated script '/sample-buildout/bin/foo'. Generated script '/sample-buildout/bin/foo'.
Generated interpreter '/sample-buildout/bin/py'.
>>> cat(sample_buildout, 'bin', 'foo') # doctest: +NORMALIZE_WHITESPACE >>> cat(sample_buildout, 'bin', 'foo') # doctest: +NORMALIZE_WHITESPACE
#!/usr/local/bin/python2.7 #!/usr/local/bin/python2.7
...@@ -538,6 +540,28 @@ setting the path. Note, as mentioned above, that leading whitespace ...@@ -538,6 +540,28 @@ setting the path. Note, as mentioned above, that leading whitespace
has been stripped. Similarly, the argument code we specified was has been stripped. Similarly, the argument code we specified was
added in the entry point call (to main). added in the entry point call (to main).
Our interpreter also has the initialization code:
>>> cat(sample_buildout, 'bin', 'py')
... # doctest: +NORMALIZE_WHITESPACE +ELLIPSIS
#!/usr/local/bin/python2.7
<BLANKLINE>
import sys
<BLANKLINE>
sys.path[0:0] = [
'/sample-buildout/eggs/demo-0.3-py3.3.egg',
'/sample-buildout/eggs/demoneeded-1.1-py3.3.egg',
'/foo/bar',
'/sample-buildout/spam',
]
<BLANKLINE>
a = (1, 2
3, 4)
<BLANKLINE>
<BLANKLINE>
_interactive = True
...
Specifying entry points Specifying entry points
----------------------- -----------------------
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment