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

Python DevShells (for pip) #951

Merged
merged 27 commits into from
May 16, 2024
Merged

Python DevShells (for pip) #951

merged 27 commits into from
May 16, 2024

Conversation

phaer
Copy link
Member

@phaer phaer commented May 1, 2024

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.

  • users need to declare an the root package and/or dependencies of a given python project as editable. Consider a devshell for a package named my-tool:
{
  pip.editables.charset-normalizer = "/home/my-user/src/charset-normalizer";
  pip.editables.click = null;
  pip.editables.my-tool = null;
}

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.

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 see
examples/packages/languages/python-local-development/default.nix and the devShell there.

@phaer phaer requested a review from DavHau May 1, 2024 23:28
@phaer
Copy link
Member Author

phaer commented May 2, 2024

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.

@DavHau DavHau force-pushed the devshells branch 2 times, most recently from 7396d52 to def4db2 Compare May 15, 2024 17:48
modules/dream2nix/pip/editable.nix Show resolved Hide resolved
modules/dream2nix/pip/editable.py Outdated Show resolved Hide resolved
)
run(["ln", "-sf", source, editable_dir])
exit(1)
# link_editable_source(editable_dir, site_dir, normalized_name, full_path)
Copy link
Member Author

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?

modules/dream2nix/pip/editable.py Outdated Show resolved Hide resolved
DavHau added 3 commits May 16, 2024 17:22
- 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
@DavHau DavHau merged commit 6a169a7 into nix-community:main May 16, 2024
71 checks passed
@phaer phaer deleted the devshells branch May 17, 2024 04:07
@purepani purepani mentioned this pull request May 27, 2024
phaer added a commit to phaer/dream2nix that referenced this pull request Jun 11, 2024
* 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>
chaoflow pushed a commit to chaoflow/dream2nix that referenced this pull request Nov 16, 2024
* 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants