Skip to content

Commit

Permalink
Merge pull request #229 from Jessseee/installing_pypi_stubs
Browse files Browse the repository at this point in the history
Adding option to install library stubs from PyPi
  • Loading branch information
FoamyGuy committed Jul 1, 2024
2 parents 5f444f0 + 9610d7d commit cb3de91
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions circup/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
functions is to prepare things for presentation to / interaction with the user.
"""
import os
import subprocess
import time
import sys
import re
Expand Down Expand Up @@ -304,6 +305,12 @@ def list_cli(ctx): # pragma: no cover
@click.option(
"--upgrade", "-U", is_flag=True, help="Upgrade modules that are already installed."
)
@click.option(
"--stubs",
"-s",
is_flag=True,
help="Install stubs module from PyPi for context in IDE.",
)
@click.option(
"--auto-file",
default=None,
Expand All @@ -312,14 +319,15 @@ def list_cli(ctx): # pragma: no cover
)
@click.pass_context
def install(
ctx, modules, pyext, requirement, auto, auto_file, upgrade=False
ctx, modules, pyext, requirement, auto, auto_file, upgrade=False, stubs=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
separated by a space. Modules can be from a Bundle or local filepaths.
"""

# pylint: disable=too-many-branches
# TODO: Ensure there's enough space on the device
available_modules = get_bundle_versions(get_bundles_list())
mod_names = {}
Expand Down Expand Up @@ -373,6 +381,24 @@ def install(
upgrade,
)

if stubs:
library_stubs = "adafruit-circuitpython-{}".format(
library.replace("adafruit_", "")
)
try:
output = subprocess.check_output(["pip", "install", library_stubs])
if (
f"Requirement already satisfied: {library_stubs}"
in output.decode()
):
click.echo(f"'{library}' stubs already installed.")
else:
click.echo(f"Installed '{library}' stubs.")
except subprocess.CalledProcessError:
click.secho(
f"Could not install stubs module {library_stubs}", fg="yellow"
)


@main.command()
@click.option("--overwrite", is_flag=True, help="Overwrite the file if it exists.")
Expand Down Expand Up @@ -697,7 +723,7 @@ def bundle_remove(bundle, reset):
bundles_local_dict = get_bundles_local_dict()
modified = False
for bun in bundle:
# cleanup in case seombody pastes the URL to the repo/releases
# cleanup in case somebody pastes the URL to the repo/releases
bun = re.sub(r"https?://github.com/([^/]+/[^/]+)(/.*)?", r"\1", bun)
found = False
for name, repo in list(bundles_local_dict.items()):
Expand Down

0 comments on commit cb3de91

Please sign in to comment.