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
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "colint"
version = "0.2"
version = "0.2.1"
description = ""
authors = [
{ name = "Davide Colì", email = "davide.coli@secomind.com" },
Expand Down
8 changes: 8 additions & 0 deletions src/colint/colinter.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from .newline_fix.newline_fix import newline_fix
from .params.params import Params
from .sort_libraries.sorter import sort_imports
from .utils.versioning import get_versioning

config_file = Path(__file__).parent / "config.toml"
params = Params.from_toml(config_file)
Expand Down Expand Up @@ -138,6 +139,13 @@ def main():
help="Include notebook cleaning in lint command",
)

parser.add_argument(
"--version",
action="version",
version=get_versioning(),
help="Show program's version number and exit.",
)

args = parser.parse_args()
run_tool(args)

Expand Down
32 changes: 32 additions & 0 deletions src/colint/utils/versioning.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import os
from importlib.metadata import PackageNotFoundError, version

from git import Repo


def _get_version_str() -> str:
try:
return version("colint")
except PackageNotFoundError:
return "(version info not found)"


def _get_last_commit_date():
try:
repo = Repo(
os.path.dirname(os.path.abspath(__file__)), search_parent_directories=True
)
commit = next(repo.iter_commits("HEAD", max_count=1))
return commit.committed_datetime.strftime("%Y-%m-%d")
except Exception:
return "unknown"


def get_versioning() -> str:
"""Get versioning string with the package version and last commit date.

Returns:
str: A string containing the package name, version, and the date of the
last commit.
"""
return f"colint {_get_version_str()} (last updated: {_get_last_commit_date()})"