Add support for package version defined as tuple
jlorieau opened this issue · comments
Description
I have a python project "mypkg" with the source code in the mypkg
directory of the root project.
My version is stored as a tuple in mypkg.__init__.py
such that it can be imported as follows:
>>> import mypkg
>>> print(mypkg.__version__)
(0, 8, 1)
I have setup towncrier to recognize my package name in my pyproject.toml
file.
[tool.towncrier]
package = "mypkg"
I did not specify the package_dir
since it is the same as my package name.
Additionally, I have created the templates and stubs as described in the tutorial.
When I try to create a draft build, an exception is raised that a tuple version is unsupported.
$ towncrier build --draft
Loading template...
Finding news fragments...
Rendering news fragments...
Traceback (most recent call last):
...
TypeError: Unsupported type for __version__: <class 'tuple'>
Expected behavior
I expect the package name and package version (tuple) to be correctly processed when running towncrier build --draft
or towncrier build
.
I can circumvent this exception by specifying the package name towncrider build --draft --name mypkg
, even though the above command has correctly found and loaded my package.
Looking at the _project.py and build.py code, there appears to be a 2 different ways for versions to be loaded.
-
get_project_name
, which does not support tuple__version__
-
get_version
, which does support tuple__version__
.
I believe the fix will simplify require get_project_name
to call get_version
in the event that a tuple version is returned.
Thanks for the report.
I don't know what to say.
I suggest closing this as won't fix and instead try to get the importlib.metadata
PR merged
#502
But if you want to create a PR to add direct support for tuple, I think that we can also merge it.
Thank you @adiroiban for the note. I think the PR #502 solution would be most elegant, so I'll set it as wontfix. Sorry I missed that PR.