mirror of
https://github.com/kennethreitz/pipenv.git
synced 2026-06-05 22:50:18 +00:00
Merge pull request #3254 from pypa/vendoring-update
Update requirementslib and pythonfinder
This commit is contained in:
@@ -0,0 +1 @@
|
||||
Updated ``requirementslib`` and ``pythonfinder`` for multiple bugfixes.
|
||||
+1
-1
@@ -7,7 +7,7 @@ import sys
|
||||
PYENV_INSTALLED = bool(os.environ.get("PYENV_SHELL")) or bool(
|
||||
os.environ.get("PYENV_ROOT")
|
||||
)
|
||||
ASDF_INSTALLED = bool(os.environ.get("ASDF_DATA_DIR"))
|
||||
ASDF_INSTALLED = bool(os.environ.get("ASDF_DIR"))
|
||||
PYENV_ROOT = os.path.expanduser(
|
||||
os.path.expandvars(os.environ.get("PYENV_ROOT", "~/.pyenv"))
|
||||
)
|
||||
|
||||
+9
-2
@@ -484,7 +484,14 @@ class PathEntry(BasePath):
|
||||
for child in self._filter_children():
|
||||
if any(shim in normalize_path(str(child)) for shim in SHIM_PATHS):
|
||||
continue
|
||||
yield (child.as_posix(), PathEntry.create(path=child, **pass_args))
|
||||
if self.only_python:
|
||||
try:
|
||||
entry = PathEntry.create(path=child, **pass_args)
|
||||
except (InvalidPythonVersion, ValueError):
|
||||
continue
|
||||
else:
|
||||
entry = PathEntry.create(path=child, **pass_args)
|
||||
yield (child.as_posix(), entry)
|
||||
return
|
||||
|
||||
@cached_property
|
||||
@@ -508,7 +515,7 @@ class PathEntry(BasePath):
|
||||
if self.is_python:
|
||||
try:
|
||||
py_version = PythonVersion.from_path(path=self, name=self.name)
|
||||
except InvalidPythonVersion:
|
||||
except (InvalidPythonVersion, ValueError):
|
||||
py_version = None
|
||||
except Exception:
|
||||
if not IGNORE_UNSUPPORTED:
|
||||
|
||||
+26
-12
@@ -25,6 +25,7 @@ from ..utils import (
|
||||
is_in_path,
|
||||
parse_pyenv_version_order,
|
||||
parse_asdf_version_order,
|
||||
parse_python_version,
|
||||
)
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@@ -361,19 +362,32 @@ class PythonVersion(object):
|
||||
try:
|
||||
version = parse_version(str(version))
|
||||
except TypeError:
|
||||
raise ValueError("Unable to parse version: %s" % version)
|
||||
if not version or not version.release:
|
||||
raise ValueError("Not a valid python version: %r" % version)
|
||||
return
|
||||
if len(version.release) >= 3:
|
||||
major, minor, patch = version.release[:3]
|
||||
elif len(version.release) == 2:
|
||||
major, minor = version.release
|
||||
patch = None
|
||||
try:
|
||||
version_dict = parse_python_version(str(version))
|
||||
except Exception:
|
||||
raise ValueError("Unable to parse version: %s" % version)
|
||||
else:
|
||||
if not version_dict:
|
||||
raise ValueError("Not a valid python version: %r" % version)
|
||||
major = int(version_dict.get("major"))
|
||||
minor = int(version_dict.get("minor"))
|
||||
patch = version_dict.get("patch")
|
||||
if patch:
|
||||
patch = int(patch)
|
||||
version = ".".join([v for v in [major, minor, patch] if v is not None])
|
||||
version = parse_version(version)
|
||||
else:
|
||||
major = version.release[0]
|
||||
minor = None
|
||||
patch = None
|
||||
if not version or not version.release:
|
||||
raise ValueError("Not a valid python version: %r" % version)
|
||||
if len(version.release) >= 3:
|
||||
major, minor, patch = version.release[:3]
|
||||
elif len(version.release) == 2:
|
||||
major, minor = version.release
|
||||
patch = None
|
||||
else:
|
||||
major = version.release[0]
|
||||
minor = None
|
||||
patch = None
|
||||
return {
|
||||
"major": major,
|
||||
"minor": minor,
|
||||
|
||||
Vendored
+16
-2
@@ -8,6 +8,7 @@ from fnmatch import fnmatch
|
||||
|
||||
import attr
|
||||
import io
|
||||
import re
|
||||
import six
|
||||
|
||||
import vistir
|
||||
@@ -24,6 +25,9 @@ except ImportError:
|
||||
from backports.functools_lru_cache import lru_cache
|
||||
|
||||
|
||||
version_re = re.compile(r"(?P<major>[0-9]+)\.(?P<minor>[0-9]+)\.?(?P<patch>(?<=\.)[0-9]+)")
|
||||
|
||||
|
||||
PYTHON_IMPLEMENTATIONS = (
|
||||
"python", "ironpython", "jython", "pypy", "anaconda", "miniconda",
|
||||
"stackless", "activepython", "micropython"
|
||||
@@ -46,13 +50,13 @@ for rule in RULES:
|
||||
)
|
||||
|
||||
|
||||
@lru_cache(maxsize=128)
|
||||
@lru_cache(maxsize=1024)
|
||||
def get_python_version(path):
|
||||
"""Get python version string using subprocess from a given path."""
|
||||
version_cmd = [path, "-c", "import sys; print(sys.version.split()[0])"]
|
||||
try:
|
||||
c = vistir.misc.run(version_cmd, block=True, nospin=True, return_object=True,
|
||||
combine_stderr=False)
|
||||
combine_stderr=False, write_to_stdout=False)
|
||||
except OSError:
|
||||
raise InvalidPythonVersion("%s is not a valid python path" % path)
|
||||
if not c.out:
|
||||
@@ -60,6 +64,14 @@ def get_python_version(path):
|
||||
return c.out.strip()
|
||||
|
||||
|
||||
@lru_cache(maxsize=1024)
|
||||
def parse_python_version(version_str):
|
||||
m = version_re.match(version_str)
|
||||
if not m:
|
||||
raise InvalidPythonVersion("%s is not a python version" % version_str)
|
||||
return m.groupdict()
|
||||
|
||||
|
||||
def optional_instance_of(cls):
|
||||
return attr.validators.optional(attr.validators.instance_of(cls))
|
||||
|
||||
@@ -151,6 +163,7 @@ def parse_pyenv_version_order(filename="version"):
|
||||
contents = fh.read()
|
||||
version_order = [v for v in contents.splitlines()]
|
||||
return version_order
|
||||
return []
|
||||
|
||||
|
||||
def parse_asdf_version_order(filename=".tool-versions"):
|
||||
@@ -165,6 +178,7 @@ def parse_asdf_version_order(filename=".tool-versions"):
|
||||
python_key, _, versions = python_section.partition(" ")
|
||||
if versions:
|
||||
return versions.split()
|
||||
return []
|
||||
|
||||
|
||||
# TODO: Reimplement in vistir
|
||||
|
||||
+11
-6
@@ -160,7 +160,7 @@ class Lockfile(object):
|
||||
path = os.curdir
|
||||
path = Path(path).absolute()
|
||||
project_path = path if path.is_dir() else path.parent
|
||||
lockfile_path = project_path / "Pipfile.lock"
|
||||
lockfile_path = path if path.is_file() else project_path / "Pipfile.lock"
|
||||
if not project_path.exists():
|
||||
raise OSError("Project does not exist: %s" % project_path.as_posix())
|
||||
elif not lockfile_path.exists() and not create:
|
||||
@@ -168,7 +168,12 @@ class Lockfile(object):
|
||||
projectfile = cls.read_projectfile(lockfile_path.as_posix())
|
||||
if not lockfile_path.exists():
|
||||
if not data:
|
||||
lf = cls.lockfile_from_pipfile(project_path.joinpath("Pipfile"))
|
||||
path_str = lockfile_path.as_posix()
|
||||
if path_str[-5:] == ".lock":
|
||||
pipfile = Path(path_str[:-5])
|
||||
else:
|
||||
pipfile = project_path.joinpath("Pipfile")
|
||||
lf = cls.lockfile_from_pipfile(pipfile)
|
||||
else:
|
||||
lf = plette.lockfiles.Lockfile(data)
|
||||
projectfile.model = lf
|
||||
@@ -212,7 +217,7 @@ class Lockfile(object):
|
||||
def load(cls, path, create=True):
|
||||
"""Create a new lockfile instance.
|
||||
|
||||
:param project_path: Path to project root
|
||||
:param project_path: Path to project root or lockfile
|
||||
:type project_path: str or :class:`pathlib.Path`
|
||||
:param str lockfile_name: Name of the lockfile in the project root directory
|
||||
:param pipfile_path: Path to the project pipfile
|
||||
@@ -225,9 +230,9 @@ class Lockfile(object):
|
||||
projectfile = cls.load_projectfile(path, create=create)
|
||||
except JSONDecodeError:
|
||||
path = os.path.abspath(path)
|
||||
if not os.path.isdir(path):
|
||||
path = os.path.dirname(path)
|
||||
path = Path(os.path.join(path, "Pipfile.lock"))
|
||||
path = Path(
|
||||
os.path.join(path, "Pipfile.lock") if os.path.isdir(path) else path
|
||||
)
|
||||
formatted_path = path.as_posix()
|
||||
backup_path = "%s.bak" % formatted_path
|
||||
LockfileCorruptException.show(formatted_path, backup_path=backup_path)
|
||||
|
||||
+1
-1
@@ -187,7 +187,7 @@ class Pipfile(object):
|
||||
raise RuntimeError("Must pass a path to classmethod 'Pipfile.load'")
|
||||
if not isinstance(path, Path):
|
||||
path = Path(path).absolute()
|
||||
pipfile_path = path if path.name == "Pipfile" else path.joinpath("Pipfile")
|
||||
pipfile_path = path if path.is_file() else path.joinpath("Pipfile")
|
||||
project_path = pipfile_path.parent
|
||||
if not project_path.exists():
|
||||
raise FileNotFoundError("%s is not a valid project path!" % path)
|
||||
|
||||
+6
-5
@@ -103,7 +103,7 @@ def iter_egginfos(path, pkg_name=None):
|
||||
if not entry.name.endswith("egg-info"):
|
||||
for dir_entry in iter_egginfos(entry.path, pkg_name=pkg_name):
|
||||
yield dir_entry
|
||||
elif pkg_name is None or entry.name.startswith(pkg_name):
|
||||
elif pkg_name is None or entry.name.startswith(pkg_name.replace("-", "_")):
|
||||
yield entry
|
||||
|
||||
|
||||
@@ -223,16 +223,16 @@ class SetupInfo(object):
|
||||
if self.setup_py is not None and self.setup_py.exists():
|
||||
target_cwd = self.setup_py.parent.as_posix()
|
||||
with cd(target_cwd), _suppress_distutils_logs():
|
||||
# This is for you, Hynek
|
||||
# see https://github.com/hynek/environ_config/blob/69b1c8a/setup.py
|
||||
script_name = self.setup_py.as_posix()
|
||||
args = ["egg_info", "--egg-base", self.base_dir]
|
||||
args = ["egg_info"]
|
||||
g = {"__file__": script_name, "__name__": "__main__"}
|
||||
local_dict = {}
|
||||
if sys.version_info < (3, 5):
|
||||
save_argv = sys.argv
|
||||
else:
|
||||
save_argv = sys.argv.copy()
|
||||
# This is for you, Hynek
|
||||
# see https://github.com/hynek/environ_config/blob/69b1c8a/setup.py
|
||||
try:
|
||||
global _setup_distribution, _setup_stop_after
|
||||
_setup_stop_after = "run"
|
||||
@@ -247,7 +247,8 @@ class SetupInfo(object):
|
||||
except NameError:
|
||||
python = os.environ.get('PIP_PYTHON_PATH', sys.executable)
|
||||
out, _ = run([python, "setup.py"] + args, cwd=target_cwd, block=True,
|
||||
combine_stderr=False, return_object=False, nospin=True)
|
||||
combine_stderr=False, return_object=False, nospin=True,
|
||||
write_to_stdout=False)
|
||||
finally:
|
||||
_setup_stop_after = None
|
||||
sys.argv = save_argv
|
||||
|
||||
Vendored
+1
-2
@@ -138,7 +138,6 @@ def _spawn_subprocess(script, env=None, block=True, cwd=None, combine_stderr=Tru
|
||||
return subprocess.Popen(script.cmdify(), **options)
|
||||
|
||||
|
||||
|
||||
def _create_subprocess(
|
||||
cmd,
|
||||
env=None,
|
||||
@@ -153,7 +152,7 @@ def _create_subprocess(
|
||||
write_to_stdout=True
|
||||
):
|
||||
if not env:
|
||||
env = {}
|
||||
env = os.environ.copy()
|
||||
try:
|
||||
c = _spawn_subprocess(cmd, env=env, block=block, cwd=cwd,
|
||||
combine_stderr=combine_stderr)
|
||||
|
||||
Reference in New Issue
Block a user