Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 12 additions & 24 deletions src/scikit_build_core/resources/_editable_redirect.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,6 @@
if TYPE_CHECKING:
import importlib.machinery

if sys.version_info < (3, 8):
from typing_extensions import TypedDict
else:
from typing import TypedDict

class KWDict_1(TypedDict, total=False): # noqa: N801
submodule_search_locations: list[str]

else:
KWDict_1 = dict


DIR = os.path.abspath(os.path.dirname(__file__))
MARKER = "SKBUILD_EDITABLE_SKIP"
Expand Down Expand Up @@ -87,29 +76,28 @@ def find_spec(
path: object = None,
target: object = None,
) -> importlib.machinery.ModuleSpec | None:
# If current item is a know package use its search locations, otherwise if it's a module use the parent's
parent = (
fullname if fullname in self.pkgs else ".".join(fullname.split(".")[:-1])
)
# If no known submodule_search_locations is found, it means it is a root module. Do not populate its kwargs
# in that case
kwargs = KWDict_1()
if parent in self.submodule_search_locations:
kwargs["submodule_search_locations"] = list(
self.submodule_search_locations[parent]
)
# If no known submodule_search_locations is found, it means it is a root
# module.
if fullname in self.submodule_search_locations:
submodule_search_locations = list(self.submodule_search_locations[fullname])
else:
submodule_search_locations = None
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),
**kwargs,
submodule_search_locations=submodule_search_locations,
)
if fullname in self.known_source_files:
redir = self.known_source_files[fullname]
return importlib.util.spec_from_file_location(fullname, redir, **kwargs)
return importlib.util.spec_from_file_location(
fullname,
redir,
submodule_search_locations=submodule_search_locations,
)
return None

def rebuild(self) -> None:
Expand Down
6 changes: 1 addition & 5 deletions tests/test_editable_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,7 @@ class EditablePackage(NamedTuple):
@pytest.fixture(
params=[
pytest.param(False, id="abs"),
pytest.param(
True,
marks=pytest.mark.xfail(strict=True, reason="Rel imports broken"),
id="rel",
),
pytest.param(True, id="rel"),
]
)
def editable_package(
Expand Down