poetry2nix
poetry2nix copied to clipboard
Installing the current project
I'm working on a package that uses Poetry. The source code is in src/ so that it isn't importable without installation. This is a common project layout (for example, attrs and flask have it). With mkPoetryEnv I get access to the dependencies but the project I'm actually working on is not installed so I can't import it.
The normal solution is to do an editable install, but pip/setuptools doesn't have support for this yet with Poetry projects. Poetry itself does its own internal implementation to make it work.
An alternative solution would be to actually install the whole package. This has the advantage that there's no possibility of incomplete installs or other weirdness, and doesn't need any special support from setuptools. The downside is that installing a package after every edit could be slow. It would be cool if there were some incremental-installation magic that could make the process fast.
A hacky solution that I can use currently is just setting PYTHONPATH=src while I'm working on my project.
I'm fine with manually setting PYTHONPATH for now, but I did want to bring this up here in case there's something poetry2nix could do to help make this easy.
Is there a good way for us to figure out what source directory to add to PYTHONPATH automatically?
If there is we could potentially do that in a shell-hook.
The directory is either projectDir or projectDir + "/src", preferring the latter if it exists.
It'll be more robust if poetry2nix can avoid using PYTHONPATH and instead use buildPythonEnv directly. That might require some thought to figure out exactly the right way to do it. In the meantime, setting PYTHONPATH will work fine in most cases though.
I've also started adding an export to .envrc to put the current project in the PYTHONPATH. I believe this same situation applies with any local module installed via poetry2nix, which in poetry defaults to develop/editable mode.
@jtrakk or @mjlbach Do you have an example project for me that has this layout?
- https://github.com/python-attrs/attrs
- https://github.com/pallets/flask
- https://github.com/pyca/cryptography
https://hynek.me/articles/testing-packaging/
@jtrakk I should have clarified: With this structure and using Poetry.