Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade flag #210

Merged
merged 3 commits into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions circup/backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,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 @@ -108,14 +108,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 @@ -284,14 +284,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 @@ -343,7 +348,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
Loading