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 requirementslib==2.0.0 & drop pip-shims & revert sysconfig patch w/ safer setuptools usage #5228

Merged
merged 14 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
2 changes: 2 additions & 0 deletions news/5228.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Remove eager and unnecessary importing of ``setuptools`` and ``pkg_resources`` to avoid conflict upgrading ``setuptools``.
Roll back ``sysconfig`` patch of ``pip`` because it was problematic for some ``--system`` commands.
1 change: 1 addition & 0 deletions news/5228.vendor.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Vendor in ``requirementslib==2.0.0`` and drop ``pip-shims`` entirely.
1 change: 0 additions & 1 deletion pipenv/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@


# Load patched pip instead of system pip
os.environ["PIP_SHIMS_BASE_MODULE"] = "pipenv.patched.pip"
os.environ["PIP_DISABLE_PIP_VERSION_CHECK"] = "1"

# Hack to make things work better.
Expand Down
7 changes: 0 additions & 7 deletions pipenv/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -2095,7 +2095,6 @@ def do_install(
pypi_mirror=pypi_mirror,
skip_lock=skip_lock,
)
pip_shims_module = os.environ.pop("PIP_SHIMS_BASE_MODULE", None)
for pkg_line in pkg_list:
click.secho(
fix_utf8(f"Installing {pkg_line}..."),
Expand Down Expand Up @@ -2232,8 +2231,6 @@ def do_install(
# Update project settings with pre preference.
if pre:
project.update_settings({"allow_prereleases": pre})
if pip_shims_module:
os.environ["PIP_SHIMS_BASE_MODULE"] = pip_shims_module
do_init(
project,
dev=dev,
Expand Down Expand Up @@ -2439,8 +2436,6 @@ def do_shell(
# otherwise its value will be changed
os.environ["PIPENV_ACTIVE"] = "1"

os.environ.pop("PIP_SHIMS_BASE_MODULE", None)

if fancy:
shell.fork(*fork_args)
return
Expand Down Expand Up @@ -2591,7 +2586,6 @@ def do_run(

load_dot_env(project, quiet=quiet)
env = os.environ.copy()
env.pop("PIP_SHIMS_BASE_MODULE", None)

path = env.get("PATH", "")
if project.virtualenv_location:
Expand All @@ -2609,7 +2603,6 @@ def do_run(
# such as in inline_activate_virtual_environment
# otherwise its value will be changed
env["PIPENV_ACTIVE"] = "1"
env.pop("PIP_SHIMS_BASE_MODULE", None)

try:
script = project.build_script(command, args)
Expand Down
54 changes: 10 additions & 44 deletions pipenv/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import pipenv
from pipenv.patched.pip._internal.commands.install import InstallCommand
from pipenv.patched.pip._internal.index.package_finder import PackageFinder
from pipenv.patched.pip._internal.req.req_uninstall import UninstallPathSet
from pipenv.patched.pip._vendor.packaging.utils import canonicalize_name
from pipenv.utils.constants import is_type_checking
from pipenv.utils.indexes import prepare_pip_source_args
Expand Down Expand Up @@ -954,24 +955,6 @@ def which(self, search, as_path=True):
result = str(result.path)
return result

def get_install_args(self, editable=False, setup_path=None):
install_arg = "install" if not editable else "develop"
install_keys = ["headers", "purelib", "platlib", "scripts", "data"]
install_args = [
self.environment.python,
"-u",
"-c",
SETUPTOOLS_SHIM % setup_path,
install_arg,
"--single-version-externally-managed",
"--no-deps",
"--prefix={}".format(self.base_paths["prefix"]),
"--no-warn-script-location",
]
for key in install_keys:
install_args.append(f"--install-{key}={self.base_paths[key]}")
return install_args

def install(self, requirements):
if not isinstance(requirements, (tuple, list)):
requirements = [requirements]
Expand Down Expand Up @@ -1031,36 +1014,19 @@ def uninstall(self, pkgname, *args, **kwargs):
)
if monkey_patch:
monkey_patch.activate()
pip_shims = self.safe_import("pip_shims")
pathset_base = pip_shims.UninstallPathSet
pathset_base._permitted = PatchedUninstaller._permitted
dist = next(
iter(d for d in self.get_working_set() if d.project_name == pkgname), None
)
pathset = pathset_base.from_dist(dist)
if pathset is not None:
pathset.remove(auto_confirm=auto_confirm, verbose=verbose)
path_set = UninstallPathSet.from_dist(dist)
if path_set is not None:
path_set.remove(auto_confirm=auto_confirm, verbose=verbose)
try:
yield pathset
yield path_set
except Exception:
if pathset is not None:
pathset.rollback()
if path_set is not None:
path_set.rollback()
else:
if pathset is not None:
pathset.commit()
if pathset is None:
if path_set is not None:
path_set.commit()
if path_set is None:
return


class PatchedUninstaller:
def _permitted(self, path):
return True


SETUPTOOLS_SHIM = (
"import setuptools, tokenize;__file__=%r;"
"f=getattr(tokenize, 'open', open)(__file__);"
"code=f.read().replace('\\r\\n', '\\n');"
"f.close();"
"exec(compile(code, __file__, 'exec'))"
)
4 changes: 0 additions & 4 deletions pipenv/help.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,12 @@


def get_pipenv_diagnostics(project):
import setuptools

print("<details><summary>$ pipenv --support</summary>")
print("")
print(f"Pipenv version: `{pipenv.__version__!r}`")
print("")
print(f"Pipenv location: `{os.path.dirname(pipenv.__file__)!r}`")
print("")
print(f"setuptools version: `{setuptools.__version__!r}`")
print("")
print(f"Python location: `{sys.executable!r}`")
print("")
print(f"OS Name: `{os.name!r}`")
Expand Down
2 changes: 1 addition & 1 deletion pipenv/patched/pip/_internal/locations/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@

_PLATLIBDIR: str = getattr(sys, "platlibdir", "lib")

_USE_SYSCONFIG_DEFAULT = sys.version_info >= (3, 7)
_USE_SYSCONFIG_DEFAULT = sys.version_info >= (3, 10)


def _should_use_sysconfig() -> bool:
Expand Down
16 changes: 4 additions & 12 deletions pipenv/utils/dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from typing import Mapping, Sequence

from pipenv.patched.pip._vendor.packaging.markers import Marker
from pipenv.patched.pip._vendor.packaging.version import parse

from .constants import SCHEME_LIST, VCS_LIST
from .shell import temp_path
Expand Down Expand Up @@ -61,10 +62,7 @@ def get_canonical_names(packages):

def pep440_version(version):
"""Normalize version to PEP 440 standards"""
# Use pip built-in version parser.
from pipenv.vendor.pip_shims import shims

return str(shims.parse_version(version))
return str(parse(version))


def pep423_name(name):
Expand Down Expand Up @@ -360,12 +358,6 @@ def locked_repository(requirement):

if not requirement.is_vcs:
return
original_base = os.environ.pop("PIP_SHIMS_BASE_MODULE", None)
os.environ["PIP_SHIMS_BASE_MODULE"] = "pipenv.patched.pip"
src_dir = create_tracked_tempdir(prefix="pipenv-", suffix="-src")
try:
with requirement.req.locked_vcs_repo(src_dir=src_dir) as repo:
yield repo
finally:
if original_base:
os.environ["PIP_SHIMS_BASE_MODULE"] = original_base
with requirement.req.locked_vcs_repo(src_dir=src_dir) as repo:
yield repo
13 changes: 0 additions & 13 deletions pipenv/vendor/pip_shims/LICENSE

This file was deleted.

54 changes: 0 additions & 54 deletions pipenv/vendor/pip_shims/__init__.py

This file was deleted.

Loading