Use Pipenv to build and publish a Python package

Viewed 2388

Context: I'm setting up a new Python project and decided to give PEP-517 and PEP-518 ("build systems") a whirl, instead of my usual setup.py-plus-a-bunch-of-shell-scripts configuration. My requirements are: dependency management and being able to create a Python package and publish it to PyPI. I decided to give Pipenv a chance.

Problem: I cannot find any information about how to create a Python package when using Pipenv to manage the dependencies. It appears that Pipenv doesn't provide means for that. So, does it mean that in addition to the Pipfile I still need to create a setup.py? What is the point of having the Pipfile then? Or is it possible to "snapshot" a Pipenv into a setup.py for example? If so, how do I manage other attributes (package description, author, project URL, etc.) in this case?

To avoid any confusion, my question is not to find a library or a tool, but about how to accompilsh a specific task - build and publish a Python package - in the Python project with dependency management based on Pipenv.

1 Answers

Pipenv doesn't allow you to publish a package as you may hope. It is used for development, and for the publishing step you will still need a setup.py file. There's some good news, you can use pipenv-setup to sync your pipenv packages without any manual editing (pipenv-setup sync --dev).

An alternative to Pipenv that also allows you to publish your project is Poetry: it has a simple poetry publish command that does just that. It is also based on pyproject.toml, which is being pushed as a replacement for setup.py

Related