Skip to content

Commit

Permalink
Add argument type validation and conversion
Browse files Browse the repository at this point in the history
Fixes #1641
  • Loading branch information
deathaxe committed Jul 6, 2023
1 parent 177f17c commit 7c552b8
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion package_control/package_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,14 @@ def install_packages(self, packages, unattended=False, progress=None):
An ``ActivityIndicator`` object to use for status information.
"""

if packages is not None:
if isinstance(packages, str):
packages = {packages}
elif not isinstance(packages, set):
if not isinstance(packages, (list, tuple)):
raise TypeError("Argument 'packages' must be a string, list or set!")
packages = set(packages)

tasks = self.create_package_tasks(
actions=(self.INSTALL, self.OVERWRITE),
include_packages=packages
Expand Down Expand Up @@ -183,10 +191,27 @@ def upgrade_packages(self, packages=None, ignore_packages=None, unattended=False
``False``, if Package Control has been updated.
"""

if packages is not None:
if isinstance(packages, str):
packages = {packages}
elif not isinstance(packages, set):
if not isinstance(packages, (list, tuple)):
raise TypeError("Argument 'packages' must be a string, list or set!")
packages = set(packages)

if ignore_packages is None:
ignore_packages = set()
elif isinstance(ignore_packages, str):
ignore_packages = {ignore_packages}
elif not isinstance(ignore_packages, set):
if not isinstance(ignore_packages, (list, tuple)):
raise TypeError("Argument 'ignore_packages' must be a string, list or set!")
ignore_packages = set(ignore_packages)

tasks = self.create_package_tasks(
actions=(self.PULL, self.UPGRADE),
include_packages=packages,
ignore_packages=(ignore_packages or set()) | self.ignored_packages() # don't upgrade disabled packages
ignore_packages=ignore_packages | self.ignored_packages() # don't upgrade disabled packages
)
if tasks is False:
message = 'There are no packages available for upgrade'
Expand Down

0 comments on commit 7c552b8

Please sign in to comment.