Skip to content

Commit

Permalink
Merge pull request #125 from frostming/upgrade-pip
Browse files Browse the repository at this point in the history
Upgrade pip
  • Loading branch information
frostming authored Jun 12, 2020
2 parents c056a5b + 33106e6 commit 765f602
Show file tree
Hide file tree
Showing 10 changed files with 171 additions and 144 deletions.
1 change: 1 addition & 0 deletions news/125.dep
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Upgrade dependency `pip` to `20.1`.
234 changes: 115 additions & 119 deletions pdm.lock

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion pdm/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ def __call__(self, *args, **kwargs):

def main(self, args=None, prog_name=None, obj=None, **extra):
"""The main entry function"""
from pip._internal.utils.temp_dir import global_tempdir_manager

self.init_parser()
self.load_plugins()

Expand All @@ -93,7 +95,8 @@ def main(self, args=None, prog_name=None, obj=None, **extra):
sys.exit(1)
else:
try:
f(options.project, options)
with global_tempdir_manager():
f(options.project, options)
except Exception:
etype, err, traceback = sys.exc_info()
if stream.verbosity > stream.NORMAL:
Expand Down
7 changes: 6 additions & 1 deletion pdm/formats/requirements.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,13 @@ def requirement_from_ireq(ireq):


def parse_requirement_file(filename):
from pip._internal.req.constructors import install_req_from_parsed_requirement

finder = get_finder([])
ireqs = list(parse_requirements(filename, finder.session, finder))
ireqs = [
install_req_from_parsed_requirement(pr)
for pr in parse_requirements(filename, finder.session, finder)
]
return ireqs, finder


Expand Down
37 changes: 18 additions & 19 deletions pdm/models/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
get_python_version,
get_sys_config_paths,
get_venv_python,
populate_link,
temp_environ,
)

Expand Down Expand Up @@ -272,7 +273,6 @@ def build(
:param allow_all: Allow building incompatible wheels.
:returns: The full path of the built artifact.
"""
from pip._internal.utils.temp_dir import global_tempdir_manager
from pdm.builders import EditableBuilder
from pdm.builders import WheelBuilder

Expand All @@ -281,9 +281,9 @@ def build(
if allow_all:
with allow_all_wheels():
# temporarily allow all wheels to get a link.
ireq.populate_link(finder, False, bool(hashes))
populate_link(finder, ireq, False)
else:
ireq.populate_link(finder, False, bool(hashes))
populate_link(finder, ireq, False)
if not ireq.editable and not ireq.req.name:
ireq.source_dir = kwargs["build_dir"]
else:
Expand All @@ -295,23 +295,22 @@ def build(
download_dir = kwargs["wheel_download_dir"]
only_download = True
if hashes:
ireq.options["hashes"] = convert_hashes(hashes)
ireq.hash_options = convert_hashes(hashes)
if not (ireq.editable and ireq.req.is_local_dir):
with global_tempdir_manager():
downloader = shims.Downloader(finder.session, "off")
downloaded = shims.unpack_url(
ireq.link,
ireq.source_dir,
downloader,
download_dir,
ireq.hashes(False),
)
# Preserve the downloaded file so that it won't be cleared.
if downloaded and only_download:
try:
shutil.copy(downloaded, download_dir)
except shutil.SameFileError:
pass
downloader = shims.Downloader(finder.session, "off")
downloaded = shims.unpack_url(
ireq.link,
ireq.source_dir,
downloader,
download_dir,
ireq.hashes(False),
)
# Preserve the downloaded file so that it won't be cleared.
if downloaded and only_download:
try:
shutil.copy(downloaded.path, download_dir)
except shutil.SameFileError:
pass
# Now all source is prepared, build it.
if ireq.link.is_wheel:
return (self.project.cache("wheels") / ireq.link.filename).as_posix()
Expand Down
18 changes: 17 additions & 1 deletion pdm/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,13 @@

from distlib.wheel import Wheel
from packaging.version import parse as parse_version
from pip_shims.shims import InstallCommand, PackageFinder, TargetPython, url_to_path
from pip_shims.shims import (
InstallCommand,
InstallRequirement,
PackageFinder,
TargetPython,
url_to_path,
)

from pdm._types import Source

Expand Down Expand Up @@ -506,3 +512,13 @@ def get_platform():
def highest_version(versions: List[str]) -> str:
"""Return the highest version of a given list."""
return max(versions, key=parse_version)


def populate_link(
finder: PackageFinder, ireq: InstallRequirement, upgrade: bool = False
):
"""Populate ireq's link attribute"""
if ireq.link:
return
link = finder.find_requirement(ireq, upgrade)
ireq.link = link
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Documentation = "https://pdm.fming.dev"
appdirs = "*"
click = "*"
distlib = "*"
pip = "<20.1,>=20.0"
pip = ">=20.1"
pip_shims = "*"
pythonfinder = "*"
tomlkit = "*"
Expand Down
2 changes: 1 addition & 1 deletion setup_dev.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def main():

print("Installing base requirements...", flush=True)
subprocess.check_call(
[venv_python.as_posix(), "-m", "pip", "install", "-U", "pip<20.1", "pdm"]
[venv_python.as_posix(), "-m", "pip", "install", "-U", "pip", "pdm"]
)

print("Setup project for development...", flush=True)
Expand Down
1 change: 0 additions & 1 deletion tests/cli/test_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,6 @@ def test_list_dependency_graph(capsys):
actions.do_list(project, True)
content, _ = capsys.readouterr()
assert "halo 0.0.29 [ required: <1.0.0,>=0.0.28 ]" in content
assert "six 1.14.0 [ required: >=1.12.0 ]" in content


def test_list_dependency_graph_with_circular(project, capsys, repository, working_set):
Expand Down
8 changes: 8 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,14 @@ def get_local_finder(*args, **kwargs):
return finder


@pytest.fixture(autouse=True)
def pip_global_tempdir_manager():
from pip._internal.utils.temp_dir import global_tempdir_manager

with global_tempdir_manager():
yield


@pytest.fixture()
def project_no_init(tmp_path, mocker):
p = TestProject(tmp_path.as_posix())
Expand Down

0 comments on commit 765f602

Please sign in to comment.