Skip to content

Commit

Permalink
Merge pull request #67 from askpatrickw/fix-65
Browse files Browse the repository at this point in the history
Fix 65 - Multi module install
  • Loading branch information
makermelissa committed Jan 21, 2021
2 parents eb120d1 + 06d8a95 commit 32d3a31
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 25 deletions.
14 changes: 11 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ To get help, just type the command::

Commands:
freeze Output details of all the modules found on the connected...
install Install a named module onto the device.
install Install a named module(s) onto the device.
list Lists all out of date modules found on the connected...
show Show the long list of all available modules in the bundle.
show <query> Search the names in the modules in the bundle for a match.
Expand Down Expand Up @@ -126,11 +126,15 @@ To interactively update the out-of-date modules::
Update 'adafruit_ble'? [y/N]: Y
OK

Install a module onto the connected device with::
Install a module or modules onto the connected device with::

$ circup install adafruit_thermal_printer
Installed 'adafruit_thermal_printer'.

$ circup install adafruit_thermal_printer adafruit_bus_io
Installed 'adafruit_thermal_printer'.
Installed 'adafruit_bus_io'.

You can also install a list of modules from a requirements.txt file in
the current working directory with::

Expand All @@ -141,11 +145,15 @@ the current working directory with::
Installed 'adafruit_sht31d'.
Installed 'neopixel'.

Uninstall a module like this::
Uninstall a module or modules like this::

$ circup uninstall adafruit_thermal_printer
Uninstalled 'adafruit_thermal_printer'.

$ circup uninstall adafruit_thermal_printer adafruit_bus_io
Uninstalled 'adafruit_thermal_printer'.
Uninstalled 'adafruit_bus_io'.

Use the ``--verbose`` flag to see the logs as the command is working::

$ circup --verbose freeze
Expand Down
47 changes: 25 additions & 22 deletions circup.py
Original file line number Diff line number Diff line change
Expand Up @@ -789,7 +789,7 @@ def install_module(device_path, name, py, mod_names): # pragma: no cover
TODO: There is currently no check for the version.
"""
if not name:
click.echo("No module name provided.")
click.echo("No module name(s) provided.")
elif name in mod_names:
library_path = os.path.join(device_path, "lib")
if not os.path.exists(library_path): # pragma: no cover
Expand Down Expand Up @@ -848,38 +848,41 @@ def install_module(device_path, name, py, mod_names): # pragma: no cover


@main.command()
@click.argument("name", required=False)
@click.argument("modules", required=False, nargs=-1)
@click.option("--py", is_flag=True)
@click.option("-r", "--requirement")
@click.pass_context
def install(ctx, name, py, requirement): # pragma: no cover
def install(ctx, modules, py, requirement): # pragma: no cover
"""
Install a named module onto the device. This is a very naive / simple
hacky proof of concept. Option -r allows specifying a text file to
install all modules listed in the text file.
Install a named module(s) onto the device. Multiple modules
can be installed at once by providing more than one module name, each
separated by a space.
Option -r allows specifying a text file to install all modules listed in
the text file.
TODO: Work out how to specify / handle dependencies (if at all), ensure
there's enough space on the device, work out the version of CircuitPython
on the device in order to copy the appropriate .mpy versions too. ;-)
"""
available_modules = get_bundle_versions()
# Normalize user input.
name = name.lower() if name else ""
mod_names = {}
for module, metadata in available_modules.items():
mod_names[module.replace(".py", "").lower()] = metadata
if requirement:
cwd = os.path.abspath(os.getcwd())
with open(cwd + "/" + requirement, "r") as file:
for line in file.readlines():
# Ignore comment lines or appended comment annotations.
line = line.split("#", 1)[0]
line = line.strip() # Remove whitespace (including \n).
if line: # Ignore blank lines.
module = line.split("==")[0] if "==" in line else line
install_module(ctx.obj["DEVICE_PATH"], module, py, mod_names)
else:
install_module(ctx.obj["DEVICE_PATH"], name, py, mod_names)
for name in modules:
name = name.lower() if name else ""
mod_names = {}
for module, metadata in available_modules.items():
mod_names[module.replace(".py", "").lower()] = metadata
if requirement:
cwd = os.path.abspath(os.getcwd())
with open(cwd + "/" + requirement, "r") as file:
for line in file.readlines():
# Ignore comment lines or appended comment annotations.
line = line.split("#", 1)[0]
line = line.strip() # Remove whitespace (including \n).
if line: # Ignore blank lines.
module = line.split("==")[0] if "==" in line else line
install_module(ctx.obj["DEVICE_PATH"], module, py, mod_names)
else:
install_module(ctx.obj["DEVICE_PATH"], name, py, mod_names)


@main.command()
Expand Down

0 comments on commit 32d3a31

Please sign in to comment.