Skip to content

Commit

Permalink
The --target option will not overwrite without --upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
dwoz committed Feb 21, 2024
1 parent b9ac4c0 commit 54ea428
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 20 deletions.
4 changes: 1 addition & 3 deletions news/10110.bugfix.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
Pip install's ``--target`` works more like the other 'install schemas'. This
fixes installing namespaced packages. A caviate is that the directory must be
in python's path to avoid un-intential upgrades. This logic now works the same
way as ``--prefix`` when it comes to upgrading pacakges.
fixes installing namespaced packages.
11 changes: 5 additions & 6 deletions src/pip/_internal/commands/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import operator
import os
import site
import sys
from optparse import SUPPRESS_HELP, Values
from typing import List, Optional

Expand Down Expand Up @@ -91,11 +92,7 @@ def add_options(self) -> None:
dest="target_dir",
metavar="dir",
default=None,
help=(
"Install packages into <dir>."
"The directory should also be in python's path to aviod "
"un-intential upgrading of packages."
),
help=("Install packages into <dir>."),
)
cmdoptions.add_target_python_options(self.cmd_opts)

Expand Down Expand Up @@ -313,6 +310,9 @@ def run(self, options: Values, args: List[str]) -> int:

global_options = options.global_options or []

if options.target_dir is not None and options.target_dir not in sys.path:
sys.path.append(options.target_dir)

session = self.get_default_session(options)

target_python = make_target_python(options)
Expand Down Expand Up @@ -365,7 +365,6 @@ def run(self, options: Values, args: List[str]) -> int:
)

self.trace_basic_info(finder)

requirement_set = resolver.resolve(
reqs, check_supported_wheels=not options.target_dir
)
Expand Down
12 changes: 1 addition & 11 deletions tests/functional/test_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -1107,18 +1107,8 @@ def test_install_package_with_target(script: PipTestEnvironment) -> None:
result = script.pip_install_local("-t", target_dir, "simple==1.0")
result.did_create(Path("scratch") / "target" / "simple")

# When the target location is not in the path packages are installed over
# eachother.
result = script.pip_install_local(
"-t",
target_dir,
"simple==1.0",
)
result.did_update(Path("scratch") / "target" / "simple")

# When target directory is in python path repeated call without --upgrade,
# When using target directory repeated call without --upgrade,
# no files should have changed
script.environ["PYTHONPATH"] = target_dir
result = script.pip_install_local(
"-t",
target_dir,
Expand Down

0 comments on commit 54ea428

Please sign in to comment.