Skip to content

Commit

Permalink
Improve version handling and display
Browse files Browse the repository at this point in the history
  • Loading branch information
jmfontaine committed Apr 13, 2024
1 parent f622840 commit 8cfeb4c
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 3 deletions.
13 changes: 12 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ description = "Spacelift Migration Kit"
license = "MIT"
name = "spacemk"
readme = "README.md"
version = "2.0.0-alpha2"
version = "2.0.0-dev"

[tool.poetry.dependencies]
python = "^3.10"
Expand All @@ -17,6 +17,7 @@ jinja2 = "3.1.3"
pydash = "8.0.0"
python-benedict = "0.33.2"
python-dotenv = "1.0.1"
python-git-info = "^0.8.3"
python-on-whales = "0.70.1"
python-slugify = "8.0.4"
pyyaml = "6.0.1"
Expand Down
24 changes: 24 additions & 0 deletions spacemk/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,34 @@
import json
import logging
import subprocess
from importlib.metadata import version
from pathlib import Path
from shutil import which

import gitinfo
from benedict import benedict
from packaging.version import Version as PyPIVersion
from semver import Version as SemVerVersion


def pypi_version_to_semver(version: str) -> str:
pypi_version = PyPIVersion(version)

if pypi_version.dev is not None:
build = gitinfo.get_git_info()["commit"][0:7]
pre = "dev"
elif pypi_version.pre is not None:
build = None
pre_mapping = {"a": "alpha", "b": "beta", "pre": "rc"}
pre = f"{pre_mapping[pypi_version.pre[0]]}{pypi_version.pre[1]}"
else:
pre = None
build = None

return str(SemVerVersion(*pypi_version.release, build=build, prerelease=pre))


__version__ = pypi_version_to_semver(version("spacemk"))


def ensure_folder_exists(path: Path | str) -> None:
Expand Down
5 changes: 4 additions & 1 deletion spacemk/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
import ccl
import click
from benedict import benedict
from click_help_colors import HelpColorsGroup
from click_help_colors import HelpColorsGroup, version_option
from dotenv import load_dotenv
from envyaml import EnvYAML
from icecream import ic
from rich.logging import RichHandler

from spacemk import __version__ as spacemk_version

ic.configureOutput(includeContext=True, contextAbsPath=True)
debug_enabled = False

Expand All @@ -21,6 +23,7 @@
help_headers_color="yellow",
help_options_color="green",
)
@version_option(prog_name="spacemk", prog_name_color="yellow", version=spacemk_version, version_color="green")
@click.option(
"--config",
default="config.yml",
Expand Down

0 comments on commit 8cfeb4c

Please sign in to comment.