Commits

Jason R. Coombs committed 843ad01

Prefer local implementation to markerlib implementation as markerlib implementation is not as complete.

Comments (0)

Files changed (2)

 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.
 
 -----
 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:
         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.
             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.
         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"""