Commit f1ecdf62 authored by Holger Brunn's avatar Holger Brunn Committed by Godefroid Chapelle

Evaluate environment markers for requirement strings

parent c0241921
...@@ -439,6 +439,39 @@ where you list them, as in: ...@@ -439,6 +439,39 @@ where you list them, as in:
In this example, we've requested a version of bobo less than 5.0. In this example, we've requested a version of bobo less than 5.0.
You can also add `environment markers <https://python.org/dev/peps/pep-0496>`_
to restrict some requirements to i.e. a certain platform or python version:
.. code-block:: ini
[bobo]
recipe = zc.recipe.egg
eggs =
bobo ==2.2.0; python_version < '3.0'
bobo ==2.3.0; python_version >= '3.0'
.. -> src
>>> prefix = """
... [buildout]
... parts = bobo
... """
>>> with open('buildout.cfg', 'w') as f:
... _ = f.write(prefix)
... _ = f.write(src)
>>> import shutil
>>> import sys
>>> v = sys.version_info
>>> shutil.rmtree('eggs')
>>> run_buildout('buildout show-picked-versions=true')
>>> yup([n for n in ls('eggs') if n.startswith('bobo-2.3.0-')])\
... if v.major >= 3 else\
... yup([n for n in ls('eggs') if n.startswith('bobo-2.2.0-')])
>>> yup('bobo==2.3.0' in read('out'))\
... if v.major >= 3 else\
... yup('bobo==2.2.0' in read('out'))
The more common way to pin a version is using a ``versions`` section: The more common way to pin a version is using a ``versions`` section:
.. code-block:: ini .. code-block:: ini
......
add support for PEP496 environment markers
...@@ -678,9 +678,15 @@ class Installer(object): ...@@ -678,9 +678,15 @@ class Installer(object):
for_buildout_run = bool(working_set) for_buildout_run = bool(working_set)
requirements = [self._constrain(pkg_resources.Requirement.parse(spec)) requirements = [pkg_resources.Requirement.parse(spec)
for spec in specs] for spec in specs]
requirements = [
self._constrain(requirement)
for requirement in requirements
if not requirement.marker or requirement.marker.evaluate()
]
if working_set is None: if working_set is None:
ws = pkg_resources.WorkingSet([]) ws = pkg_resources.WorkingSet([])
else: else:
...@@ -1168,6 +1174,8 @@ def scripts(reqs, working_set, executable, dest=None, ...@@ -1168,6 +1174,8 @@ def scripts(reqs, working_set, executable, dest=None,
for req in reqs: for req in reqs:
if isinstance(req, str): if isinstance(req, str):
req = pkg_resources.Requirement.parse(req) req = pkg_resources.Requirement.parse(req)
if req.marker and not req.marker.evaluate():
continue
dist = working_set.find(req) dist = working_set.find(req)
# regular console_scripts entry points # regular console_scripts entry points
for name in pkg_resources.get_entry_map(dist, 'console_scripts'): for name in pkg_resources.get_entry_map(dist, 'console_scripts'):
......
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