Skip to content

Commit

Permalink
Refactor CLI structure and update dependencies
Browse files Browse the repository at this point in the history
Moved CLI logic to a dedicated `cli.py` module to improve maintainability and readability. Updated Python base image to 3.13 in Dockerfile and added the `truststore` package for enhanced SSL certificate handling. Adjusted tests, imports, and entry points to reflect the new CLI structure.
  • Loading branch information
dvershinin committed Dec 23, 2024
1 parent 7035504 commit b52da68
Show file tree
Hide file tree
Showing 12 changed files with 452 additions and 436 deletions.
5 changes: 4 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Use a lightweight base image with Python and pip installed
FROM python:3.9-alpine
FROM python:3.13-alpine

# Using "lastversion" user as provided by some linter was a mistake and causes issues with GitHub actions being ran as "runner"
# and lastversion running as a different user and being unable to work with workspace files for extracting to its directory
Expand All @@ -15,5 +15,8 @@ COPY setup.py README.md ./
# Install the application and its dependencies
RUN pip install -e .

# Additionally install truststore package for SSL certificate verification via pip
RUN pip install truststore

# Set the entrypoint to the command that runs your application
ENTRYPOINT ["lastversion"]
4 changes: 2 additions & 2 deletions bandit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
skips: ['B105', B404', 'B603']
# Do not check paths including `/tests/`:
# they use `assert`, leading to B101 false positives.
# also we do not need check security issues in tests
# also we do not need to check security issues in tests
exclude_dirs:
- '/tests/'
- '/tests/'
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
},
tests_require=tests_requires,
include_package_data=True,
entry_points={"console_scripts": ["lastversion = lastversion:main"]},
entry_points={"console_scripts": ["lastversion = lastversion.cli:main"]},
classifiers=[
"Intended Audience :: Developers",
"Intended Audience :: System Administrators",
Expand Down
20 changes: 2 additions & 18 deletions src/lastversion/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,14 @@

import logging

from .__about__ import (
__version__,
)

# Intentionally import for export here, so it is ok to silence DeepSource test
# skipcq: PY-W2000
from .lastversion import __self__

# skipcq: PY-W2000
from .lastversion import check_version

# skipcq: PY-W2000
from .lastversion import has_update
from .lastversion import check_version, has_update, latest

# skipcq: PY-W2000
from .lastversion import latest
__all__ = ["check_version", "has_update", "latest"]

# skipcq: PY-W2000
from .lastversion import main

# https://realpython.com/python-logging-source-code/#library-vs-application-logging-what-is-nullhandler
# When used as a library, we default to opt-in approach, whereas library user
# has to enable logging
# from lastversion
logging.getLogger(__name__).addHandler(logging.NullHandler())
# patch up https://github.com/ionrock/cachecontrol/issues/230
logging.getLogger("cachecontrol.controller").addHandler(logging.NullHandler())
Expand Down
5 changes: 3 additions & 2 deletions src/lastversion/__main__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Used to run the package as a script with `python -m lastversion`."""
from lastversion import lastversion

lastversion.main()
from lastversion import cli

cli.main()
19 changes: 10 additions & 9 deletions src/lastversion/argparse_version.py
Original file line number Diff line number Diff line change
@@ -1,32 +1,33 @@
"""Provides a custom argparse action to show program's version and exit."""
"""Provides a custom argparse action to show the program's version and exit."""

import logging
import sys as _sys
from argparse import SUPPRESS, Action

import lastversion
from .__about__ import __version__
from .__about__ import __version__, __self__
from .exceptions import ApiCredentialsError


log = logging.getLogger(__name__)


class VersionAction(Action):
"""Custom argparse action to show program's version and exit."""
"""Custom argparse action to show the program's version and exit."""

def __init__(self, **kwargs):
# Set default values if not provided in kwargs
kwargs.setdefault('dest', SUPPRESS)
kwargs.setdefault('default', SUPPRESS)
kwargs.setdefault('nargs', 0)
kwargs.setdefault('help', "show program's version number and exit")
kwargs.setdefault("dest", SUPPRESS)
kwargs.setdefault("default", SUPPRESS)
kwargs.setdefault("nargs", 0)
kwargs.setdefault("help", "show program's version number and exit")
super().__init__(**kwargs)
self.version = kwargs.get('version2')
self.version = kwargs.get("version2")

def __call__(self, parser, namespace, values, option_string=None):
version = f"%(prog)s {__version__}"
try:
last_version = lastversion.latest(lastversion.__self__)
last_version = lastversion.latest(__self__)
if __version__ == str(last_version):
version += ", up to date"
else:
Expand Down
Loading

0 comments on commit b52da68

Please sign in to comment.