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

When updating a version ignore the current version in case of erros #804

Merged
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
14 changes: 9 additions & 5 deletions pontos/version/commands/_cargo.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from pathlib import Path
from typing import Iterator, Tuple, Union, Literal
from typing import Iterator, Literal, Tuple, Union

import tomlkit

from ..errors import VersionError
from ..version import Version, VersionUpdate
from ._command import VersionCommand
from ..errors import VersionError


class CargoVersionCommand(VersionCommand):
Expand Down Expand Up @@ -40,10 +40,14 @@
def update_version(
self, new_version: Version, *, force: bool = False
) -> VersionUpdate:
previous_version = self.get_current_version()
try:
previous_version = self.get_current_version()

if not force and new_version == previous_version:
return VersionUpdate(previous=previous_version, new=new_version)
if not force and new_version == previous_version:
return VersionUpdate(previous=previous_version, new=new_version)
except VersionError:

Check warning on line 48 in pontos/version/commands/_cargo.py

View check run for this annotation

Codecov / codecov/patch

pontos/version/commands/_cargo.py#L48

Added line #L48 was not covered by tests
# just ignore current version and override it
previous_version = None

Check warning on line 50 in pontos/version/commands/_cargo.py

View check run for this annotation

Codecov / codecov/patch

pontos/version/commands/_cargo.py#L50

Added line #L50 was not covered by tests

changed_files = []
for project_path, project in self.__as_project_document(
Expand Down
11 changes: 8 additions & 3 deletions pontos/version/commands/_cmake.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,15 @@
) -> VersionUpdate:
content = self.project_file_path.read_text(encoding="utf-8")
cmake_version_parser = CMakeVersionParser(content)
previous_version = self.get_current_version()

if not force and new_version == previous_version:
return VersionUpdate(previous=previous_version, new=new_version)
try:
previous_version = self.get_current_version()

if not force and new_version == previous_version:
return VersionUpdate(previous=previous_version, new=new_version)
except VersionError:

Check warning on line 42 in pontos/version/commands/_cmake.py

View check run for this annotation

Codecov / codecov/patch

pontos/version/commands/_cmake.py#L42

Added line #L42 was not covered by tests
# just ignore current version and override it
previous_version = None

Check warning on line 44 in pontos/version/commands/_cmake.py

View check run for this annotation

Codecov / codecov/patch

pontos/version/commands/_cmake.py#L44

Added line #L44 was not covered by tests

new_content = cmake_version_parser.update_version(new_version)
self.project_file_path.write_text(new_content, encoding="utf-8")
Expand Down
7 changes: 3 additions & 4 deletions pontos/version/commands/_go.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,12 @@ def update_version(
"""Update the current version of this project"""
try:
current_version = self.get_current_version()
if not force and new_version == current_version:
return VersionUpdate(previous=current_version, new=new_version)
except VersionError:
# likely the initial release
# just ignore current version and override it
current_version = None

if not force and new_version == current_version:
return VersionUpdate(previous=current_version, new=new_version)

self._update_version_file(new_version=new_version)

return VersionUpdate(
Expand Down
12 changes: 8 additions & 4 deletions pontos/version/commands/_java.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
def find_file(
filename: Path, search_path: str, search_glob: str
) -> Optional[Path]:
"""Find a file somewherre within an directory tree
"""Find a file somewhere within an directory tree
Arguments:
filename (Path) The file to look up
search_path (str) The path to look for the file
Expand Down Expand Up @@ -180,9 +180,13 @@
def update_version(
self, new_version: Version, *, force: bool = False
) -> VersionUpdate:
package_version = self.get_current_version()
if not force and new_version == package_version:
return VersionUpdate(previous=package_version, new=new_version)
try:
package_version = self.get_current_version()
if not force and new_version == package_version:
return VersionUpdate(previous=package_version, new=new_version)
except VersionError:

Check warning on line 187 in pontos/version/commands/_java.py

View check run for this annotation

Codecov / codecov/patch

pontos/version/commands/_java.py#L187

Added line #L187 was not covered by tests
# just ignore current version and override it
package_version = None

Check warning on line 189 in pontos/version/commands/_java.py

View check run for this annotation

Codecov / codecov/patch

pontos/version/commands/_java.py#L189

Added line #L189 was not covered by tests

changed_files = [self.project_file_path]
self._update_pom_version(new_version=new_version)
Expand Down
10 changes: 7 additions & 3 deletions pontos/version/commands/_javascript.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,13 @@ def _update_version_file(
def update_version(
self, new_version: Version, *, force: bool = False
) -> VersionUpdate:
package_version = self.get_current_version()
if not force and new_version == package_version:
return VersionUpdate(previous=package_version, new=new_version)
try:
package_version = self.get_current_version()
if not force and new_version == package_version:
return VersionUpdate(previous=package_version, new=new_version)
except VersionError:
# just ignore current version and override it
package_version = None

changed_files = [self.project_file_path]
self._update_package_json(new_version=new_version)
Expand Down
31 changes: 18 additions & 13 deletions pontos/version/commands/_python.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,23 +185,28 @@ def verify_version(
def update_version(
self, new_version: Version, *, force: bool = False
) -> VersionUpdate:
try:
current_version = self.get_current_version()
except VersionError:
# maybe no version module exists yet. fallback to version from
# pyproject.toml
current_version = self._get_version_from_pyproject_toml()

new_pep440_version = PEP440VersioningScheme.from_version(new_version)
current_converted_version = self.versioning_scheme.from_version(
current_version
)

if not force and new_pep440_version == current_version:
return VersionUpdate(
previous=current_converted_version, new=new_version
try:
try:
current_version = self.get_current_version()
except VersionError:
# maybe no version module exists yet. fallback to version from
# pyproject.toml
current_version = self._get_version_from_pyproject_toml()

current_converted_version = self.versioning_scheme.from_version(
current_version
)

if not force and new_pep440_version == current_version:
return VersionUpdate(
previous=current_converted_version, new=new_version
)
except VersionError:
# just ignore current version and override it
current_converted_version = None

try:
self._update_pyproject_version(new_version=new_pep440_version)
except OSError as e:
Expand Down
4 changes: 2 additions & 2 deletions tests/version/commands/test_python.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def test_empty_pyproject_toml(self):
"", name="pyproject.toml", change_into=True
), self.assertRaisesRegex(
VersionError,
r"Version information not found in .*pyproject\.toml file\.",
r"\[tool.pontos.version\] section missing in .*pyproject\.toml\.",
):
cmd = PythonVersionCommand(PEP440VersioningScheme)
new_version = PEP440VersioningScheme.parse_version("22.1.2")
Expand All @@ -166,7 +166,7 @@ def test_empty_tool_section(self):
"[tool]", name="pyproject.toml", change_into=True
), self.assertRaisesRegex(
VersionError,
r"Version information not found in .*pyproject\.toml file\.",
r"\[tool.pontos.version\] section missing in .*pyproject\.toml\.",
):
cmd = PythonVersionCommand(PEP440VersioningScheme)
new_version = PEP440VersioningScheme.parse_version("22.1.2")
Expand Down
Loading