-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build: Rework editables for full PEP-660 support
The previously used mechanism of synthezising a package using hatchling sort of works, and was enough to prove the concept of editables with Nix. This changes `mkDerivationEditable` to use PEP-660 and should support pretty much everything. The big complication in this development was the need for source level patching since editables are a pretty loose concept and are implemented differently by different build systems. Source patching uses https://github.com/Instagram/LibCST/. I'd like to rewrite this bit purely in Rust later. So far I've successfully used this support with a few build systems, most notably meson. For meson this requires manually calling `patch_editable.py` to create the initial files. After that point dynamic recompilation "just works". This will be exposed as a separate package somehow, just not yet.
- Loading branch information
1 parent
b8651de
commit 3db43c7
Showing
21 changed files
with
553 additions
and
125 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
{ | ||
runCommand, | ||
lib, | ||
python, | ||
mkVirtualEnv, | ||
}: | ||
|
||
let | ||
env = | ||
mkVirtualEnv "editable-hook-env" { | ||
libcst = [ ]; | ||
pyproject-hooks = [ ]; | ||
} | ||
// lib.optionalAttrs (python.pythonOlder "3.11") { | ||
tomli = [ ]; | ||
}; | ||
|
||
in | ||
runCommand "editable-hook" { } '' | ||
mkdir -p $out/bin | ||
cat > $out/bin/build-editable << EOF | ||
#!${env}/bin/python | ||
EOF | ||
cat ${./editable_hook/build_editable.py} >> $out/bin/build-editable | ||
cat > $out/bin/patch-editable << EOF | ||
#!${env}/bin/python | ||
EOF | ||
cat ${./editable_hook/patch_editable.py} >> $out/bin/patch-editable | ||
chmod +x $out/bin/* | ||
'' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import os | ||
import sys | ||
from pathlib import Path | ||
from typing import Any | ||
|
||
if sys.version_info >= (3, 11): | ||
import tomllib | ||
else: | ||
import tomli as tomllib # pyright: ignore[reportMissingImports] | ||
import pyproject_hooks | ||
|
||
|
||
def main(): | ||
build_dir = Path(os.getcwd()) | ||
dist = build_dir.joinpath("dist") | ||
|
||
with open(build_dir.joinpath("pyproject.toml"), "rb") as pyproject_file: | ||
pyproject: dict[str, Any] = tomllib.load(pyproject_file) # pyright: ignore[reportUnknownMemberType,reportExplicitAny] | ||
|
||
# Get build backend with fallback behaviour | ||
# https://pip.pypa.io/en/stable/reference/build-system/pyproject-toml/#fallback-behaviour | ||
try: | ||
build_backend: str = pyproject["build-system"]["build-backend"] | ||
except KeyError: | ||
build_backend = "setuptools.build_meta:__legacy__" | ||
|
||
try: | ||
dist.mkdir() | ||
except FileExistsError: | ||
pass | ||
|
||
# Call editable build hooks using pyproject-hooks | ||
hook_caller = pyproject_hooks.BuildBackendHookCaller( | ||
source_dir=str(build_dir), | ||
build_backend=build_backend, | ||
) | ||
hook_caller.build_editable(str(dist)) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
Oops, something went wrong.