Merge pull request #210 from FoamyGuy/upgrade_flag

Upgrade flag
This commit is contained in:
Scott Shawcroft 2024-04-23 09:38:10 -07:00 committed by GitHub
commit 582c55e1a5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 28 additions and 5 deletions

View file

@ -92,7 +92,7 @@ class Backend:
# pylint: disable=too-many-locals,too-many-branches,too-many-arguments,too-many-nested-blocks
def install_module(
self, device_path, device_modules, name, pyext, mod_names
self, device_path, device_modules, name, pyext, mod_names, upgrade=False
): # pragma: no cover
"""
Finds a connected device and installs a given module name if it
@ -107,14 +107,27 @@ class Backend:
source or from a pre-compiled module
:param mod_names: Dictionary of metadata from modules that can be generated
with get_bundle_versions()
:param bool upgrade: Upgrade the specified modules if they're already installed.
"""
if not name:
click.echo("No module name(s) provided.")
elif name in mod_names:
# Grab device modules to check if module already installed
if name in device_modules:
click.echo("'{}' is already installed.".format(name))
return
if not upgrade:
# skip already installed modules if no -upgrade flag
click.echo("'{}' is already installed.".format(name))
return
# uninstall the module before installing
name = name.lower()
_mod_names = {}
for module_item, _metadata in device_modules.items():
_mod_names[module_item.replace(".py", "").lower()] = _metadata
if name in _mod_names:
_metadata = _mod_names[name]
module_path = _metadata["path"]
self.uninstall(device_path, module_path)
library_path = (
os.path.join(device_path, self.LIB_DIR_PATH)

View file

@ -286,6 +286,9 @@ def list_cli(ctx): # pragma: no cover
@click.option(
"--auto", "-a", is_flag=True, help="Install the modules imported in code.py."
)
@click.option(
"--upgrade", "-U", is_flag=True, help="Upgrade modules that are already installed."
)
@click.option(
"--auto-file",
default=None,
@ -293,7 +296,9 @@ def list_cli(ctx): # pragma: no cover
" Also accepts an absolute path or a local ./ path.",
)
@click.pass_context
def install(ctx, modules, pyext, requirement, auto, auto_file): # pragma: no cover
def install(
ctx, modules, pyext, requirement, auto, auto_file, upgrade=False
): # pragma: no cover
"""
Install a named module(s) onto the device. Multiple modules
can be installed at once by providing more than one module name, each
@ -345,7 +350,12 @@ def install(ctx, modules, pyext, requirement, auto, auto_file): # pragma: no co
click.echo(f"Ready to install: {to_install}\n")
for library in to_install:
ctx.obj["backend"].install_module(
ctx.obj["DEVICE_PATH"], device_modules, library, pyext, mod_names
ctx.obj["DEVICE_PATH"],
device_modules,
library,
pyext,
mod_names,
upgrade,
)