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