Generating an exported package version from poetry's version

14 hours ago 3
ARTICLE AD BOX

I maintain a number of Python packages which use poetry as its dependency and build system. For some of these packages I would find it very useful for the package to be able to export its underlying version number, for example for use in user-agents and metadata tags and the like.

Currently I have a preflight build script that generates a __version__.py inside the package at build time, and this file is excluded by .gitignore and contains contents like:

__version__ = "0.5.3rc3"

or whatever the current value of tool.poetry.version is. However, since it's excluded by .gitignore it is not included as part of the build, even if I explicitly add it with an include directive within tool.poetry (which is puzzling, as the poetry docs state that include should override the implicit exclude from .gitignore).

However, I suspect that I am going about this all wrong and I would like to know if there's a better approach for exporting a package's own version number at poetry build time.

Read Entire Article