[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

2
.gitignore vendored
View file

@ -143,4 +143,4 @@ docker/*.whl
docker/root/*.whl
docker/root/defaults/examples
.local/
.local/

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:
@-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:

View file

@ -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

View file

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

View file

@ -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)

View file

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

View file

@ -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()