pypa / hatch

Modern, extensible Python project management
https://hatch.pypa.io/latest/
MIT License
6.07k stars 306 forks source link

[Feature]: Add support for `versioneer`. #529

Closed wiseaidev closed 2 years ago

wiseaidev commented 2 years ago

Hey everyone. From the docs, the only way to get the version of a package is from a source file, the static value __version__ stored in a src/__init__.py file. versioneer allows you to dynamically fetch the value of the package version like so:

from ._version import get_versions
__version__ = get_versions()['version']
del get_versions

Based on the above info, I am not sure how to tell hatch to get the value of the __version__ variable from versionneer. If it is not possible, it would be nice to add support for it.

That's pretty much it. Have a nice day/night.

ofek commented 2 years ago

https://hatch.pypa.io/latest/plugins/version-source/code/

wiseaidev commented 2 years ago

Lemme test it. BRB.

Edit: Hey @ofek, it doesn't work by applying these changes.

python3 -m build --sdist ```sh * Creating virtualenv isolated environment... * Installing packages in isolated environment... (hatchling>=1.8.0) * Getting dependencies for sdist... * Building sdist... Traceback (most recent call last): File "/home/harmouch/.pyenv/versions/3.9.10/lib/python3.9/site-packages/pep517/in_process/_in_process.py", line 351, in main() File "/home/harmouch/.pyenv/versions/3.9.10/lib/python3.9/site-packages/pep517/in_process/_in_process.py", line 333, in main json_out['return_val'] = hook(**hook_input['kwargs']) File "/home/harmouch/.pyenv/versions/3.9.10/lib/python3.9/site-packages/pep517/in_process/_in_process.py", line 302, in build_sdist return backend.build_sdist(sdist_directory, config_settings) File "/tmp/build-env-sdvrodp2/lib/python3.9/site-packages/hatchling/build.py", line 21, in build_sdist return os.path.basename(next(builder.build(sdist_directory, ['standard']))) File "/tmp/build-env-sdvrodp2/lib/python3.9/site-packages/hatchling/builders/plugin/interface.py", line 80, in build self.metadata.validate_fields() File "/tmp/build-env-sdvrodp2/lib/python3.9/site-packages/hatchling/metadata/core.py", line 214, in validate_fields _ = self.version File "/tmp/build-env-sdvrodp2/lib/python3.9/site-packages/hatchling/metadata/core.py", line 102, in version self._set_version() File "/tmp/build-env-sdvrodp2/lib/python3.9/site-packages/hatchling/metadata/core.py", line 195, in _set_version version = self.hatch.version.cached File "/tmp/build-env-sdvrodp2/lib/python3.9/site-packages/hatchling/metadata/core.py", line 1277, in cached raise type(e)(f'Error getting the version from source `{self.source.PLUGIN_NAME}`: {e}') from None ModuleNotFoundError: Error getting the version from source `code`: No module named '/home/harmouch/Desktop/open-source/fides/src/fides/__init__' ERROR Backend subprocess exited when trying to invoke build_sdist ```

You can checkout this branch to try it out.

Also tried to add it in build-system to see if it works:

[build-system]
requires = ["hatchling>=1.8.0", "versioneer-518"]

Raises the same exception.

ofek commented 2 years ago

Add search-paths = ["src"] then change import to from fides._version import get_versions

wiseaidev commented 2 years ago

In my opinion, this thing requires documentation, like common gotchas or something.

ofek commented 2 years ago

Done! https://hatch.pypa.io/dev/plugins/version-source/code/#missing-imports