Skip to content

Commit

Permalink
Merge pull request #210 from FoamyGuy/upgrade_flag
Browse files Browse the repository at this point in the history
Upgrade flag
  • Loading branch information
tannewt committed Apr 23, 2024
2 parents 656f1fb + 9887ee9 commit 582c55e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
19 changes: 16 additions & 3 deletions circup/backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def install_module_mpy(self, bundle, metadata):

# 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
Expand All @@ -107,14 +107,27 @@ def install_module(
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)
Expand Down
14 changes: 12 additions & 2 deletions circup/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,14 +286,19 @@ 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,
help="Specify the name of a file on the board to read for auto install."
" 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
Expand Down Expand Up @@ -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,
)


Expand Down

0 comments on commit 582c55e

Please sign in to comment.