Need to know what's the difference between setup.py and setup.cfg. Both are used prominently in openstack projects
setup. cfg is a file which might be used to specify such options in addition to reading the command line when calling python setup.py <somecommand> . The documentation for setup.
The setup.py file may be the most significant file that should be placed at the root of the Python project directory. It primarily serves two purposes: It includes choices and metadata about the program, such as the package name, version, author, license, minimal dependencies, entry points, data files, and so on.
cfg , for users to edit is a cheap and easy way to solicit it. Configuration files also let you provide default values for any command option, which the installer can then override either on the command-line or by editing the config file.
py:34: SetuptoolsDeprecationWarning: setup.py install is deprecated. Use build and pip and other standards-based tools. I found a very detailed write-up explaining this issue: "Why you shouldn't invoke setup.py directly" (October 2021).
Traditionally, setup.py
has been used to build a Python package, i.e.,
python setup.py build
Like any old Python file, setup.py
can contain lots of code. In most cases, however, it is purely declarative and simply lists package properties, e.g.,
from setuptools import setup setup( name="foobar", version="0.1.0", author="John Doe", # ... )
In fact, some consider it bad style to put much logic in setup.py
. To reflect that, setup.cfg
(which is declarative by design) has become more popular for packaging:
[metadata] name = foobar version = 0.1.0 author = John Doe # ...
This has the advantage that the packaging software (e.g., setuptools) doesn't need to evaluate a Python file to get the meta data, but can simply parse a config file.
You can add a dummy setup.py
to that,
from setuptools import setup if __name__ == "__main__": setup()
or go full PEP 517/518 and instead add a pyproject.toml
.
[build-system] requires = ["setuptools>=42", "wheel"] build-backend = "setuptools.build_meta"
You can then build your projects using pypa-build (pip install build
) with
python3 -m build --sdist --wheel .
That being said, the landscape of Python packaging software is very much in motion at the moment (2019/20/21) and it is not clear which will be the preferred method of defining a Python package in the future. For example, there is PEP 621 which suggests to put package metadata into pyproject.toml
.
If 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