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

#432 Use importlib.metadata.version to get the version #502

Merged
merged 22 commits into from
May 22, 2024
Merged
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
c933cbb
#432 An initial attempt
agriyakhetarpal Apr 29, 2023
89c3232
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Apr 29, 2023
d8e281f
Merge branch 'trunk' into 432-poetry-version
agriyakhetarpal May 2, 2023
3aff9fb
Merge branch 'trunk' into 432-poetry-version
adiroiban Jun 4, 2023
ff05eed
Merge branch 'trunk' into 432-poetry-version
adiroiban Jul 17, 2023
69b197a
Merge branch 'trunk' into 432-poetry-version
adiroiban Apr 28, 2024
c2a23df
Get metadata version from packages_distributions
SmileyChris May 7, 2024
2af8e80
Fix dependency format
SmileyChris May 21, 2024
6b85972
Safer check in _get_metadata_version
SmileyChris May 21, 2024
819d160
Update test to match new "no version found" exception text
SmileyChris May 21, 2024
7f1d8ce
logic style nitpick
SmileyChris May 21, 2024
1f28954
Mypy fixes
SmileyChris May 21, 2024
770eb48
Fix incremental test
SmileyChris May 21, 2024
9bbcb70
Add test to check version from metadata
SmileyChris May 22, 2024
85a769e
Remove a redundant try/except
SmileyChris May 22, 2024
30fe7ed
Looser pin for importlib-metadata
SmileyChris May 22, 2024
6ec518d
Use a pyupgrade compatible format for the importlib_metadata fallback…
SmileyChris May 22, 2024
d5e0a60
Improve comments for the version-related methods
SmileyChris May 22, 2024
f02a26a
Small tweak to the version error message
SmileyChris May 22, 2024
8050a0b
Revert missing version name change in test
SmileyChris May 22, 2024
5bee9d4
Add a newsfragment
SmileyChris May 22, 2024
783e122
Merge branch 'trunk' into 432-poetry-version
SmileyChris May 22, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Mypy fixes
  • Loading branch information
SmileyChris committed May 21, 2024
commit 1f28954877acd1e3a36b36136272a606b752b22b
5 changes: 4 additions & 1 deletion src/towncrier/_project.py
Original file line number Diff line number Diff line change
@@ -13,14 +13,15 @@
from importlib.metadata import PackageNotFoundError
from importlib.metadata import version as metadata_version
from types import ModuleType
from typing import Any

from incremental import Version as IncrementalVersion


try:
from importlib.metadata import packages_distributions
except ImportError:
from importlib_metadata import packages_distributions
from importlib_metadata import packages_distributions # type: ignore


def _get_package(package_dir: str, package: str) -> ModuleType:
@@ -57,6 +58,8 @@ def _get_metadata_version(package: str) -> str | None:


def get_version(package_dir: str, package: str) -> str:
version: Any

# First try to get the version from the package metadata.
if version := _get_metadata_version(package):
return version