Commit 67fd1da8 authored by Gary Poster's avatar Gary Poster

Fix some problems with allowed_eggs_from_site_packages

parent 525254ce
...@@ -58,7 +58,6 @@ if is_jython: ...@@ -58,7 +58,6 @@ if is_jython:
import java.lang.System import java.lang.System
jython_os_name = (java.lang.System.getProperties()['os.name']).lower() jython_os_name = (java.lang.System.getProperties()['os.name']).lower()
setuptools_loc = pkg_resources.working_set.find( setuptools_loc = pkg_resources.working_set.find(
pkg_resources.Requirement.parse('setuptools') pkg_resources.Requirement.parse('setuptools')
).location ).location
...@@ -873,7 +872,13 @@ class Installer: ...@@ -873,7 +872,13 @@ class Installer:
dist = best[req.key] = env.best_match(req, ws) dist = best[req.key] = env.best_match(req, ws)
except pkg_resources.VersionConflict, err: except pkg_resources.VersionConflict, err:
raise VersionConflict(err, ws) raise VersionConflict(err, ws)
if dist is None: if dist is None or (
dist.location in self._site_packages and not
self.allow_site_package_egg(dist.project_name)):
# If we didn't find a distribution in the
# environment, or what we found is from site
# packages and not allowed to be there, try
# again.
if destination: if destination:
logger.debug('Getting required %r', str(req)) logger.debug('Getting required %r', str(req))
else: else:
...@@ -1548,15 +1553,15 @@ def _generate_site(dest, working_set, executable, extra_paths=(), ...@@ -1548,15 +1553,15 @@ def _generate_site(dest, working_set, executable, extra_paths=(),
""" """
path = _get_path(working_set, extra_paths) path = _get_path(working_set, extra_paths)
site_path = os.path.join(dest, 'site.py') site_path = os.path.join(dest, 'site.py')
egg_path_string, preamble = _relative_path_and_setup( original_path_setup = preamble = ''
site_path, path, relative_paths, indent_level=2, omit_os_import=True)
if preamble:
preamble = '\n'.join(
[(line and ' %s' % (line,) or line)
for line in preamble.split('\n')])
original_path_setup = ''
if include_site_packages: if include_site_packages:
stdlib, site_paths = _get_system_paths(executable) stdlib, site_paths = _get_system_paths(executable)
# We want to make sure that paths from site-packages, such as those
# allowed by allowed_eggs_from_site_packages, always come last, or
# else site-packages paths may include packages that mask the eggs we
# really want.
path = [p for p in path if p not in site_paths]
# Now we set up the code we need.
original_path_setup = original_path_snippet % ( original_path_setup = original_path_snippet % (
_format_paths((repr(p) for p in site_paths), 2),) _format_paths((repr(p) for p in site_paths), 2),)
distribution = working_set.find( distribution = working_set.find(
...@@ -1570,10 +1575,17 @@ def _generate_site(dest, working_set, executable, extra_paths=(), ...@@ -1570,10 +1575,17 @@ def _generate_site(dest, working_set, executable, extra_paths=(),
relative_paths) relative_paths)
else: else:
location = repr(distribution.location) location = repr(distribution.location)
preamble += namespace_include_site_packages_setup % (location,) preamble = namespace_include_site_packages_setup % (location,)
original_path_setup = ( original_path_setup = (
addsitedir_namespace_originalpackages_snippet + addsitedir_namespace_originalpackages_snippet +
original_path_setup) original_path_setup)
egg_path_string, relative_preamble = _relative_path_and_setup(
site_path, path, relative_paths, indent_level=2, omit_os_import=True)
if relative_preamble:
relative_preamble = '\n'.join(
[(line and ' %s' % (line,) or line)
for line in relative_preamble.split('\n')])
preamble = relative_preamble + preamble
addsitepackages_marker = 'def addsitepackages(' addsitepackages_marker = 'def addsitepackages('
enableusersite_marker = 'ENABLE_USER_SITE = ' enableusersite_marker = 'ENABLE_USER_SITE = '
successful_rewrite = False successful_rewrite = False
......
...@@ -2255,6 +2255,75 @@ include-site-packages. ...@@ -2255,6 +2255,75 @@ include-site-packages.
""" """
def allowed_eggs_from_site_packages_dependencies_bugfix():
"""
If you specify that a package with a dependency may come from site-packages,
that doesn't mean that the dependency may come from site-packages. This
is a test for a bug fix to verify that this is true.
>>> py_path, site_packages_path = make_py()
>>> create_sample_sys_install(site_packages_path)
>>> interpreter_dir = tmpdir('interpreter')
>>> interpreter_parts_dir = os.path.join(
... interpreter_dir, 'parts', 'interpreter')
>>> interpreter_bin_dir = os.path.join(interpreter_dir, 'bin')
>>> mkdir(interpreter_bin_dir)
>>> mkdir(interpreter_dir, 'eggs')
>>> mkdir(interpreter_dir, 'parts')
>>> mkdir(interpreter_parts_dir)
>>> ws = zc.buildout.easy_install.install(
... ['demo'], join(interpreter_dir, 'eggs'), executable=py_path,
... links=[link_server], index=link_server+'index/',
... allowed_eggs_from_site_packages=['demo'])
>>> [dist.project_name for dist in ws]
['demo', 'demoneeded']
>>> from pprint import pprint
>>> pprint([dist.location for dist in ws])
['/executable_buildout/site-packages',
'/interpreter/eggs/demoneeded-1.1-pyN.N.egg']
"""
def allowed_eggs_from_site_packages_bug_592524():
"""
When we use allowed_eggs_from_site_packages, we need to make sure that the
site-packages paths are not inserted with the normal egg paths. They already
included at the end, and including them along with the normal egg paths will
possibly mask subsequent egg paths. This affects interpreters and scripts
generated by sitepackage_safe_scripts.
Our "py_path" has the "demoneeded" and "demo" packages available.
>>> py_path, site_packages_path = make_py()
>>> create_sample_sys_install(site_packages_path)
>>> interpreter_dir = tmpdir('interpreter')
>>> interpreter_parts_dir = os.path.join(
... interpreter_dir, 'parts', 'interpreter')
>>> interpreter_bin_dir = os.path.join(interpreter_dir, 'bin')
>>> mkdir(interpreter_bin_dir)
>>> mkdir(interpreter_dir, 'eggs')
>>> mkdir(interpreter_dir, 'parts')
>>> mkdir(interpreter_parts_dir)
>>> ws = zc.buildout.easy_install.install(
... ['demo', 'other'], join(interpreter_dir, 'eggs'), executable=py_path,
... links=[link_server], index=link_server+'index/',
... allowed_eggs_from_site_packages=['demo'])
>>> generated = zc.buildout.easy_install.sitepackage_safe_scripts(
... interpreter_bin_dir, ws, py_path, interpreter_parts_dir,
... interpreter='py', include_site_packages=True)
Now we will look at the paths in the site.py we generated. Notice that the
site-packages are at the end. They were not before this bugfix.
>>> test = 'import pprint, sys; pprint.pprint(sys.path[-4:])'
>>> print call_py(join(interpreter_bin_dir, 'py'), test)
['/interpreter/eggs/other-1.0-pyN.N.egg',
'/interpreter/eggs/demoneeded-1.1-pyN.N.egg',
'/executable_buildout/eggs/setuptools-0.0-pyN.N.egg',
'/executable_buildout/site-packages']
<BLANKLINE>
"""
def subprocesses_have_same_environment_by_default(): def subprocesses_have_same_environment_by_default():
""" """
The scripts generated by sitepackage_safe_scripts set the PYTHONPATH so that, The scripts generated by sitepackage_safe_scripts set the PYTHONPATH so that,
......
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