[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
This commit is contained in:
Jesse Bannon 2023-02-20 14:18:30 -08:00 committed by GitHub
parent 251cd541ec
commit 2231bd43c8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 16 additions and 7 deletions

View file

@ -1,4 +1,8 @@
export DATE=$(shell date +'%Y.%m.%d')
export REV=$(shell git rev-parse --short HEAD)
export VERSION="$(DATE)+$(REV)"
lint: lint:
@-isort . @-isort .
@-black . @-black .
@ -10,13 +14,14 @@ check_lint:
&& pylint src/ \ && pylint src/ \
&& pydocstyle src/* && pydocstyle src/*
wheel: clean wheel: clean
$(shell echo "__version__ = \"$(VERSION)\"" > src/ytdl_sub/__init__.py)
pip3 install build pip3 install build
python3 -m build python3 -m build
docker_stage: wheel docker_stage: wheel
cp dist/*.whl docker/root/ cp dist/*.whl docker/root/
cp -R examples docker/root/defaults/ cp -R examples docker/root/defaults/
docker: docker_stage 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: docs:
sphinx-build -a -b html docs docs/_html sphinx-build -a -b html docs docs/_html
clean: clean:

View file

@ -1,6 +1,6 @@
[metadata] [metadata]
name = ytdl-sub name = ytdl-sub
version = attr:ytdl_sub.version.__version__ version = attr:ytdl_sub.__version__
author = Jesse Bannon author = Jesse Bannon
description = ytdl automated with metadata creation description = ytdl automated with metadata creation
author_email = use_github_issues@nope.com author_email = use_github_issues@nope.com

View file

@ -0,0 +1 @@
__version__ = "2023.02.20+30051b1"

View file

@ -1,5 +1,6 @@
import sys import sys
from ytdl_sub import __version__
from ytdl_sub.cli.main_args_parser import parser from ytdl_sub.cli.main_args_parser import parser
from ytdl_sub.utils.exceptions import ValidationException from ytdl_sub.utils.exceptions import ValidationException
from ytdl_sub.utils.logger import Logger from ytdl_sub.utils.logger import Logger
@ -32,9 +33,10 @@ def main():
except Exception: # pylint: disable=broad-except except Exception: # pylint: disable=broad-except
logger.exception("An uncaught error occurred:") logger.exception("An uncaught error occurred:")
logger.error( 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 " "issue at https://github.com/jmbannon/ytdl-sub/issues with your config and "
"command/subscription yaml file to reproduce. Thanks for trying ytdl-sub!", "command/subscription yaml file to reproduce. Thanks for trying ytdl-sub!",
__version__,
Logger.debug_log_filename(), Logger.debug_log_filename(),
) )
sys.exit(1) sys.exit(1)

View file

@ -1 +0,0 @@
__version__ = "0.2.0"

View file

@ -5,6 +5,7 @@ from unittest.mock import patch
import pytest import pytest
from src.ytdl_sub import __version__
from src.ytdl_sub.main import main from src.ytdl_sub.main import main
from ytdl_sub.utils.exceptions import ValidationException from ytdl_sub.utils.exceptions import ValidationException
from ytdl_sub.utils.logger import Logger from ytdl_sub.utils.logger import Logger
@ -13,7 +14,7 @@ from ytdl_sub.utils.logger import Logger
@pytest.fixture @pytest.fixture
def expected_uncaught_error_message(): def expected_uncaught_error_message():
return ( 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"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!" 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_count == 1
assert mock_error.call_args.args[0] == expected_uncaught_error_message 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()