Skip to content

Commit

Permalink
fix(stubs): perform repo lookups prior to adding stub
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 11, 2022
1 parent c17be65 commit 5410a13
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
5 changes: 4 additions & 1 deletion micropy/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from __future__ import annotations

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

Expand Down Expand Up @@ -193,7 +194,7 @@ def install(mpy, packages, dev=False, path=None):
@click.argument("stub_name", required=True)
@click.option("-f", "--force", is_flag=True, default=False, help="Overwrite Stub if it exists.")
@pass_mpy
def add(mpy, stub_name, force=False):
def add(mpy: main.MicroPy, stub_name, force=False):
"""Add Stubs from package or path.
\b
Expand All @@ -214,6 +215,8 @@ def add(mpy, stub_name, force=False):
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)
try:
stub = mpy.stubs.add(stub_name, force=force)
except exc.StubNotFound:
Expand Down
6 changes: 1 addition & 5 deletions micropy/stubs/stubs.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from distlib import metadata
from micropy import data, utils
from micropy.exceptions import StubError, StubNotFound, StubValidationError
from micropy.exceptions import StubError, StubValidationError
from micropy.logger import Log
from micropy.stubs import source
from packaging.utils import parse_sdist_filename
Expand Down Expand Up @@ -321,10 +321,6 @@ def add(self, location, dest=None, force=False):
if self._should_recurse(location):
return self.load_from(location, strict=False, copy_to=dest)
self.log.info(f"\nResolving stub...")
try:
location = self.repo.resolve_package(location)
except StubNotFound:
pass
stub_source = source.get_source(location, log=self.log)
return self._load(stub_source, copy_to=dest)

Expand Down

0 comments on commit 5410a13

Please sign in to comment.