Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for package version defined as tuple #537

Closed
jlorieau opened this issue Jul 25, 2023 · 2 comments
Closed

Add support for package version defined as tuple #537

jlorieau opened this issue Jul 25, 2023 · 2 comments

Comments

@jlorieau
Copy link

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.

  1. get_project_name, which does not support tuple __version__

  2. 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.

@adiroiban
Copy link
Member

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.

@adiroiban adiroiban changed the title Possible CLI bug Add support for package version defined as tuple Jul 25, 2023
@jlorieau
Copy link
Author

jlorieau commented Jul 25, 2023

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.

@jlorieau jlorieau closed this as not planned Won't fix, can't repro, duplicate, stale Jul 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants