Skip to content

Commit

Permalink
Add a --keep-untracked option to the install command.
Browse files Browse the repository at this point in the history
  • Loading branch information
PetterS committed Mar 11, 2020
1 parent 54701a1 commit bbfc6c2
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
6 changes: 6 additions & 0 deletions poetry/console/commands/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ class InstallCommand(EnvCommand):
"Output the operations but do not execute anything "
"(implicitly enables --verbose).",
),
option(
"keep-untracked",
None,
"Does not remove packages not present in the lock file.",
),
option(
"extras",
"E",
Expand Down Expand Up @@ -58,6 +63,7 @@ def handle(self):
installer.extras(extras)
installer.dev_mode(not self.option("no-dev"))
installer.dry_run(self.option("dry-run"))
installer.keep_untracked(self.option("keep-untracked"))
installer.verbose(self.option("verbose"))

return_code = installer.run()
Expand Down
21 changes: 21 additions & 0 deletions poetry/installation/installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def __init__(
self._pool = pool

self._dry_run = False
self._keep_untracked = False
self._update = False
self._verbose = False
self._write_lock = True
Expand Down Expand Up @@ -83,6 +84,14 @@ def dry_run(self, dry_run=True): # type: (bool) -> Installer
def is_dry_run(self): # type: () -> bool
return self._dry_run

def keep_untracked(self, keep_untracked=True): # type: (bool) -> Installer
self._keep_untracked = keep_untracked

return self

def is_keep_untracked(self): # type: () -> bool
return self._keep_untracked

def verbose(self, verbose=True): # type: (bool) -> Installer
self._verbose = verbose

Expand Down Expand Up @@ -424,6 +433,18 @@ def _get_operations_from_lock(

ops.append(op)


if not self._keep_untracked:
for installed in installed_repo.packages:
is_in_lock_file = False
for locked in locked_repository.packages:
if locked.name == installed.name:
is_in_lock_file = True
break

if not is_in_lock_file:
ops.append(Uninstall(installed))

return ops

def _filter_operations(
Expand Down

0 comments on commit bbfc6c2

Please sign in to comment.