-
-
Notifications
You must be signed in to change notification settings - Fork 126
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
Python DevShells (for pip) #951
Conversation
Regarding pdm support: @DavHau mentioned that he might want to re-do the groups feature of the pdm module. For the editables we need a) a python environment and b) an attrset with one drv per package. Another area which might need a bit more work, is garbage collection in .dream2nix. We probably don't want to drop .dream2nix/editables for each shell as it might contain actual worktrees. So we need to diff the declared editables and the existing ones. |
7396d52
to
def4db2
Compare
) | ||
run(["ln", "-sf", source, editable_dir]) | ||
exit(1) | ||
# link_editable_source(editable_dir, site_dir, normalized_name, full_path) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe this can be removed? Looks like a left-over as well?
because there's only 1 attr left now
from the environment.
and teach the devshell how to load it
- change editables interface to use bool or path - expose public.shellHook for composition - use shellHook by default in public.devShell - extend example to include a script
- remove dependency on root package build - always set root package as editable by default - compute dit-info dir by calling a packages build backend or extracting directly from the wheel - only pass required sources to editables shell hook - add build inputs of all editables to teh dev shell - move editables state to .dream2nix/python to remove likelyhood of collision with other ecosystems state - delete editables state if editables configuration changed
- never copy dependency sources - force user to specify a local path
* fetchPipMetadata: set meta.mainProgram * fetchPipMetadata: deduplicate test fixtures * fetchPipMetadata: add is_direct to lock file * devShell: proof of concept * python-local-development: add editables example * devshell: simplify editables interface * buildPythonPackage: remove editable option again * devshell: use findRoot for editables * devshell: add support for .whl sources * devshell: avoid polluting the shells environment * devshell: make editable.nix flatter because there's only 1 attr left now * devshell: fix pyEnv by filtering editables from the environment. * devshell: skip existing editables * devshell: remove patched pyEnv, rewrite sys.path * devshell: add special case for root package * python-local-development: improve editable example * python-local-development: filter source * devshell: reset site_dir on each load * pip: don't ignoreCollisions in pyEnv * pip: default to no sitecustomize.py... and teach the devshell how to load it * pip: rewrite editable in python * editable: use shutil.copytree * editable: refactor into functions * editables: add suport for console_scripts * improve pip editables interface - change editables interface to use bool or path - expose public.shellHook for composition - use shellHook by default in public.devShell - extend example to include a script * improve edtiable support: - remove dependency on root package build - always set root package as editable by default - compute dit-info dir by calling a packages build backend or extracting directly from the wheel - only pass required sources to editables shell hook - add build inputs of all editables to teh dev shell - move editables state to .dream2nix/python to remove likelyhood of collision with other ecosystems state - delete editables state if editables configuration changed * refine python editable support: - never copy dependency sources - force user to specify a local path --------- Co-authored-by: DavHau <hsngrmpf+github@gmail.com>
* fetchPipMetadata: set meta.mainProgram * fetchPipMetadata: deduplicate test fixtures * fetchPipMetadata: add is_direct to lock file * devShell: proof of concept * python-local-development: add editables example * devshell: simplify editables interface * buildPythonPackage: remove editable option again * devshell: use findRoot for editables * devshell: add support for .whl sources * devshell: avoid polluting the shells environment * devshell: make editable.nix flatter because there's only 1 attr left now * devshell: fix pyEnv by filtering editables from the environment. * devshell: skip existing editables * devshell: remove patched pyEnv, rewrite sys.path * devshell: add special case for root package * python-local-development: improve editable example * python-local-development: filter source * devshell: reset site_dir on each load * pip: don't ignoreCollisions in pyEnv * pip: default to no sitecustomize.py... and teach the devshell how to load it * pip: rewrite editable in python * editable: use shutil.copytree * editable: refactor into functions * editables: add suport for console_scripts * improve pip editables interface - change editables interface to use bool or path - expose public.shellHook for composition - use shellHook by default in public.devShell - extend example to include a script * improve edtiable support: - remove dependency on root package build - always set root package as editable by default - compute dit-info dir by calling a packages build backend or extracting directly from the wheel - only pass required sources to editables shell hook - add build inputs of all editables to teh dev shell - move editables state to .dream2nix/python to remove likelyhood of collision with other ecosystems state - delete editables state if editables configuration changed * refine python editable support: - never copy dependency sources - force user to specify a local path --------- Co-authored-by: DavHau <hsngrmpf+github@gmail.com>
Hello,
This is a PR which implements devshells with support for console scripts and richer metadata then the approach in #912. Its currently only implemented for the pip builder, but the idea should be portable to PDM as well. Planning to look into this soon.
my-tool
:The first expression would link the editable
charset-normalizer
from the given absolute path, to.dream2nix/editables/charset-normalizer
and install it.The second line would default to copying
click
from the nix store to.dream2nix/editables/click
and install it.As the first one matches the root package, we would default to link our project root to
.dream2nix/editables/my-tool
and install it.We also implicitly adds dependencies which are "direct installs" in pips report to editables, e.g. "click @ git+https://github.com/pallets/click.git@main" for convenience.
"Installing" here only affects the devshell, we don't touch the results of
nix build
, but instead run a python script (editable.py
) in a shellHook to get the right PATH and PYTHONPATH for the shell setup and install wrapper scripts for console_scripts of our dependencies.We do change public.pyEnv by moving its upstream sitecustomize.py to _sitecustomize.py. It was recently re-introduced into nixpkgs as its removal caused a few pkgs to break, but it did work for the overwhelming majority without issues. Moving it, deactivates it by default but it can easily be re-included if needed. We do so in the devshell just in case in https://github.com/nix-community/dream2nix/compare/main...phaer:dream2nix:devshells?expand=1#diff-4f29741e77180e7c500ebe90ecaa8af18d8aede267e142bf2f83888073079c9eR213
This PR includes commits from fetchPipMetadata: make mitmproxy optional #932. I can drop them if unwanted.
The history includes my first attempt as a shell script. Should I squash this?
Give it a try
Just add some
pip.editables
as above to your package and include${your-pkg.config.pip.editablesShellHook}
in your shellHook or seeexamples/packages/languages/python-local-development/default.nix and the devShell there.