Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,7 @@ See also git tags: https://github.com/jedie/manageprojects/tags
[comment]: <> (✂✂✂ auto generated history start ✂✂✂)

* [v0.23.0](https://github.com/jedie/manageprojects/compare/v0.22.1...v0.23.0)
* 2025-09-04 - Bugfix type error in publish version check
* 2025-09-04 - ruff: remove "force-sort-within-sections = true" (Just use the default)
* 2024-11-21 - Switch from click to tyro
* [v0.22.1](https://github.com/jedie/manageprojects/compare/v0.22.0...v0.22.1)
Expand Down
38 changes: 35 additions & 3 deletions manageprojects/tests/test_utilities_publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,23 @@
import sys
import tomllib
from pathlib import Path
from unittest import TestCase
from unittest.mock import patch

from bx_py_utils.test_utils.redirect import RedirectOut
from cli_base.cli_tools import subprocess_utils
from cli_base.cli_tools.test_utils.git_utils import init_git
from cli_base.cli_tools.test_utils.logs import AssertLogs
from cli_base.cli_tools.test_utils.rich_test_utils import NoColorEnvRich
from packaging.version import Version

import manageprojects
from manageprojects.cli_dev import PACKAGE_ROOT
from manageprojects.test_utils.subprocess import FakeStdout, SubprocessCallMock
from manageprojects.tests.base import GIT_BIN_PARENT
from manageprojects.tests.base import GIT_BIN_PARENT, BaseTestCase
from manageprojects.utilities.publish import (
PublisherGit,
build,
check_version,
clean_version,
get_pyproject_toml_version,
hatchling_dynamic_version,
Expand All @@ -25,7 +27,7 @@
from manageprojects.utilities.temp_path import TemporaryDirectory


class PublishTestCase(TestCase):
class PublishTestCase(BaseTestCase):
def test_build(self):
def return_callback(popenargs, args, kwargs):
return FakeStdout(stdout='Mocked run output')
Expand Down Expand Up @@ -216,3 +218,33 @@ def test_hatchling_dynamic_version(self):
)
self.assertIsInstance(version, Version)
self.assertEqual(version, Version(manageprojects.__version__))

def test_check_version(self):
# Enforce matching versions:
with patch('manageprojects.utilities.publish.version', return_value=manageprojects.__version__):
module_version = check_version(
module=manageprojects,
package_path=PACKAGE_ROOT,
)
self.assertEqual(module_version, Version(manageprojects.__version__))

# Error case:
with (
NoColorEnvRich(),
RedirectOut() as buffer,
self.assertRaises(SystemExit),
patch('manageprojects.utilities.publish.version', return_value='0.1.2'),
):
module_version = check_version(
module=manageprojects,
package_path=PACKAGE_ROOT,
)
self.assertEqual(module_version, Version(manageprojects.__version__))
self.assertEqual(buffer.stderr, '')
self.assert_in_content(
got=buffer.stdout,
parts=(
f'Version mismatch: current version {manageprojects.__version__} is not the installed one: 0.1.2',
'(Hint: Install package and run publish again)',
),
)
8 changes: 6 additions & 2 deletions manageprojects/utilities/publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,12 @@ def check_version(*, module, package_path: Path, distribution_name: str | None =
if not distribution_name:
distribution_name = module.__name__

module_version = clean_version(module.__version__)
installed_version = clean_version(version(distribution_name))
if module_version := module.__version__:
module_version = clean_version(module_version)

if installed_version := version(distribution_name):
installed_version = clean_version(installed_version)

if module_version != installed_version:
exit_with_error(
f'Version mismatch: current version {module_version} is not the installed one: {installed_version}',
Expand Down