From c16e377dee4c0abfa8dd40281278c1c2ccc0abec Mon Sep 17 00:00:00 2001 From: foamyguy Date: Fri, 12 Apr 2024 17:54:27 -0500 Subject: [PATCH 1/3] upgrade flag for install --- circup/backends.py | 19 ++++++++++++++++--- circup/commands.py | 7 +++++-- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/circup/backends.py b/circup/backends.py index 4e2d1b7..4b2a873 100644 --- a/circup/backends.py +++ b/circup/backends.py @@ -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 @@ -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) diff --git a/circup/commands.py b/circup/commands.py index 74117d9..428e51a 100644 --- a/circup/commands.py +++ b/circup/commands.py @@ -284,6 +284,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, @@ -291,7 +294,7 @@ 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 @@ -343,7 +346,7 @@ 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 ) From 2ee6f3171ee1b50c554e01ed0bce66e273f2ab56 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Fri, 12 Apr 2024 17:55:01 -0500 Subject: [PATCH 2/3] format --- circup/commands.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/circup/commands.py b/circup/commands.py index 428e51a..8c9a457 100644 --- a/circup/commands.py +++ b/circup/commands.py @@ -294,7 +294,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, upgrade=False): # 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 @@ -346,7 +348,12 @@ def install(ctx, modules, pyext, requirement, auto, auto_file, upgrade=False): 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, upgrade + ctx.obj["DEVICE_PATH"], + device_modules, + library, + pyext, + mod_names, + upgrade, ) From 9887ee97f78801ac51862770680dab58dc7cc0ef Mon Sep 17 00:00:00 2001 From: foamyguy Date: Mon, 22 Apr 2024 17:54:53 -0500 Subject: [PATCH 3/3] capital -U flag for upgrade --- circup/commands.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/circup/commands.py b/circup/commands.py index 8c9a457..10a86d5 100644 --- a/circup/commands.py +++ b/circup/commands.py @@ -285,7 +285,7 @@ def list_cli(ctx): # pragma: no cover "--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." + "--upgrade", "-U", is_flag=True, help="Upgrade modules that are already installed." ) @click.option( "--auto-file",