aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason R. Coombs <jaraco@jaraco.com>2013-06-09 09:23:43 -0400
committerJason R. Coombs <jaraco@jaraco.com>2013-06-09 09:23:43 -0400
commit7ae6e5e399dfd2274395aa11570184e47ee7144e (patch)
tree116db38689759a5dce785bc00eb2f84d938ef1d1
parent0cfd8865097b9093ee1fd50c49ceabad411c885e (diff)
downloadexternal_python_setuptools-7ae6e5e399dfd2274395aa11570184e47ee7144e.tar.gz
external_python_setuptools-7ae6e5e399dfd2274395aa11570184e47ee7144e.tar.bz2
external_python_setuptools-7ae6e5e399dfd2274395aa11570184e47ee7144e.zip
Prefer local implementation to markerlib implementation as markerlib implementation is not as complete.
--HG-- extra : histedit_source : 3855347db7042dc34032b6bfa7b4c4e5239c1c3f
-rw-r--r--CHANGES.txt4
-rw-r--r--pkg_resources.py22
2 files changed, 13 insertions, 13 deletions
diff --git a/CHANGES.txt b/CHANGES.txt
index 01c70cce..34177d63 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -6,9 +6,7 @@ CHANGES
0.7.2
-----
-* Issue #14: Prefer markerlib for evaluation of marker expressions in extras.
- Fall back to implementation based on 'parser' for Python 2.5 and 2.4
- clients.
+* Issue #14: Use markerlib when the `parser` module is not available.
* Issue #10: ``ez_setup.py`` now uses HTTPS to download setuptools from PyPI.
-----
diff --git a/pkg_resources.py b/pkg_resources.py
index 83901bb8..1706dcd4 100644
--- a/pkg_resources.py
+++ b/pkg_resources.py
@@ -39,6 +39,11 @@ if sys.version_info >= (3, 3) and sys.implementation.name == "cpython":
else:
importlib_bootstrap = None
+try:
+ import parser
+except ImportError:
+ pass
+
def _bypass_ensure_directory(name, mode=0777):
# Sandbox-bypassing version of ensure_directory()
if not WRITE_SUPPORT:
@@ -1211,7 +1216,7 @@ def invalid_marker(text):
return sys.exc_info()[1]
return False
-def _evaluate_marker_legacy(text, extra=None, _ops={}):
+def evaluate_marker(text, extra=None, _ops={}):
"""
Evaluate a PEP 426 environment marker on CPython 2.4+.
Return a boolean indicating the marker result in this environment.
@@ -1297,17 +1302,13 @@ def _evaluate_marker_legacy(text, extra=None, _ops={}):
return s[1:-1]
raise SyntaxError("Language feature not supported in environment markers")
- import parser
return interpret(parser.expr(text).totuple(1)[1])
-def evaluate_marker(text):
+def _markerlib_evaluate(text):
"""
- Evaluate a PEP 426 environment marker.
+ Evaluate a PEP 426 environment marker using markerlib.
Return a boolean indicating the marker result in this environment.
Raise SyntaxError if marker is invalid.
-
- Note the implementation is incomplete as it does not support parentheses
- for grouping.
"""
import _markerlib
# markerlib implements Metadata 1.2 (PEP 345) environment markers.
@@ -1323,9 +1324,10 @@ def evaluate_marker(text):
raise SyntaxError(e.args[0])
return result
-# support marker evaluation on Python 2.4+
-if sys.version_info < (2,6) and _pyimp() == 'CPython':
- evaluate_marker = _evaluate_marker_legacy
+if 'parser' not in globals():
+ # fallback to less-complete _markerlib implementation if 'parser' module
+ # is not available.
+ evaluate_marker = _markerlib_evaluate
class NullProvider:
"""Try to implement resources and metadata for arbitrary PEP 302 loaders"""