Closed amyreese closed 1 year ago
Being able to read __version__
from a separate file, without needing to import the entire package, would resolve omnilib/ufmt#123 and mitigate the need for conda-forge to install runtime dependencies at build time to support packages that import __version__
from a separate file.
FWIW, there's prior art in pypa/setuptools for this: https://github.com/pypa/setuptools/blob/be6c0218bcba78dbd4ea0b5a8bb9acd5d5306240/setuptools/config/expand.py#L160-L168
Thanks! There's one little change I want (comment above), but I like the idea and the implementation. :+1:
Thanks @amyreese, and nice work on a first contribution. :slightly_smiling_face:
In cases where packages import
__version__
from version modules (like those generated by setuptools_scm or attribution), this allows flit-core to use the existing ast-based logic to read the version directly from those files when possible. It checks a few well-known version filenames, including the package-level__init__.py
as usual, with__init__.py
taking precedence over external version files if an assigned__version__
value exists in multiple places.This makes flit more resilient to reading version from these packages, even if their
__init__.py
has transitive imports that aren't available in the environment at build time (eg, conda-forge builds). It also reduces the number of times when flit has to fall back to actually importing the__init__.py
file rather than reading with ast.