Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Editable installs now respect the value of wheel.install-dir #867

Merged
merged 11 commits into from
Aug 20, 2024
2 changes: 2 additions & 0 deletions src/scikit_build_core/build/_editable.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def editable_redirect(
verbose: bool,
build_options: Sequence[str],
install_options: Sequence[str],
install_dir: str,
) -> str:
"""
Prepare the contents of the _editable_redirect.py file.
Expand All @@ -46,6 +47,7 @@ def editable_redirect(
verbose,
build_options,
install_options,
install_dir,
)
arguments_str = ", ".join(repr(x) for x in arguments)
editable_txt += f"\n\ninstall({arguments_str})\n"
Expand Down
1 change: 1 addition & 0 deletions src/scikit_build_core/build/wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ def _make_editable(
verbose=settings.editable.verbose,
build_options=build_options,
install_options=install_options,
install_dir=settings.wheel.install_dir,
)

wheel.writestr(
Expand Down
22 changes: 20 additions & 2 deletions src/scikit_build_core/resources/_editable_redirect.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ def __init__(
verbose: bool,
build_options: list[str],
install_options: list[str],
dir: str = DIR,
dir: str,
install_dir: str,
) -> None:
self.known_source_files = known_source_files
self.known_wheel_files = known_wheel_files
Expand All @@ -42,6 +43,11 @@ def __init__(
self.build_options = build_options
self.install_options = install_options
self.dir = dir
self.install_dir = (
install_dir
if os.path.isabs(install_dir)
henryiii marked this conversation as resolved.
Show resolved Hide resolved
else os.path.join(DIR, install_dir)
)
# Construct the __path__ of all resource files
# I.e. the paths of all package-like objects
submodule_search_locations: dict[str, set[str]] = {}
Expand Down Expand Up @@ -136,7 +142,14 @@ def rebuild(self) -> None:
result.check_returncode()

result = subprocess.run(
["cmake", "--install", ".", "--prefix", DIR, *self.install_options],
[
"cmake",
"--install",
".",
"--prefix",
self.install_dir,
*self.install_options,
],
cwd=self.path,
stdout=sys.stderr if verbose else subprocess.PIPE,
env=env,
Expand All @@ -159,6 +172,7 @@ def install(
verbose: bool = False,
build_options: list[str] | None = None,
install_options: list[str] | None = None,
install_dir: str = "",
) -> None:
"""
Install a meta path finder that redirects imports to the source files, and
Expand All @@ -169,6 +183,8 @@ def install(
:param path: The path to the build directory, or None
:param verbose: Whether to print the cmake commands (also controlled by the
SKBUILD_EDITABLE_VERBOSE environment variable)
:param install_dir: The wheel install directory override, if one was
specified
"""
sys.meta_path.insert(
0,
Expand All @@ -180,5 +196,7 @@ def install(
verbose,
build_options or [],
install_options or [],
DIR,
install_dir,
),
)
1 change: 1 addition & 0 deletions tests/test_editable_redirect.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def test_editable_redirect():
build_options=[],
install_options=[],
dir=str(Path("/sitepackages")),
install_dir="",
)

assert finder.submodule_search_locations == process_dict_set(
Expand Down
1 change: 1 addition & 0 deletions tests/test_editable_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ def test_navigate_editable_pkg(editable_package: EditablePackage, virtualenv: VE
verbose=False,
build_options=[],
install_options=[],
install_dir="",
)

site_packages.joinpath("_pkg_editable.py").write_text(editable_txt)
Expand Down
Loading