Commit 5c6ab577 authored by jim's avatar jim

Refactored generation of relative egg paths to generate simpler code.


git-svn-id: http://svn.zope.org/repos/main/zc.buildout/trunk@98239 62d5b8a3-27da-0310-9561-8e5933582275
parent 6de4bedb
...@@ -4,6 +4,11 @@ Status ...@@ -4,6 +4,11 @@ Status
Change History Change History
************** **************
1.2.1 (2009-03-18)
==================
- Refactored generation of relative egg paths to generate simpler code.
1.2.0 (2009-03-17) 1.2.0 (2009-03-17)
================== ==================
......
...@@ -973,6 +973,8 @@ def _relative_path_and_setup(sname, path, relative_paths): ...@@ -973,6 +973,8 @@ def _relative_path_and_setup(sname, path, relative_paths):
for path_item in path] for path_item in path]
) )
rpsetup = relative_paths_setup rpsetup = relative_paths_setup
for i in range(_relative_depth(relative_paths, sname)):
rpsetup += "base = os.path.dirname(base)\n"
else: else:
spath = repr(path)[1:-1].replace(', ', ',\n ') spath = repr(path)[1:-1].replace(', ', ',\n ')
rpsetup = '' rpsetup = ''
...@@ -1011,9 +1013,7 @@ def _relativitize(path, script, relative_paths): ...@@ -1011,9 +1013,7 @@ def _relativitize(path, script, relative_paths):
if (common == relative_paths or if (common == relative_paths or
common.startswith(os.path.join(relative_paths, '')) common.startswith(os.path.join(relative_paths, ''))
): ):
return "join(dirname(%s, __file__), %r)" % ( return "join(base, %r)" % _relative_path(common, path)
_relative_depth(common, script), _relative_path(common, path)
)
else: else:
return repr(path) return repr(path)
...@@ -1021,13 +1021,8 @@ def _relativitize(path, script, relative_paths): ...@@ -1021,13 +1021,8 @@ def _relativitize(path, script, relative_paths):
relative_paths_setup = """ relative_paths_setup = """
import os import os
def dirname(n, path):
while n >= 0:
n -= 1
path = os.path.dirname(path)
return path
join = os.path.join join = os.path.join
base = os.path.dirname(__file__)
""" """
def _script(module_name, attrs, path, dest, executable, arguments, def _script(module_name, attrs, path, dest, executable, arguments,
...@@ -1124,7 +1119,6 @@ def _pyscript(path, dest, executable, rsetup): ...@@ -1124,7 +1119,6 @@ def _pyscript(path, dest, executable, rsetup):
py_script_template = script_header + '''\ py_script_template = script_header + '''\
%(relative_paths_setup)s %(relative_paths_setup)s
import sys import sys
......
...@@ -814,20 +814,16 @@ to pass a common base directory of the scripts and eggs: ...@@ -814,20 +814,16 @@ to pass a common base directory of the scripts and eggs:
<BLANKLINE> <BLANKLINE>
import os import os
<BLANKLINE> <BLANKLINE>
def dirname(n, path):
while n >= 0:
n -= 1
path = os.path.dirname(path)
return path
<BLANKLINE>
join = os.path.join join = os.path.join
base = os.path.dirname(__file__)
base = os.path.dirname(base)
<BLANKLINE> <BLANKLINE>
import sys import sys
sys.path[0:0] = [ sys.path[0:0] = [
join(dirname(1, __file__), 'eggs/demo-0.3-py2.4.egg'), join(base, 'eggs/demo-0.3-pyN.N.egg'),
join(dirname(1, __file__), 'eggs/demoneeded-1.1-py2.4.egg'), join(base, 'eggs/demoneeded-1.1-pyN.N.egg'),
'/foo', '/foo',
join(dirname(1, __file__), 'bar'), join(base, 'bar'),
] ]
<BLANKLINE> <BLANKLINE>
import eggrecipedemo import eggrecipedemo
...@@ -848,24 +844,19 @@ We specified an interpreter and its paths are adjusted too: ...@@ -848,24 +844,19 @@ We specified an interpreter and its paths are adjusted too:
>>> cat(bo, 'bin', 'py') >>> cat(bo, 'bin', 'py')
#!/usr/local/bin/python2.4 #!/usr/local/bin/python2.4
<BLANKLINE> <BLANKLINE>
<BLANKLINE>
import os import os
<BLANKLINE> <BLANKLINE>
def dirname(n, path):
while n >= 0:
n -= 1
path = os.path.dirname(path)
return path
<BLANKLINE>
join = os.path.join join = os.path.join
base = os.path.dirname(__file__)
base = os.path.dirname(base)
<BLANKLINE> <BLANKLINE>
import sys import sys
<BLANKLINE> <BLANKLINE>
sys.path[0:0] = [ sys.path[0:0] = [
join(dirname(1, __file__), 'eggs/demo-0.3-py2.4.egg'), join(base, 'eggs/demo-0.3-pyN.N.egg'),
join(dirname(1, __file__), 'eggs/demoneeded-1.1-py2.4.egg'), join(base, 'eggs/demoneeded-1.1-pyN.N.egg'),
'/foo', '/foo',
join(dirname(1, __file__), 'bar'), join(base, 'bar'),
] ]
<BLANKLINE> <BLANKLINE>
_interactive = True _interactive = True
......
Change History Change History
************** **************
1.2.1 (2009-03-18)
==================
- Refactored generation of relative egg paths to generate simpler code.
1.2.0 (2009-03-17) 1.2.0 (2009-03-17)
================== ==================
......
...@@ -424,20 +424,16 @@ Let's look at the script that was generated: ...@@ -424,20 +424,16 @@ Let's look at the script that was generated:
<BLANKLINE> <BLANKLINE>
import os import os
<BLANKLINE> <BLANKLINE>
def dirname(n, path):
while n >= 0:
n -= 1
path = os.path.dirname(path)
return path
<BLANKLINE>
join = os.path.join join = os.path.join
base = os.path.dirname(__file__)
base = os.path.dirname(base)
<BLANKLINE> <BLANKLINE>
import sys import sys
sys.path[0:0] = [ sys.path[0:0] = [
join(dirname(1, __file__), 'eggs/demo-0.4c1-py2.4.egg'), join(base, 'eggs/demo-0.4c1-pyN.N.egg'),
join(dirname(1, __file__), 'eggs/demoneeded-1.2c1-py2.4.egg'), join(base, 'eggs/demoneeded-1.2c1-pyN.N.egg'),
'/foo/bar', '/foo/bar',
join(dirname(1, __file__), 'spam'), join(base, 'spam'),
] ]
<BLANKLINE> <BLANKLINE>
import eggrecipedemo import eggrecipedemo
...@@ -475,20 +471,16 @@ each individual script section: ...@@ -475,20 +471,16 @@ each individual script section:
<BLANKLINE> <BLANKLINE>
import os import os
<BLANKLINE> <BLANKLINE>
def dirname(n, path):
while n >= 0:
n -= 1
path = os.path.dirname(path)
return path
<BLANKLINE>
join = os.path.join join = os.path.join
base = os.path.dirname(__file__)
base = os.path.dirname(base)
<BLANKLINE> <BLANKLINE>
import sys import sys
sys.path[0:0] = [ sys.path[0:0] = [
join(dirname(1, __file__), 'eggs/demo-0.4c1-py2.4.egg'), join(base, 'eggs/demo-0.4c1-pyN.N.egg'),
join(dirname(1, __file__), 'eggs/demoneeded-1.2c1-py2.4.egg'), join(base, 'eggs/demoneeded-1.2c1-pyN.N.egg'),
'/foo/bar', '/foo/bar',
join(dirname(1, __file__), 'spam'), join(base, 'spam'),
] ]
<BLANKLINE> <BLANKLINE>
import eggrecipedemo import eggrecipedemo
......
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