Skip to content

Commit

Permalink
feat(cli): utilize stub source locators during add.
Browse files Browse the repository at this point in the history
Signed-off-by: Braden Mars <bradenmars@bradenmars.me>
  • Loading branch information
BradenM committed Dec 12, 2022
1 parent 5c19624 commit d24b409
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions micropy/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from __future__ import annotations

import sys
from contextlib import suppress
from pathlib import Path
from typing import TYPE_CHECKING

Expand All @@ -14,6 +13,7 @@
from micropy import main, utils
from micropy.logger import Log
from micropy.project import Project, modules
from micropy.stubs import source as stubs_source
from questionary import Choice

if TYPE_CHECKING:
Expand Down Expand Up @@ -212,11 +212,13 @@ def add(mpy: main.MicroPy, stub_name, force=False):
Checkout the docs on Github for more info.
"""
mpy.stubs.verbose_log(True)
proj = mpy.project
mpy.log.title(f"Adding $[{stub_name}] to stubs")
with suppress(exc.StubNotFound):
stub_name = mpy.repo.resolve_package(stub_name)
locator = stubs_source.StubSource(
[stubs_source.RepoStubLocator(mpy.repo), stubs_source.StubInfoSpecLocator()]
)
with locator.ready(stub_name) as stub:
stub_name = stub
try:
stub = mpy.stubs.add(stub_name, force=force)
except exc.StubNotFound:
Expand All @@ -226,6 +228,7 @@ def add(mpy: main.MicroPy, stub_name, force=False):
mpy.log.error(f"$[{stub_name}] is not a valid stub!")
sys.exit(1)
else:
mpy.log.success(f"{stub.name} added!")
if proj.exists:
mpy.log.title(f"Adding $[{stub.name}] to $[{proj.name}]")
proj.add_stub(stub)
Expand Down

0 comments on commit d24b409

Please sign in to comment.