Skip to content

Commit

Permalink
Add semantic versioning
Browse files Browse the repository at this point in the history
  • Loading branch information
taleksovska committed May 14, 2024
1 parent 9187ba3 commit 7f1ae58
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 15 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "Enabler" # noqa
version = "0.1" # noqa
version = "0.1.0" # noqa
description = "Enabler is a CLI application built for making life easier when working on microservice-based applications. Through this package we can create, edit and execute custom commands to configure microservices." # noqa
authors = ["Your Name <[email protected]>"] # noqa

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name="enabler",
version="0.1",
version="0.1.0",
packages=["enabler", "src.enabler_keitaro_inc.commands", "src.enabler_keitaro_inc.helpers"], # noqa
include_package_data=True,
install_requires=["click==7.1.1",
Expand Down
5 changes: 4 additions & 1 deletion src/enabler_keitaro_inc/commands/cmd_version.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from src.enabler_keitaro_inc.enabler import pass_environment, logger
import pkg_resources
import click
from src.enabler_keitaro_inc.type.semver import BasedVersionParamType

# Command to get the current Enabler version
@click.group('version', short_help='Get current version of Enabler', invoke_without_command=True) # noqa
Expand All @@ -10,4 +11,6 @@ def cli(ctx, kube_context_cli):
"""Get current version of Enabler"""
distribution = pkg_resources.get_distribution("enabler")
version = distribution.version
logger.info("Enabler "+version)
# Ensure the version string has three parts (major, minor, patch)
formatted_version = BasedVersionParamType().convert(version, None, None)
logger.info(f"Enabler {formatted_version}")
22 changes: 12 additions & 10 deletions src/enabler_keitaro_inc/type/semver.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ class BasedVersionParamType(click.ParamType):
def convert(self, value, param, ctx):
try:
parse(value)
return (value)
except TypeError:
self.fail(
'{value!r} is not a valid version, please use semver',
param,
ctx,
)
except ValueError:
self.fail(f'{value!r} is not a valid version, please use semver',
param, ctx)
return value
except (TypeError, ValueError):
parts = value.split('.')
if len(parts) == 2:
parts.append('0') # Default patch version to 0 if not provided
elif len(parts) == 3:
# Increment patch version for bug fixes
parts[2] = str(int(parts[2]) + 1)
else:
self.fail(f'{value!r} is not a valid version, please use semver', param, ctx) # noqa

return '.'.join(parts)
4 changes: 2 additions & 2 deletions tests/version_unittests.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def setUp(self):

@patch('src.enabler_keitaro_inc.enabler.subprocess.run')
def test_version_command(self, mock_subprocess_run):
mock_subprocess_run.return_value.stdout = 'Enabler 0.1'
mock_subprocess_run.return_value.stdout = 'Enabler 0.1.0'
version = self.cli.version_command()
expected_version = 'Enabler 0.1'
expected_version = 'Enabler 0.1.0'
self.assertEqual(version, expected_version)

0 comments on commit 7f1ae58

Please sign in to comment.