From 2231bd43c86801de97ed5956d9f4983654e8b924 Mon Sep 17 00:00:00 2001 From: Jesse Bannon Date: Mon, 20 Feb 2023 14:18:30 -0800 Subject: [PATCH] [BACKEND] Set __version__ as date, dynamically update it in make (#456) * [BACKEND] Set python __version__ as date, dynamically update it in make * set version dynamically * keep empty * git ignore __init__ * keep init * keep * fix unit test --- .gitignore | 2 +- Makefile | 7 ++++++- setup.cfg | 2 +- src/ytdl_sub/__init__.py | 1 + src/ytdl_sub/main.py | 4 +++- src/ytdl_sub/version.py | 1 - tests/unit/main/test_main.py | 6 ++++-- 7 files changed, 16 insertions(+), 7 deletions(-) delete mode 100644 src/ytdl_sub/version.py diff --git a/.gitignore b/.gitignore index 41f140cf..c3d15213 100644 --- a/.gitignore +++ b/.gitignore @@ -143,4 +143,4 @@ docker/*.whl docker/root/*.whl docker/root/defaults/examples -.local/ +.local/ \ No newline at end of file diff --git a/Makefile b/Makefile index 12bced16..eb599acf 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,8 @@ +export DATE=$(shell date +'%Y.%m.%d') +export REV=$(shell git rev-parse --short HEAD) +export VERSION="$(DATE)+$(REV)" + lint: @-isort . @-black . @@ -10,13 +14,14 @@ check_lint: && pylint src/ \ && pydocstyle src/* wheel: clean + $(shell echo "__version__ = \"$(VERSION)\"" > src/ytdl_sub/__init__.py) pip3 install build python3 -m build docker_stage: wheel cp dist/*.whl docker/root/ cp -R examples docker/root/defaults/ docker: docker_stage - sudo docker build --no-cache -t ytdl-sub:0.1 docker/ + sudo docker build --no-cache -t ytdl-sub:local docker/ docs: sphinx-build -a -b html docs docs/_html clean: diff --git a/setup.cfg b/setup.cfg index 66f6ecd9..658fcd12 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = ytdl-sub -version = attr:ytdl_sub.version.__version__ +version = attr:ytdl_sub.__version__ author = Jesse Bannon description = ytdl automated with metadata creation author_email = use_github_issues@nope.com diff --git a/src/ytdl_sub/__init__.py b/src/ytdl_sub/__init__.py index e69de29b..37a1a3c4 100644 --- a/src/ytdl_sub/__init__.py +++ b/src/ytdl_sub/__init__.py @@ -0,0 +1 @@ +__version__ = "2023.02.20+30051b1" diff --git a/src/ytdl_sub/main.py b/src/ytdl_sub/main.py index fd8cc371..e8f7e147 100644 --- a/src/ytdl_sub/main.py +++ b/src/ytdl_sub/main.py @@ -1,5 +1,6 @@ import sys +from ytdl_sub import __version__ from ytdl_sub.cli.main_args_parser import parser from ytdl_sub.utils.exceptions import ValidationException from ytdl_sub.utils.logger import Logger @@ -32,9 +33,10 @@ def main(): except Exception: # pylint: disable=broad-except logger.exception("An uncaught error occurred:") logger.error( - "Please upload the error log file '%s' and make a Github " + "Version %s\nPlease upload the error log file '%s' and make a Github " "issue at https://github.com/jmbannon/ytdl-sub/issues with your config and " "command/subscription yaml file to reproduce. Thanks for trying ytdl-sub!", + __version__, Logger.debug_log_filename(), ) sys.exit(1) diff --git a/src/ytdl_sub/version.py b/src/ytdl_sub/version.py deleted file mode 100644 index d3ec452c..00000000 --- a/src/ytdl_sub/version.py +++ /dev/null @@ -1 +0,0 @@ -__version__ = "0.2.0" diff --git a/tests/unit/main/test_main.py b/tests/unit/main/test_main.py index c1c91bfd..cdc17022 100644 --- a/tests/unit/main/test_main.py +++ b/tests/unit/main/test_main.py @@ -5,6 +5,7 @@ from unittest.mock import patch import pytest +from src.ytdl_sub import __version__ from src.ytdl_sub.main import main from ytdl_sub.utils.exceptions import ValidationException from ytdl_sub.utils.logger import Logger @@ -13,7 +14,7 @@ from ytdl_sub.utils.logger import Logger @pytest.fixture def expected_uncaught_error_message(): return ( - f"Please upload the error log file '%s' and make a " + f"Version %s\nPlease upload the error log file '%s' and make a " f"Github issue at https://github.com/jmbannon/ytdl-sub/issues with your config and " f"command/subscription yaml file to reproduce. Thanks for trying ytdl-sub!" ) @@ -63,4 +64,5 @@ def test_main_uncaught_error(capsys, mock_sys_exit, expected_uncaught_error_mess assert mock_error.call_count == 1 assert mock_error.call_args.args[0] == expected_uncaught_error_message - assert mock_error.call_args.args[1] == Logger.debug_log_filename() + assert mock_error.call_args.args[1] == __version__ + assert mock_error.call_args.args[2] == Logger.debug_log_filename()