Skip to content

Commit

Permalink
Merge pull request #35 from marcoffee/master
Browse files Browse the repository at this point in the history
Added option to select packages to ignore on all
  • Loading branch information
simion authored Aug 27, 2020
2 parents 8b9f490 + d68f788 commit b9caa5c
Showing 1 changed file with 30 additions and 11 deletions.
41 changes: 30 additions & 11 deletions pip_upgrader/packages_interactive_selector.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,10 @@ def ask_for_packages(self):
print(table.table)
print('')

print('Please choose which packages should be upgraded. Choices: "all", "q" (quit), "x" (exit) or "1 2 3"')
print(
'Please choose which packages should be upgraded. '
'Choices: "all -1 -2 -3", "q" (quit), "x" (exit) or "1 2 3"'
)
choice = user_input('Choice: ').strip()

if not choice and not choice.strip():
Expand All @@ -91,18 +94,34 @@ def ask_for_packages(self):
print(Color('{autored}Exit.{/autored}'))
raise KeyboardInterrupt()

if choice == "all":
self._select_packages(self.packages_for_upgrade.keys())
else:
try:
selected = list(self._select_packages([int(index.strip()) for index in choice.split(' ')]))
if not any(selected):
print(Color('{autored}No valid choice selected.{/autored}'))
raise KeyboardInterrupt()
except ValueError: # pragma: nocover
print(Color('{autored}Invalid choice{/autored}'))
try:
include = []

if choice.startswith("all"):
# make iterator on stripped choices
exclude_it = map(str.strip, choice[ 3 : ].split(" "))
# filter out empty strings and create set of excluded indices
exclude = frozenset(map(int, filter(len, exclude_it)))

# include packages on keys not in excluded set
include = [
i for i in self.packages_for_upgrade.keys()
if -i not in exclude
]

else:
include = [int(index.strip()) for index in choice.split(' ')]

selected = list(self._select_packages(include))

if not any(selected):
print(Color('{autored}No valid choice selected.{/autored}'))
raise KeyboardInterrupt()

except ValueError: # pragma: nocover
print(Color('{autored}Invalid choice{/autored}'))
raise KeyboardInterrupt()

def _select_packages(self, indexes):
selected = []

Expand Down

0 comments on commit b9caa5c

Please sign in to comment.