pypa / packaging-problems

An issue tracker for the problems in packaging
151 stars 35 forks source link

Getting all pyproject.toml values #659

Open achapkowski opened 1 year ago

achapkowski commented 1 year ago

Problem description

Is there a command via setup.py or something within pip that will produce a pyproject.toml template?

abravalheri commented 1 year ago

I am afraid neither setuptools or pip ships something built-in that you can use directly.

However there are a few alternatives if you want to convert setup.cfg or setup.py into pyproject.toml:

If you have a setup.cfg in place you can use ini2toml to convert it to pyproject.toml.

If you are not using setup.cfg, but you have setup.py in place you can try first using something like setup-py-upgrade and then using ini2toml.

If you are starting from scratch, you may use a project generator to get the basic project structure up (e.g. https://github.com/pyscaffold/pyscaffold or https://github.com/ionelmc/cookiecutter-pylibrary) and then use the techniques discussed above if necessary.

If you have pipx you can run all these commands quite easily:

pipx run setup-py-upgrade --help
pipx run 'ini2toml[full]' --help
henryiii commented 1 year ago

Hatch can also convert a setup.py to pyproject.toml, with pipx run hatch new --init. If you are starting from scratch, there's also pipx run cookiecutter gh:scikit-hep/cookie, based on https://scikit-hep.org/developer, which has best practices for lots of different aspects of packaging.

achapkowski commented 1 year ago

I'll give that a try with hatch.

This is a legacy project that honestly packaging was the last thing I wanted to redo.

When you force devs to migrate, tools should be in place to assist then or at least comprehensive documentation. Pyproject.toml files feels like a fractured mess compared to setup.py way.

abravalheri commented 1 year ago

When you force devs to migrate, tools should be in place to assist then or at least comprehensive documentation. Pyproject.toml files feels like a fractured mess compared to setup.py way.

Hi @achapkowski, please note that having a setup.py as a configuration file is not deprecated and you don't need to migrate away from it.

What is deprecated is calling python setup.py ... as a CLI script. In this sense, the only migration you are required to do is to run python -m build instead of python setup.py sdist or python setup.py bdist_wheel.

(If your setup.py is heavily customised and rely on the fact that it runs as a CLI script, maybe there will be some compatibility issues that would require further changes, but it is worth trying python -m build as the project is right now before dedicating energy to change things).

The article https://blog.ganssle.io/articles/2021/10/setup-py-deprecated.html has a table with other command replacements for python setup.py ... commands.