-
-
Notifications
You must be signed in to change notification settings - Fork 293
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
Add path option for Python source. #335
Conversation
2480206
to
658b25f
Compare
Not sure what the failing CI on Mac is about, it reports that |
I think sdists require an option in pyproject.toml that is read in |
Not sure what you mean with that, Do you mean something different? |
You could include setup.py, but maturin doesn't write or read setup.py. Maybe you have specified a call to maturin there, pip prefers it to pyproject.toml, and are not seeing the normal PEP 517 flow? I am thinking of running |
Thanks for the explanation, I'll look into it some time tomorrow! |
@sebpuetz thanks for this. Might it be worth also adding this option to the toml configuration in Also, I think CI issue now fixed on master if you rebase 👍 |
1bd3483
to
2cb5c3e
Compare
Thanks for the feedback, the directory for the Python source is now configurable through $ pip install . --no-build-isolation installs directly from the directory and $ maturin sdist
$ pip install target/wheels/*.tar.gz --no-build-isolation works, too.
|
Is there something other than the conflicting files that needs to be addressed to merge this PR? |
I think the overall design question is one for @konstin, so I would prefer wait for their feedback on this proposal. Questions in my mind that I'm not sure what the right answer is:
Sorry I have done a bit of a u-turn when thinking about this more :( |
There's good reason to split up the project structure like this. Importing from the project root will always import from the package in the project rather than from $ maturin build -i python
$ pip install target/wheels/pyo3_mixed-2.1.1-cp37-cp37m-manylinux1_x86_64.whl
$ python test_pyo3_mixed.py
Traceback (most recent call last):
File "test_pyo3_mixed.py", line 3, in <module>
import pyo3_mixed
File "/data/rust_projects/maturin/test-crates/pyo3-mixed/pyo3_mixed/__init__.py", line 2, in <module>
from .pyo3_mixed import get_21
ModuleNotFoundError: No module named 'pyo3_mixed.pyo3_mixed' In a setting with pytest and with a $ maturin build -i python
$ pip install target/wheels/pyo3_mixed-2.1.1-cp37-cp37m-manylinux1_x86_64.whl
$ pytest
[...]
Traceback:
/home/seb/.pyenv/versions/3.7.7/lib/python3.7/importlib/__init__.py:127: in import_module
return _bootstrap._gcd_import(name[level:], package, level)
tests/test_tests.py:1: in <module>
import pyo3_mixed
pyo3_mixed/__init__.py:2: in <module>
from .pyo3_mixed import get_21
E ModuleNotFoundError: No module named 'pyo3_mixed.pyo3_mixed' Although, this can be fixed by setting If you want to drop into a interactive session and quickly check something, you need to navigate out of the project root or need an editable install. There's a decent blog-post about why the src project layout is preferable: https://blog.ionelmc.ro/2014/05/25/python-packaging/#the-structure cited by pytest docs which offer some more reasoning why different layouts can be preferable https://docs.pytest.org/en/stable/goodpractices.html. Imo, changing the folder structure let's you avoid quite a number of annoyances. |
First of all thank you for the pull request and sorry I took so long to respond! Also thanks to @ijl and @davidhewitt for reviewing this!
I actually thought of that as feature, as this way you can edit python code and don't need to reinstall with maturin, or get outdated code from site-packages, but I guess that really depends on the workflow and I feel like we should definitely support module-not-in-root layouts such as the src-layout. (I actually thought about using the src/module_name when adding that feature, however I decided against it since it would confusing that the top level python module looks like a submodule of the rust tree)
I would prefer a key called One thing that I might have just missed in the code is how the name mismatch is handled: If you package a module called
A key problem is that there currently is no consensus about package structure in python outside from the layout of a wheel (this is also what makes dependency resolution so hard in python: sdists don't have reliable metadata). There are discussions about standardizing metadata in pyproject.toml and a standard way to specify dependencies, but both seem to have stalled. Another key difference is that unlike I completely agree that a stricter layout is easier to use (and also less error-prone), which is why maturin has rather strong constraints, but in this case I think it's worth supporting an extra mode. I'd also really like to offer proper editable installs which would make this a lot smoother from a user perspective, but unfortunately they are neither properly documented nor standardized. Another option for at least the shared library would be symlinks, however symlinks have issues on windows.
As I wrote above using |
Using |
Could you elaborate? (I don't have experience shipping type annotations, I've only seen that orjson has a orjson.pyi file) |
Type annotations will only be read in module directories so it requires a mixed project. If you just include a pyi alongside the shared object, it will be at |
Forcing the Python package to be in the project root leads to difficulties testing and evaluating the package:
import my_package
will import from the folder in the project instead of the install undersite-packages
.pytest
from the project root suffers the same consequences: tests will import from the folder in the project instead of the installed version.maturin develop
can be tested in the current setup.Not sure whether I missed something or if there are reasons that make this solution sub-optimal, looking forward to some feedback!