Single-sourcing the package version in setup.cfg for Python projects is a good practice to ensure consistency and avoid duplication of version information across different files. One common approach is to define the package version in a separate module or file and then import that version into setup.cfg.
Here's how you can achieve single-sourcing of the package version:
version.py) in the root of your project. In this file, define a variable to hold the package version. For example:# version.py __version__ = '1.0.0'
setup.cfg file, use the importlib_metadata option to import the version from the version.py file:# setup.cfg [metadata] name = your_package_name version = attr: your_package_name.version.__version__
version.py file is always available when installing or distributing the package, make sure to include it in your package's source distribution. You can use the include_package_data option in setup.cfg:# setup.cfg [options] package_dir = = src packages = find: [options.package_data] your_package_name = version.py
src directory (or any other directory you specified in package_dir above) to keep the package structure clean and organized.By following these steps, you have successfully single-sourced the package version in your setup.cfg file. Now, the version is maintained in a single location (version.py) and automatically imported into setup.cfg when building, installing, or distributing your Python package. This approach reduces redundancy and makes it easier to manage the version across your project.
"Single-sourcing package version setup.cfg example"
[metadata] version = attr: package.__version__
"How to use setup.cfg for versioning in Python projects"
[metadata] version = attr: my_package.__version__
"setup.cfg versioning best practices"
[metadata] version = attr: my_module.__version__
"setup.cfg version field for Python projects"
[metadata] version = attr: my_library.__version__
"Python project versioning setup.cfg example"
[metadata] version = attr: project.version
"How to manage package versions in setup.cfg"
[metadata] version = attr: my_project.__version__
"Single-source versioning in setup.cfg Python"
[metadata] version = attr: my_package.version
"setup.cfg versioning vs. setup.py versioning"
[metadata] version = attr: my_package_version.version
"setup.cfg versioning for setuptools"
[metadata] version = attr: my_package.version_info
"setup.cfg versioning tutorial Python"
[metadata] version = attr: my_package.get_version()
code-generation keytool msgpack nest crc stringbuilder data-pipeline ios8 photokit gis