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

This change gets pipenv working with pip 22.x #79

Merged
merged 10 commits into from
Mar 28, 2022
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: [3.6, 3.7, 3.8, 3.9, "3.10"]
python-version: [3.7, 3.8, 3.9, "3.10"]
os: [macos, ubuntu, windows]

steps:
Expand Down
1 change: 1 addition & 0 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"pip~=21.1.0",
"pip~=21.2.0",
"pip~=21.3.0",
"pip~=22.0.0",
"git+https://github.com/pypa/pip.git",
]

Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ exclude =
.cache,
.eggs,
setup.py,
max-complexity=13
max-complexity=16

[mypy]
ignore_missing_imports=true
Expand Down
2 changes: 1 addition & 1 deletion src/pip_shims/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding=utf-8 -*-
"""
This library is a set of compatibilty access shims to the ``pip`` internal API.
This library is a set of compatibility access shims to the ``pip`` internal API.
It provides compatibility with pip versions 8.0 through the current release. The
shims are provided using a lazy import strategy by hacking a module by overloading
a class instance's ``getattr`` method. This library exists due to my constant
Expand Down
17 changes: 16 additions & 1 deletion src/pip_shims/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
TFinder = TypeVar("TFinder")
TResolver = TypeVar("TResolver")
TReqTracker = TypeVar("TReqTracker")
TBuildTracker = TypeVar("TBuildTracker")
TReqSet = TypeVar("TReqSet")
TLink = TypeVar("TLink")
TSession = TypeVar("TSession", bound=Session)
Expand Down Expand Up @@ -708,6 +709,7 @@ def shim_unpack(
only_download=None, # type: Optional[bool]
downloader_provider=None, # type: Optional[TShimmedFunc]
session=None, # type: Optional[Any]
verbosity=0, # type: Optional[int]
):
# (...) -> None
"""
Expand Down Expand Up @@ -735,6 +737,7 @@ def shim_unpack(
to instantiate, if applicable.
:param Optional[`~requests.Session`] session: A PipSession instance, defaults to
None.
:param Optional[int] verbosity: 1 or 0 to indicate verbosity flag, defaults to 0.
:return: The result of unpacking the url.
:rtype: None
"""
Expand Down Expand Up @@ -769,6 +772,8 @@ def shim_unpack(
assert session is not None
assert progress_bar is not None
unpack_kwargs[arg_name] = downloader_provider(session, progress_bar)
if "verbosity" in required_args:
unpack_kwargs["verbosity"] = verbosity
return unpack_fn(**unpack_kwargs) # type: ignore


Expand Down Expand Up @@ -812,10 +817,12 @@ def make_preparer(
require_hashes=None, # type: Optional[bool]
use_user_site=None, # type: Optional[bool]
req_tracker=None, # type: Optional[Union[TReqTracker, TShimmedFunc]]
build_tracker=None, # type: Optional[Union[TBuildTracker, TShimmedFunc]]
install_cmd_provider=None, # type: Optional[TShimmedFunc]
downloader_provider=None, # type: Optional[TShimmedFunc]
install_cmd=None, # type: Optional[TCommandInstance]
finder_provider=None, # type: Optional[TShimmedFunc]
verbosity=0, # type: Optional[int]
):
# (...) -> ContextManager
"""
Expand Down Expand Up @@ -851,6 +858,8 @@ def make_preparer(
preparing requirements
:param Optional[Union[TReqTracker, TShimmedFunc]] req_tracker: The requirement
tracker to use for building packages, defaults to None
:param Optional[Union[TBuildTracker, TShimmedFunc]] build_tracker: The build
tracker to use for building packages, defaults to None and fallsback to req_tracker.
:param Optional[TShimmedFunc] downloader_provider: A downloader provider
:param Optional[TCommandInstance] install_cmd: The install command used to create
the finder, session, and options if needed, defaults to None
Expand Down Expand Up @@ -883,7 +892,6 @@ def make_preparer(
raise TypeError("No requirement tracker and no req tracker generator found!")
if "downloader" in required_args and not downloader_provider:
raise TypeError("no downloader provided, but one is required to continue!")
req_tracker_fn = resolve_possible_shim(req_tracker_fn)
pip_options_created = options is None
session_is_required = "session" in required_args
finder_is_required = "finder" in required_args
Expand Down Expand Up @@ -924,11 +932,18 @@ def make_preparer(
preparer_args["downloader"] = downloader_provider(session, progress_bar)
if "in_tree_build" in required_args:
preparer_args["in_tree_build"] = True
if "verbosity" in required_args:
preparer_args["verbosity"] = verbosity
req_tracker_fn = resolve_possible_shim(req_tracker_fn)
req_tracker_fn = nullcontext if not req_tracker_fn else req_tracker_fn
with req_tracker_fn() as tracker_ctx:
if "req_tracker" in required_args:
req_tracker = tracker_ctx if req_tracker is None else req_tracker
preparer_args["req_tracker"] = req_tracker
if "build_tracker" in required_args:
req_tracker = tracker_ctx if req_tracker is None else req_tracker
build_tracker = req_tracker if build_tracker is None else build_tracker
preparer_args["build_tracker"] = build_tracker
preparer_args["lazy_wheel"] = True
result = call_function_with_correct_args(preparer_fn, **preparer_args)
yield result
Expand Down
6 changes: 4 additions & 2 deletions tests/test_instances.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,8 @@ def test_resolution(tmpdir, PipCommand):
"ignore_requires_python": selection_prefs.ignore_requires_python,
}
)
if parse_version(pip_version) >= parse_version("22.0"):
finder_args["use_deprecated_html5lib"] = False
else:
finder_args = {
"find_links": pip_options.find_links,
Expand All @@ -246,7 +248,6 @@ def test_resolution(tmpdir, PipCommand):
"session": session,
"allow_all_prereleases": False,
}
# finder_args["allow_all_prereleases"] = False
finder = PackageFinder(**finder_args)
ireq = InstallRequirement.from_line("requests>=2.18")
if install_req_from_line:
Expand Down Expand Up @@ -424,6 +425,8 @@ def test_wheelbuilder(tmpdir, PipCommand):
"ignore_requires_python": selection_prefs.ignore_requires_python,
}
)
if parse_version(pip_version) >= parse_version("22.0"):
finder_args["use_deprecated_html5lib"] = False
else:
finder_args = {
"find_links": pip_options.find_links,
Expand All @@ -432,7 +435,6 @@ def test_wheelbuilder(tmpdir, PipCommand):
"session": session,
"allow_all_prereleases": False,
}
# finder_args["allow_all_prereleases"] = False
finder = PackageFinder(**finder_args)
build_dir = tmpdir.mkdir("build_dir")
source_dir = tmpdir.mkdir("source_dir")
Expand Down