Skip to content

Commit

Permalink
only transform .py entry points (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
rmorshea committed Apr 22, 2023
1 parent 6f88266 commit ddda4b7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/tagstr/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

class TagStrPathHook(PathEntryFinder):
def __init__(self, path: str) -> None:
if not os_path.isfile(path):
raise ImportError("Only files are supported")
if not os_path.isfile(path) or os_path.splitext(path)[1] != ".py":
raise ImportError("Only .py files are supported")
self.entry_file = path
self.file_finder = FileFinder(
os_path.dirname(path), (TagStrSourceFileLoader, [".py"])
Expand Down Expand Up @@ -45,6 +45,8 @@ def find_spec(
if fullname == "__main__":
loader = TagStrSourceFileLoader(fullname, self.entry_file)
return ModuleSpec(fullname, loader, is_package=False)
elif path is None:
return None

for finder in sys.meta_path:
if finder is not self:
Expand Down
1 change: 1 addition & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import tagstr.importer # noqa

0 comments on commit ddda4b7

Please sign in to comment.