Skip to content

Commit

Permalink
Quick fix for incremental rc version normalization.
Browse files Browse the repository at this point in the history
  • Loading branch information
adiroiban committed Dec 20, 2022
1 parent 26a5eba commit fbc4f1f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
12 changes: 8 additions & 4 deletions src/towncrier/_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from importlib import import_module
from types import ModuleType

from incremental import Version
from incremental import Version as IncrementalVersion


def _get_package(package_dir: str, package: str) -> ModuleType:
Expand Down Expand Up @@ -50,8 +50,12 @@ def get_version(package_dir: str, package: str) -> str:
if isinstance(version, str):
return version.strip()

if isinstance(version, Version):
return version.base().strip()
if isinstance(version, IncrementalVersion):
# FIXME:https://github.com/twisted/incremental/issues/81
# Incremental uses `.rcN`.
# importlib uses `rcN` (without a dot separation).
# Here we make incremental work like importlib.
return version.base().strip().replace(".rc", "rc")

if isinstance(version, tuple):
return ".".join(map(str, version)).strip()
Expand All @@ -76,7 +80,7 @@ def get_project_name(package_dir: str, package: str) -> str:
if isinstance(version, str):
return package.title()

if isinstance(version, Version):
if isinstance(version, IncrementalVersion):
# Incremental has support for package names
return version.package

Expand Down
8 changes: 4 additions & 4 deletions src/towncrier/test/test_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@


try:
from importlib.metadata import version
from importlib.metadata import version as metadata_version
except ImportError:
version = None
metadata_version = None


class VersionFetchingTests(TestCase):
Expand Down Expand Up @@ -48,14 +48,14 @@ def test_tuple(self):
version = get_version(temp, "mytestproja")
self.assertEqual(version, "1.3.12")

@skipIf(version is None, "Needs importlib.metadata.")
@skipIf(metadata_version is None, "Needs importlib.metadata.")
def test_incremental(self):
"""
An incremental Version __version__ is picked up.
"""
pkg = "../src"

self.assertEqual(version("towncrier"), get_version(pkg, "towncrier"))
self.assertEqual(metadata_version("towncrier"), get_version(pkg, "towncrier"))
self.assertEqual("towncrier", get_project_name(pkg, "towncrier"))

def _setup_missing(self):
Expand Down

0 comments on commit fbc4f1f

Please sign in to comment.