[Python] Using a dynamic version when building a Python package with Setuptools (setup.py)

Discussão em 'Python' iniciado por Stack, Setembro 9, 2025.

  1. Stack

    Stack Membro Participativo

    We have a big legacy project that contains some python code inside, the version of all components in the project is set during runtime by the build system which builds the project. We now need to package the python code with the same version used by the other components.
    The package is currently archived using the following command python setup.py bdist_wheel with no versioning.

    The question is how can we pass the dynamic version to the setup.py command during build time. Something like:

    python setup.py --version x.x.x bdist_wheel


    There are several options to override a version file like version.py or version.txt with the new version and then use it in the setup.py file, but assuming we can't add any more steps to the build process and can only modify the build command and the python files how can it be done?

    Additional requirements:

    • In case no version is passed a default value should be used.
    • The version should be available in the python code (like having it as a __version__ parameter in the __init__.py)
    • If possible should support the usage of setup.cfg or pyproject.toml for metadata configuration

    Continue reading...

Compartilhe esta Página