Update pythonfinder, vistir, and requirementslib versions

Signed-off-by: Dan Ryan <dan@danryan.co>
This commit is contained in:
Dan Ryan
2018-11-22 01:37:05 -05:00
parent 36b75e72c9
commit d7e3d3354b
10 changed files with 85 additions and 31 deletions
+1
View File
@@ -513,6 +513,7 @@ class PathEntry(BasePath):
if self.is_dir:
return None
if self.is_python:
py_version = None
try:
py_version = PythonVersion.from_path(path=self, name=self.name)
except (InvalidPythonVersion, ValueError):
+11 -9
View File
@@ -15,6 +15,7 @@ from packaging.version import parse as parse_version
from vistir.compat import Path
from ..environment import SYSTEM_ARCH, PYENV_ROOT, ASDF_DATA_DIR
from ..exceptions import InvalidPythonVersion
from .mixins import BaseFinder, BasePath
from ..utils import (
_filter_none,
@@ -109,7 +110,7 @@ class PythonFinder(BaseFinder, BasePath):
version = None
try:
version = PythonVersion.parse(p.name)
except ValueError:
except (ValueError, InvalidPythonVersion):
entry = next(iter(version_path.find_all_python_versions()), None)
if not entry:
if self.ignore_unsupported:
@@ -246,7 +247,7 @@ class PythonVersion(object):
is_postrelease = attr.ib(default=False)
is_devrelease = attr.ib(default=False)
is_debug = attr.ib(default=False)
version = attr.ib(default=None, validator=optional_instance_of(Version))
version = attr.ib(default=None)
architecture = attr.ib(default=None)
comes_from = attr.ib(default=None)
executable = attr.ib(default=None)
@@ -368,7 +369,7 @@ class PythonVersion(object):
return self.architecture
@classmethod
def from_path(cls, path, name=None):
def from_path(cls, path, name=None, ignore_unsupported=True):
"""Parses a python version from a system path.
Raises:
@@ -377,23 +378,24 @@ class PythonVersion(object):
:param path: A string or :class:`~pythonfinder.models.path.PathEntry`
:type path: str or :class:`~pythonfinder.models.path.PathEntry` instance
:param str name: Name of the python distribution in question
:param bool ignore_unsupported: Whether to ignore or error on unsupported paths.
:return: An instance of a PythonVersion.
:rtype: :class:`~pythonfinder.models.python.PythonVersion`
"""
from .path import PathEntry
from ..environment import IGNORE_UNSUPPORTED
if not isinstance(path, PathEntry):
path = PathEntry.create(path, is_root=False, only_python=True, name=name)
if not path.is_python and not IGNORE_UNSUPPORTED:
raise ValueError("Not a valid python path: %s" % path.path)
return
from ..environment import IGNORE_UNSUPPORTED
ignore_unsupported = ignore_unsupported or IGNORE_UNSUPPORTED
if not path.is_python:
if not (ignore_unsupported or IGNORE_UNSUPPORTED):
raise ValueError("Not a valid python path: %s" % path.path)
py_version = get_python_version(path.path.absolute().as_posix())
instance_dict = cls.parse(py_version.strip())
if not isinstance(instance_dict.get("version"), Version) and not IGNORE_UNSUPPORTED:
if not isinstance(instance_dict.get("version"), Version) and not ignore_unsupported:
raise ValueError("Not a valid python path: %s" % path.path)
return
if not name:
name = path.name
instance_dict.update(
+16 -6
View File
@@ -31,7 +31,7 @@ if MYPY_RUNNING:
from attr.validators import _OptionalValidator
version_re = re.compile(r"(?P<major>\d+)\.(?P<minor>\d+)\.?(?P<patch>(?<=\.)[0-9]+)?\.?"
version_re = re.compile(r"(?P<major>\d+)(?:\.(?P<minor>\d+))?(?:\.(?P<patch>(?<=\.)[0-9]+))?\.?"
r"(?:(?P<prerel>[abc]|rc|dev)(?:(?P<prerelversion>\d+(?:\.\d+)*))?)"
r"?(?P<postdev>(\.post(?P<post>\d+))?(\.dev(?P<dev>\d+))?)?")
@@ -81,10 +81,10 @@ def parse_python_version(version_str):
if version_str.endswith("-debug"):
is_debug = True
version_str, _, _ = version_str.rpartition("-")
m = version_re.match(version_str)
if not m:
match = version_re.match(version_str)
if not match:
raise InvalidPythonVersion("%s is not a python version" % version_str)
version_dict = m.groupdict() # type: Dict[str, str]
version_dict = match.groupdict() # type: Dict[str, str]
major = int(version_dict.get("major", 0)) if version_dict.get("major") else None
minor = int(version_dict.get("minor", 0)) if version_dict.get("minor") else None
patch = int(version_dict.get("patch", 0)) if version_dict.get("patch") else None
@@ -97,8 +97,18 @@ def parse_python_version(version_str):
try:
version = parse_version(version_str)
except TypeError:
version_parts = [str(v) for v in [major, minor, patch] if v is not None]
version = parse_version(".".join(version_parts))
version = None
if isinstance(version, LegacyVersion) or version is None:
v_dict = version_dict.copy()
pre = ""
if v_dict.get("prerel") and v_dict.get("prerelversion"):
pre = v_dict.pop("prerel")
pre = "{0}{1}".format(pre, v_dict.pop("prerelversion"))
v_dict["pre"] = pre
keys = ["major", "minor", "patch", "pre", "postdev", "post", "dev"]
values = [v_dict.get(val) for val in keys]
version_str = ".".join([str(v) for v in values if v])
version = parse_version(version_str)
return {
"major": major,
"minor": minor,
+3 -3
View File
@@ -21,13 +21,13 @@ pipdeptree==0.13.0
pipreqs==0.4.9
docopt==0.6.2
yarg==0.1.9
pythonfinder==1.1.9.post1
pythonfinder==1.1.10
requests==2.20.1
chardet==3.0.4
idna==2.7
urllib3==1.24
certifi==2018.10.15
requirementslib==1.3.1.post1
requirementslib==1.3.3
attrs==18.2.0
distlib==0.2.8
packaging==18.0
@@ -40,7 +40,7 @@ semver==2.8.1
shutilwhich==1.1.0
toml==0.10.0
cached-property==1.4.3
vistir==0.2.4
vistir==0.2.5
pip-shims==0.3.2
ptyprocess==0.6.0
enum34==1.1.6
+1 -1
View File
@@ -31,7 +31,7 @@ from .path import mkdir_p, rmtree, create_tracked_tempdir, create_tracked_tempfi
from .spin import VistirSpinner, create_spinner
__version__ = '0.2.4'
__version__ = '0.2.5'
__all__ = [
+3
View File
@@ -83,6 +83,9 @@ if six.PY2:
else:
from builtins import ResourceWarning, FileNotFoundError, PermissionError, IsADirectoryError
six.add_move(six.MovedAttribute("Iterable", "collections", "collections.abc"))
from six.moves import Iterable
if not sys.warnoptions:
warnings.simplefilter("default", ResourceWarning)
+12 -10
View File
@@ -10,12 +10,12 @@ import sys
from collections import OrderedDict
from functools import partial
from itertools import islice
from itertools import islice, tee
import six
from .cmdparse import Script
from .compat import Path, fs_str, partialmethod, to_native_string
from .compat import Path, fs_str, partialmethod, to_native_string, Iterable
from .contextmanagers import spinner as spinner
if os.name != "nt":
@@ -78,15 +78,17 @@ def unnest(elem):
[1234, 3456, 4398345, 234234, 2396, 23895750, 9283798, 29384, 289375983275, 293759, 2347, 2098, 7987, 27599]
"""
if _is_iterable(elem):
for item in elem:
if _is_iterable(item):
for sub_item in unnest(item):
yield sub_item
else:
yield item
if isinstance(elem, Iterable) and not isinstance(elem, six.string_types):
elem, target = tee(elem, 2)
else:
raise ValueError("Expecting an iterable, got %r" % elem)
target = elem
for el in target:
if isinstance(el, Iterable) and not isinstance(el, six.string_types):
el, el_copy = tee(el, 2)
for sub in unnest(el_copy):
yield sub
else:
yield el
def _is_iterable(elem):
+29
View File
@@ -30,6 +30,8 @@ __all__ = [
"check_for_unc_path",
"get_converted_relative_path",
"handle_remove_readonly",
"normalize_path",
"is_in_path",
"is_file_url",
"is_readonly_path",
"is_valid_url",
@@ -80,6 +82,33 @@ else:
return os.path.normpath(path)
def normalize_path(path):
"""
Return a case-normalized absolute variable-expanded path.
:param str path: The non-normalized path
:return: A normalized, expanded, case-normalized path
:rtype: str
"""
return os.path.normpath(os.path.normcase(
os.path.abspath(os.path.expandvars(os.path.expanduser(str(path))))
))
def is_in_path(path, parent):
"""
Determine if the provided full path is in the given parent root.
:param str path: The full path to check the location of.
:param str parent: The parent path to check for membership in
:return: Whether the full path is a member of the provided parent.
:rtype: bool
"""
return normalize_path(str(path)).startswith(normalize_path(str(parent)))
def normalize_drive(path):
"""Normalize drive in path so they stay consistent.
+4 -2
View File
@@ -12,7 +12,7 @@ import cursor
import six
from .compat import to_native_string
from .termcolors import COLOR_MAP, COLORS, colored
from .termcolors import COLOR_MAP, COLORS, colored, DISABLE_COLORS
from io import StringIO
try:
@@ -34,7 +34,9 @@ CLEAR_LINE = chr(27) + "[K"
class DummySpinner(object):
def __init__(self, text="", **kwargs):
colorama.init()
super(DummySpinner, self).__init__()
if DISABLE_COLORS:
colorama.init()
from .misc import decode_for_output
self.text = to_native_string(decode_for_output(text)) if text else ""
self.stdout = kwargs.get("stdout", sys.stdout)
+5
View File
@@ -5,6 +5,11 @@ import os
from .compat import to_native_string
DISABLE_COLORS = os.getenv("CI", False) or os.getenv("ANSI_COLORS_DISABLED",
os.getenv("VISTIR_DISABLE_COLORS", False)
)
ATTRIBUTES = dict(
list(zip([
'bold',