From 738ffeeb21ec6bcf9c83e6184c0f91b363c4c637 Mon Sep 17 00:00:00 2001 From: Matt Davis Date: Wed, 24 Aug 2022 14:49:10 -0400 Subject: [PATCH 1/2] Vendor in pythonfinder==1.3.1 --- pipenv/vendor/pythonfinder/__init__.py | 2 +- pipenv/vendor/pythonfinder/cli.py | 23 +++++++------------ pipenv/vendor/pythonfinder/compat.py | 21 +++-------------- pipenv/vendor/pythonfinder/models/__init__.py | 2 -- pipenv/vendor/pythonfinder/models/mixins.py | 4 +--- pipenv/vendor/pythonfinder/models/path.py | 16 +++++++------ pipenv/vendor/pythonfinder/models/python.py | 14 +++++------ pipenv/vendor/pythonfinder/pythonfinder.py | 13 ++++------- pipenv/vendor/pythonfinder/utils.py | 20 ++++------------ pipenv/vendor/vendor.txt | 2 +- 10 files changed, 37 insertions(+), 80 deletions(-) diff --git a/pipenv/vendor/pythonfinder/__init__.py b/pipenv/vendor/pythonfinder/__init__.py index 6bca723924..951f74e353 100644 --- a/pipenv/vendor/pythonfinder/__init__.py +++ b/pipenv/vendor/pythonfinder/__init__.py @@ -10,7 +10,7 @@ from .models import SystemPath, WindowsFinder from .pythonfinder import Finder -__version__ = "1.2.10" +__version__ = "1.3.1" logger = logging.getLogger(__name__) diff --git a/pipenv/vendor/pythonfinder/cli.py b/pipenv/vendor/pythonfinder/cli.py index c8d7753b16..db8046bfdd 100644 --- a/pipenv/vendor/pythonfinder/cli.py +++ b/pipenv/vendor/pythonfinder/cli.py @@ -8,32 +8,25 @@ @click.command() -@click.option("--find", default=False, nargs=1, help="Find a specific python version.") -@click.option("--which", default=False, nargs=1, help="Run the which command.") +@click.option("--find", nargs=1, help="Find a specific python version.") +@click.option("--which", nargs=1, help="Run the which command.") @click.option("--findall", is_flag=True, default=False, help="Find all python versions.") @click.option( - "--version", is_flag=True, default=False, help="Display PythonFinder version." -) -@click.option( - "--ignore-unsupported/--no-unsupported", + "--ignore-unsupported", + "--no-unsupported", is_flag=True, default=True, envvar="PYTHONFINDER_IGNORE_UNSUPPORTED", help="Ignore unsupported python versions.", ) -@click.version_option(prog_name="pyfinder", version=__version__) +@click.version_option( + prog_name=click.style("PythonFinder", bold=True), + version=click.style(__version__, fg="yellow"), +) @click.pass_context def cli( ctx, find=False, which=False, findall=False, version=False, ignore_unsupported=True ): - if version: - click.echo( - "{0} version {1}".format( - click.style("PythonFinder", fg="white", bold=True), - click.style(str(__version__), fg="yellow"), - ) - ) - ctx.exit() finder = Finder(ignore_unsupported=ignore_unsupported) if findall: versions = [v for v in finder.find_all_python_versions()] diff --git a/pipenv/vendor/pythonfinder/compat.py b/pipenv/vendor/pythonfinder/compat.py index 1cded95852..51fca9529f 100644 --- a/pipenv/vendor/pythonfinder/compat.py +++ b/pipenv/vendor/pythonfinder/compat.py @@ -1,21 +1,10 @@ # -*- coding=utf-8 -*- import sys -import pipenv.vendor.six as six +from pathlib import Path -if sys.version_info[:2] <= (3, 4): - from pathlib2 import Path # type: ignore # noqa -else: - from pathlib import Path - -if six.PY3: - from builtins import TimeoutError - from functools import lru_cache -else: - from backports.functools_lru_cache import lru_cache # type: ignore # noqa - - class TimeoutError(OSError): - pass +from builtins import TimeoutError +from functools import lru_cache def getpreferredencoding(): @@ -24,10 +13,6 @@ def getpreferredencoding(): # Borrowed from Invoke # (see https://github.com/pyinvoke/invoke/blob/93af29d/invoke/runners.py#L881) _encoding = locale.getpreferredencoding(False) - if six.PY2 and not sys.platform == "win32": - _default_encoding = locale.getdefaultlocale()[1] - if _default_encoding is not None: - _encoding = _default_encoding return _encoding diff --git a/pipenv/vendor/pythonfinder/models/__init__.py b/pipenv/vendor/pythonfinder/models/__init__.py index e7e03a70b3..e9497096e7 100644 --- a/pipenv/vendor/pythonfinder/models/__init__.py +++ b/pipenv/vendor/pythonfinder/models/__init__.py @@ -5,8 +5,6 @@ import operator from itertools import chain -import pipenv.vendor.six as six - from ..utils import KNOWN_EXTS, unnest from .path import SystemPath from .python import PythonVersion diff --git a/pipenv/vendor/pythonfinder/models/mixins.py b/pipenv/vendor/pythonfinder/models/mixins.py index 1e31efd3df..974ece6019 100644 --- a/pipenv/vendor/pythonfinder/models/mixins.py +++ b/pipenv/vendor/pythonfinder/models/mixins.py @@ -6,7 +6,6 @@ from collections import defaultdict import pipenv.vendor.attr as attr -import pipenv.vendor.six as six from ..compat import fs_str from ..environment import MYPY_RUNNING @@ -378,8 +377,7 @@ def find_python_version( return next(iter(r[0] for r in results if r is not None), None) -@six.add_metaclass(abc.ABCMeta) -class BaseFinder(object): +class BaseFinder(object, metaclass=abc.ABCMeta): def __init__(self): #: Maps executable paths to PathEntries from .path import PathEntry diff --git a/pipenv/vendor/pythonfinder/models/path.py b/pipenv/vendor/pythonfinder/models/path.py index 01ff67ddbe..0679e7abd4 100644 --- a/pipenv/vendor/pythonfinder/models/path.py +++ b/pipenv/vendor/pythonfinder/models/path.py @@ -1,16 +1,14 @@ # -*- coding=utf-8 -*- -from __future__ import absolute_import, print_function +import errno import operator import os import stat import sys -import errno from collections import defaultdict from itertools import chain import pipenv.vendor.attr as attr -import pipenv.vendor.six as six from pipenv.vendor.pyparsing.core import cached_property from ..compat import Path, fs_str @@ -64,15 +62,17 @@ ChildType = Union[PythonFinder, "PathEntry"] PathType = Union[PythonFinder, "PathEntry"] + def exists_and_is_accessible(path): try: return path.exists() except PermissionError as pe: - if pe.errno == errno.EACCES: # Permission denied + if pe.errno == errno.EACCES: # Permission denied return False else: raise + @attr.s class SystemPath(object): global_search = attr.ib(default=True) @@ -238,7 +238,9 @@ def _run_setup(self): ) new_instance = attr.evolve( new_instance, - path_order=[p.as_posix() for p in path_instances if p.exists()], + path_order=[ + p.as_posix() for p in path_instances if exists_and_is_accessible(p) + ], paths=path_entries, ) if os.name == "nt" and "windows" not in self.finders: @@ -736,9 +738,9 @@ def _gen_children(self): pass_name = self.name != self.path.name pass_args = {"is_root": False, "only_python": self.only_python} if pass_name: - if self.name is not None and isinstance(self.name, six.string_types): + if self.name is not None and isinstance(self.name, str): pass_args["name"] = self.name # type: ignore - elif self.path is not None and isinstance(self.path.name, six.string_types): + elif self.path is not None and isinstance(self.path.name, str): pass_args["name"] = self.path.name # type: ignore if not self.is_dir: diff --git a/pipenv/vendor/pythonfinder/models/python.py b/pipenv/vendor/pythonfinder/models/python.py index eaadc00539..ca9954204c 100644 --- a/pipenv/vendor/pythonfinder/models/python.py +++ b/pipenv/vendor/pythonfinder/models/python.py @@ -1,5 +1,4 @@ # -*- coding=utf-8 -*- -from __future__ import absolute_import, print_function import logging import operator @@ -9,7 +8,6 @@ from collections import defaultdict import pipenv.vendor.attr as attr -import pipenv.vendor.six as six from pipenv.patched.pip._vendor.packaging.version import Version from ..compat import Path, lru_cache @@ -62,14 +60,14 @@ def overload(f): @attr.s(slots=True) -class PythonFinder(BaseFinder, BasePath): +class PythonFinder(BasePath, BaseFinder): root = attr.ib(default=None, validator=optional_instance_of(Path), type=Path) # should come before versions, because its value is used in versions's default initializer. #: Whether to ignore any paths which raise exceptions and are not actually python ignore_unsupported = attr.ib(default=True, type=bool) #: Glob path for python versions off of the root directory version_glob_path = attr.ib(default="versions/*", type=str) - #: The function to use to sort version order when returning an ordered verion set + #: The function to use to sort version order when returning an ordered version set sort_function = attr.ib(default=None) # type: Callable #: The root locations used for discovery roots = attr.ib(default=attr.Factory(defaultdict), type=defaultdict) @@ -133,7 +131,7 @@ def get_version_order(self): def get_bin_dir(self, base): # type: (Union[Path, str]) -> Path - if isinstance(base, six.string_types): + if isinstance(base, str): base = Path(base) if os.name == "nt": return base @@ -374,7 +372,7 @@ def __getattribute__(self, key): elif self.comes_from: executable = self.comes_from.path.as_posix() if executable is not None: - if not isinstance(executable, six.string_types): + if not isinstance(executable, str): executable = executable.as_posix() instance_dict = self.parse_executable(executable) for k in instance_dict.keys(): @@ -525,7 +523,7 @@ def parse(cls, version): Raises: ValueError -- Unable to parse version string ValueError -- Not a valid python version - TypeError -- NoneType or unparseable type passed in + TypeError -- NoneType or unparsable type passed in :param str version: A valid version string :return: A dictionary with metadata about the specified python version. @@ -614,7 +612,7 @@ def parse_executable(cls, path): result_version = None # type: Optional[str] if path is None: raise TypeError("Must pass a valid path to parse.") - if not isinstance(path, six.string_types): + if not isinstance(path, str): path = path.as_posix() # if not looks_like_python(path): # raise ValueError("Path %r does not look like a valid python path" % path) diff --git a/pipenv/vendor/pythonfinder/pythonfinder.py b/pipenv/vendor/pythonfinder/pythonfinder.py index a80f91dfb7..3d466babaa 100644 --- a/pipenv/vendor/pythonfinder/pythonfinder.py +++ b/pipenv/vendor/pythonfinder/pythonfinder.py @@ -1,13 +1,8 @@ # -*- coding=utf-8 -*- -from __future__ import absolute_import, print_function - import importlib import operator import os -import pipenv.vendor.six as six -from pipenv.vendor.click import secho - from . import environment from .compat import lru_cache from .exceptions import InvalidPythonVersion @@ -98,7 +93,7 @@ def reload_system_path(self): self._system_path = self._system_path.clear_caches() self._system_path = None pyfinder_path = importlib.import_module("pythonfinder.models.path") - six.moves.reload_module(pyfinder_path) + importlib.reload(pyfinder_path) self._system_path = self.create_system_path() def rehash(self): @@ -146,7 +141,7 @@ def parse_major( # type: (...) -> Dict[str, Union[int, str, bool, None]] from .models import PythonVersion - major_is_str = major and isinstance(major, six.string_types) + major_is_str = major and isinstance(major, str) is_num = ( major and major_is_str @@ -253,7 +248,7 @@ def find_python_version( } # type: Dict[str, Union[str, int, Any]] if ( - isinstance(major, six.string_types) + isinstance(major, str) and pre is None and minor is None and dev is None @@ -270,7 +265,7 @@ def find_python_version( _dev = version_dict.get("is_devrelease", dev) dev = bool(_dev) if _dev is not None else dev if "architecture" in version_dict and isinstance( - version_dict["architecture"], six.string_types + version_dict["architecture"], str ): arch = version_dict["architecture"] # type: ignore if os.name == "nt" and self.windows_finder is not None: diff --git a/pipenv/vendor/pythonfinder/utils.py b/pipenv/vendor/pythonfinder/utils.py index 52ff7c91cb..bae43ee44e 100644 --- a/pipenv/vendor/pythonfinder/utils.py +++ b/pipenv/vendor/pythonfinder/utils.py @@ -1,6 +1,4 @@ # -*- coding=utf-8 -*- -from __future__ import absolute_import, print_function - import io import itertools import os @@ -11,23 +9,13 @@ from threading import Timer import pipenv.vendor.attr as attr -import pipenv.vendor.six as six from pipenv.patched.pip._vendor.packaging.version import LegacyVersion, Version from .compat import Path, TimeoutError, lru_cache # noqa from .environment import MYPY_RUNNING, PYENV_ROOT, SUBPROCESS_TIMEOUT from .exceptions import InvalidPythonVersion -six.add_move( - six.MovedAttribute("Iterable", "collections", "collections.abc") -) # type: ignore # noqa -six.add_move( - six.MovedAttribute("Sequence", "collections", "collections.abc") -) # type: ignore # noqa -# fmt: off -from pipenv.vendor.six.moves import Iterable # type: ignore # noqa # isort:skip -from pipenv.vendor.six.moves import Sequence # type: ignore # noqa # isort:skip -# fmt: on +from collections.abc import Iterable, Sequence if MYPY_RUNNING: from typing import Any, Callable, Dict, Iterator, List, Optional, Set, Tuple, Union @@ -332,13 +320,13 @@ def filter_pythons(path): def unnest(item): # type: (Any) -> Iterable[Any] target = None # type: Optional[Iterable] - if isinstance(item, Iterable) and not isinstance(item, six.string_types): + if isinstance(item, Iterable) and not isinstance(item, str): item, target = itertools.tee(item, 2) else: target = item if getattr(target, "__iter__", None): for el in target: - if isinstance(el, Iterable) and not isinstance(el, six.string_types): + if isinstance(el, Iterable) and not isinstance(el, str): el, el_copy = itertools.tee(el, 2) for sub in unnest(el_copy): yield sub @@ -384,7 +372,7 @@ def split_version_and_name( name=None, # type: Optional[str] ): # type: (...) -> Tuple[Optional[Union[str, int]], Optional[Union[str, int]], Optional[Union[str, int]], Optional[str]] # noqa - if isinstance(major, six.string_types) and not minor and not patch: + if isinstance(major, str) and not minor and not patch: # Only proceed if this is in the format "x.y.z" or similar if major.isdigit() or (major.count(".") > 0 and major[0].isdigit()): version = major.split(".", 2) diff --git a/pipenv/vendor/vendor.txt b/pipenv/vendor/vendor.txt index db2301528b..bbdbc7500f 100644 --- a/pipenv/vendor/vendor.txt +++ b/pipenv/vendor/vendor.txt @@ -19,7 +19,7 @@ ptyprocess==0.7.0 pyparsing==3.0.9 python-dateutil==2.8.2 python-dotenv==0.19.0 -pythonfinder==1.2.10 +pythonfinder==1.3.1 requirementslib==2.0.0 shellingham==1.4.0 six==1.16.0 From 53d4daf36156d409fb1c8c802d6813f1abf1274d Mon Sep 17 00:00:00 2001 From: Matt Davis Date: Wed, 24 Aug 2022 14:50:33 -0400 Subject: [PATCH 2/2] Add news fragment. --- news/5292.vendor.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 news/5292.vendor.rst diff --git a/news/5292.vendor.rst b/news/5292.vendor.rst new file mode 100644 index 0000000000..05f8f2fba7 --- /dev/null +++ b/news/5292.vendor.rst @@ -0,0 +1 @@ +Vendor in ``pythonfinder==1.3.1``