nbtlib icon indicating copy to clipboard operation
nbtlib copied to clipboard

Provide a `setup.py`, as Poetry does not (yet) cover all cases

Open MestreLion opened this issue 6 years ago • 4 comments

TL;DR: Poetry does not provide (yet) any way to install a local package (cloned from github) in editable mode (the equivalent of pip install -e .), and pip does not support (yet) editable mode with pyproject.toml. The solution is, for the time being, to provide a setup.py.

Long version:

So here's my use-case: I'm using nbtlib as a dependency in my projects, which themselves might or might not use Poetry. For developing those projects, I can simply run pip3 install --user nbtlib and done, a stable nbtlib is downloaded from PyPI and installed in my ~/.local/lib/python3.x/site-packages and made globally available to any project that might use it. (or install it in each project's virtualenv, same result)

But... I'd also like to contribute to nbtlib. So I clone it's github repo, install Poetry and pytest to run tests before creating PRs. So far so great. Now I want to use this modified version in my projects, so I need to install the local version (not a stable from PyPI). And it must be in editable mode, so any further changes are automatically refletected in my projects.

Poetry? No such feature. It's meant for managing a package's dependencies, not to install or use a package as a dependency. Pip? No luck: it does not support pip install -e . with a pyproject.toml:

01:15:27 rodrigo@desktop ~/work/minecraft/nbtlib master $ pip3 install --user -e .
ERROR: File "setup.py" not found. Directory cannot be installed in editable mode: /home/rodrigo/work/minecraft/nbtlib
(A "pyproject.toml" file was found, but editable mode currently requires a setup.py based build.)

Poetry is still too immature and lacks a lot of features to cover all use cases of setup.py, pip and etc. And pip is not modern enough to use pyproject.toml for all of its features.

If there's no better solution, I believe nbtlib should provide a setup.py, at least until both tools mature.

MestreLion avatar Dec 20 '19 05:12 MestreLion

Poetry just reached 1.0 though, I think it's great but I can see why it might still be lacking in a few areas. I kinda like the solution proposed here. I think using poetry's setup.py generator as explained here would be a good idea.

Edit: I haven't looked into it yet but dephell could be interesting as well.

vberlier avatar Dec 24 '19 19:12 vberlier

Since this is still open, and you've included in the 2.0 discussion, I believe I should give some 2021 feedback:

Poetry has matured a lot since then. The whole packaging landscape did. I'm finally able to perform a poetry install . and it, by default, install the package in editable mode. I still have to set a flag to override your poetry.toml setting so it installs to my ~/.local site-packages, but at least that's doable now (is that file intended to be on the git repo?) pip install -e . works too, and invokes poetry's builder. So I don't have to use poetry on my project to use a local nbtlib.

I didn't revisit yet all of the many issues I had with it to see of any still holds today, nor I checked if they still had those poor non-XDG choices about default dirs, but the fact it has --editable makes me even consider adopting it. And also the fact that whenever I try to use pyproject.toml with setuptools it is nothing but pain. Even setup.cfg feels worse than a setup.py written using good practices.

Besides you've already created a setup.py shim for other purposes, so if a given tool requires one, it's there.

Given all of that, I think you can close this. Poetry now is able to do what I need

MestreLion avatar Nov 03 '21 17:11 MestreLion

You might, however, consider switching to poetry-core for your build system:

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"

The project itself would still be managed by the full-fledged Poetry, but the clients/users would only require the core to build.

MestreLion avatar Nov 03 '21 17:11 MestreLion

I see, thanks for the feedback on this.

You might, however, consider switching to poetry-core for your build system

Oh right looks like I didn't do it yet for nbtlib.

vberlier avatar Nov 04 '21 10:11 vberlier