Skip to content Skip to sidebar Skip to footer

Is There Any Practical Reason Why I Must Have A Code Version Embedded In Python Source Code?

Is there any practical reason why I must have a code version embedded in the source code? Explicitly I'm interested in setup.py but also some use __version__. By 'embed in source

Solution 1:

Technically, you don't have to embed the version in your package. Passing the version to setuptools.setup() will ensure that it will be save in the package metadata for the packaging mechanism to handle (e.g. setuptools, pip, poetry, etc.).

It has been deemed is a good practice to also include it to the package as it could be useful when you write code which needs to check version of the library (the __version__ "dundler" is first mentioned in PEP 8 and clarified in PEP 396), but it might not be necessary anymore since Python 3.8 embed importlib.metadata:

>>> from importlib.metadata import version
>>> version("wheel")
'0.35.1'

So your solution would work fine, but I would recommend you to use setuptools-scm instead which will prevent you for managing the subprocess yourself.

Post a Comment for "Is There Any Practical Reason Why I Must Have A Code Version Embedded In Python Source Code?"