Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vendor in pythonfinder==1.3.1 #5292

Merged
merged 2 commits into from
Aug 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions news/5292.vendor.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Vendor in ``pythonfinder==1.3.1``
2 changes: 1 addition & 1 deletion pipenv/vendor/pythonfinder/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand Down
23 changes: 8 additions & 15 deletions pipenv/vendor/pythonfinder/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()]
Expand Down
21 changes: 3 additions & 18 deletions pipenv/vendor/pythonfinder/compat.py
Original file line number Diff line number Diff line change
@@ -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():
Expand All @@ -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


Expand Down
2 changes: 0 additions & 2 deletions pipenv/vendor/pythonfinder/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 1 addition & 3 deletions pipenv/vendor/pythonfinder/models/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
16 changes: 9 additions & 7 deletions pipenv/vendor/pythonfinder/models/path.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
14 changes: 6 additions & 8 deletions pipenv/vendor/pythonfinder/models/python.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# -*- coding=utf-8 -*-
from __future__ import absolute_import, print_function

import logging
import operator
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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():
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand Down
13 changes: 4 additions & 9 deletions pipenv/vendor/pythonfinder/pythonfinder.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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:
Expand Down
20 changes: 4 additions & 16 deletions pipenv/vendor/pythonfinder/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# -*- coding=utf-8 -*-
from __future__ import absolute_import, print_function

import io
import itertools
import os
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion pipenv/vendor/vendor.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down