Skip to content

Commit

Permalink
fix(editable): find wheel files before local files (#305)
Browse files Browse the repository at this point in the history
Fix mixing .pyi files with complied output by prioritizing wheel files
over local files. Fix #304.

Signed-off-by: Henry Schreiner <[email protected]>
  • Loading branch information
henryiii authored Apr 27, 2023
1 parent 98ec432 commit aaebd58
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/scikit_build_core/resources/_editable_redirect.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,16 @@ def find_spec(
path: object = None,
target: object = None,
) -> importlib.machinery.ModuleSpec | None:
if fullname in self.known_source_files:
redir = self.known_source_files[fullname]
return importlib.util.spec_from_file_location(fullname, redir)
if fullname in self.known_wheel_files:
redir = self.known_wheel_files[fullname]
if self.rebuild_flag:
self.rebuild()
return importlib.util.spec_from_file_location(
fullname, os.path.join(DIR, redir)
)
if fullname in self.known_source_files:
redir = self.known_source_files[fullname]
return importlib.util.spec_from_file_location(fullname, redir)

return None

Expand Down
1 change: 1 addition & 0 deletions tests/packages/simplest_c/src/simplest/_module.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
def square(__x: float, __y: float) -> float: ...
5 changes: 3 additions & 2 deletions tests/test_simplest_c.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def test_pep517_sdist(tmp_path, monkeypatch):
".gitignore",
"src/module.c",
"src/simplest/__init__.py",
"src/simplest/_module.pyi",
"src/simplest/data.txt",
"src/simplest/sdist_only.txt",
"src/not_a_package/simple.txt",
Expand Down Expand Up @@ -65,7 +66,7 @@ def test_pep517_wheel(tmp_path, monkeypatch, virtualenv):

filtered_pkg = {x for x in simplest_pkg if not x.startswith("_module")}

assert len(filtered_pkg) == len(simplest_pkg) - 1
assert len(filtered_pkg) == len(simplest_pkg) - 2
assert {"simplest-0.0.1.dist-info", "simplest"} == file_names
assert {
"__init__.py",
Expand Down Expand Up @@ -114,7 +115,7 @@ def test_pep517_wheel_incexl(tmp_path, monkeypatch, virtualenv):

filtered_pkg = {x for x in simplest_pkg if not x.startswith("_module")}

assert len(filtered_pkg) == len(simplest_pkg) - 1
assert len(filtered_pkg) == len(simplest_pkg) - 2
assert {"simplest-0.0.1.dist-info", "simplest", "not_a_package"} == file_names
assert {
"__init__.py",
Expand Down

0 comments on commit aaebd58

Please sign in to comment.