I am developing a Python package, and I don't want to have to keep running pip install . to reinstall my package every time I change something. Using the -e or --editable doesn't seem to work unless I have a setup.py file, nor does --no-use-pep517. I have a pyproject.toml instead, as is preferred nowadays if I am not mistaken. So, what is the preferred way to do this nowadays?
My package is just a CLI script, but it imports some functions from another file in the same directory called utils.py. When developing, I can't just run the script manually from the terminal, because then I get "name_of_package is not a package" from the line from name_of_package.utils import function. Whereas if I just have from utils import function, I can run the script from the terminal, but when I pip install it, it says "there is no module named utils".
I did install poetry and installed my dependencies, ran poetry shell and then tried to run my script with poetry run /path/to/script.py, but I kept getting an error that my package wasn't a package.
Nowadays, with setuptools as a build back-end you have the choice of using setup.py, setup.cfg, pyproject.toml, or any combination of these three files to declare the project's metadata and configure the project's packaging. With pyproject.toml being the preferred one as it is standardized (see below). All these are compatible with editable installation (python -m pip install --editable .).
The editable installation mechanism has a standard specification (initiated by the PEP 660 document). And many build back-ends besides setuptools support it. These are the build back-ends I know of that support the standardized editable installation mechanism:
ensconsflit-core (see flit)hatchling (see hatch)maturinmeson-pythonpdm-backend (see pdm)poetry-core (see poetry)setuptoolswheyAll these build back-ends can have their configuration in pyproject.toml (including support for the standardized [build-system] section), and all but Poetry support the standardized [project] section. I have a comparison table here.
References:
setup.py deprecated?setup.py based project?pyproject.tomlIf you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With