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

Add a --remove-untracked option to the install command. #2172

Merged
merged 13 commits into from
May 1, 2020
Prev Previous commit
Next Next commit
Merge with develop.
  • Loading branch information
PetterS committed May 1, 2020
commit 0dacf9fd2d45856333b1f50c8dafdc77c1620c85
40 changes: 29 additions & 11 deletions poetry/installation/installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
from poetry.puzzle.operations import Uninstall
from poetry.puzzle.operations import Update
from poetry.puzzle.operations.operation import Operation
from poetry.puzzle.provider import Provider
from poetry.repositories import Pool
from poetry.repositories import Repository
from poetry.repositories.installed_repository import InstalledRepository
Expand Down Expand Up @@ -206,17 +205,36 @@ def _do_install(self, local_repo):
root = root.clone()
del root.dev_requires[:]

if self._remove_untracked:
locked_names = {locked.name for locked in locked_repository.packages}
if self._io.is_verbose():
self._io.write_line("")
self._io.write_line(
"<info>Finding the necessary packages for the current system</>"
)

for installed in self._installed_repository.packages:
if installed.name == self._package.name:
continue
if installed.name in Provider.UNSAFE_PACKAGES:
# Never remove pip, setuptools etc.
continue
if installed.name not in locked_names:
ops.append(Uninstall(installed))
# We resolve again by only using the lock file
pool = Pool(ignore_repository_names=True)

# Making a new repo containing the packages
# newly resolved and the ones from the current lock file
repo = Repository()
for package in local_repo.packages + locked_repository.packages:
if not repo.has_package(package):
repo.add_package(package)

pool.add_repository(repo)

# We whitelist all packages to be sure
# that the latest ones are picked up
whitelist = []
for pkg in locked_repository.packages:
whitelist.append(pkg.name)

solver = Solver(
root, pool, self._installed_repository, locked_repository, NullIO()
)

with solver.use_environment(self._env):
ops = solver.solve(use_latest=whitelist)

# We need to filter operations so that packages
# not compatible with the current system,
Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.