Skip to content

Commit

Permalink
fix(stubs): always ensure correct pyi stub root paths.
Browse files Browse the repository at this point in the history
Signed-off-by: Braden Mars <bradenmars@bradenmars.me>
  • Loading branch information
BradenM committed May 18, 2023
1 parent be269ee commit 27f87a1
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions micropy/stubs/stubs.py
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,13 @@ def __init__(self, path, copy_to=None, **kwargs):
if copy_to is not None:
self.copy_to(copy_to)

def find_root(self, path: Path) -> Path:
"""Attempt to find appropriate stub root."""
pyi_files = path.rglob("*.pyi")
if pyi_path := next(pyi_files, None):
return pyi_path.parent
return path

def copy_to(self, dest, name=None):
"""Copy stub to a directory."""
if not name:
Expand Down Expand Up @@ -519,9 +526,11 @@ def __init__(self, path, copy_to=None, **kwargs):
super().__init__(path, copy_to, **kwargs)

stubs_path = self.path / "stubs"
self.stubs = stubs_path if stubs_path.exists() else self.path
self.stubs = self.find_root(stubs_path if stubs_path.exists() else self.path)

frozen_path = self.path / "frozen"
self.frozen = frozen_path if frozen_path.exists() else self.path
self.frozen = self.find_root(frozen_path if frozen_path.exists() else self.path)

stubber = self.info.get("stubber")
self.stub_version = stubber.get("version")

Expand Down

0 comments on commit 27f87a1

Please sign in to comment.