From 99161c82d236d5b8a1809c10289affc45fb24795 Mon Sep 17 00:00:00 2001 From: eclipse Date: Tue, 4 Nov 2025 13:02:46 +0100 Subject: [PATCH] added "version" subcommand; but the version number is still hardcoded in two separate locations as poetry 1.1.12 does not support dynamic attributes in pyproject.toml --- README.md | 32 +++++++++++++++++++++++++++++++- poetry.lock | 2 +- pyproject.toml | 2 +- src/bookbuild/__init__.py | 1 + src/bookbuild/__main__.py | 4 ++++ src/bookbuild/defaults.py | 24 +++++++++++++----------- src/bookbuild/main.py | 2 ++ src/bookbuild/version.py | 19 +++++++++++++++++++ 8 files changed, 72 insertions(+), 14 deletions(-) create mode 100644 src/bookbuild/version.py diff --git a/README.md b/README.md index 52d114a..3670014 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ ## Installation -Im lokalen `bookbuild`-Repository (Development): +Im lokalen `bookbuild`-Repository (Development) **fkt. nicht: der Befehl installiert nur die dependencies, nicht bookbuild selbst**: ```bash $ poetry build @@ -30,3 +30,33 @@ Systemweit (fkt. noch nicht): $ pip install -e git+https://git.unterdemradar.de/tobias/bookbuild#egg=bookbuild ``` + + +## Programm ausführen + +Mit `poetry run bookbuild` kann man das Programm ausführen, ohne die venv vorher aktivieren zu müssen (das erledigt poetry im Hintergrund). + +Manchmal passiert es, dass der Befehl immer nur die installierte Version ausführt und nicht den aktuellen Code aus dem Repository. In diesem Fall muss man `poetry update` ausführen, dann sollte es wieder gehen + +Im Zweifel kann man den aktuellen Code auch direkt ausführen, indem man das `src/`-Verzeichnis mit einbezieht. Dazu wechselt man entweder ins Verzeichnis: + +```bash +$ # mit poetry +$ cd src/ +$ poetry run bookbuild # oder poetry run python -m bookbuild +$ # ohne poetry +$ . .venv/bin/activate +$ cd src/ +$ python -m bookbuild +``` + +Oder man gibt das Verzeichnis als Modulpfad mit an: + +```bash +$ # mit poetry +$ poetry run python -m src.bookbuild # was nicht geht: poetry run src.bookbuild +$ # ohne poetry +$ . .venv/bin/activate +$ python -m src.bookbuild +``` + diff --git a/poetry.lock b/poetry.lock index d362daf..f9425ba 100644 --- a/poetry.lock +++ b/poetry.lock @@ -131,7 +131,7 @@ python-versions = ">=3.9" [metadata] lock-version = "1.1" python-versions = "^3.10" -content-hash = "6fbf8536c3d7c8fe08a1342d50c3fee906261965039e443c8b323a381ceb9b4c" +content-hash = "58dd26373197ceffe88b78af71c4a7316fa3d383b8ab14180fb85b5af1ecbdef" [metadata.files] click = [] diff --git a/pyproject.toml b/pyproject.toml index 1f2103a..2e91c18 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,7 @@ [tool.poetry] name = "bookbuild" description = "Build script for my book projects" -version = "0.2.0" +version = "0.2.1" license = "GPL-3.0-or-later" readme = "README.md" authors = ["Tobias Radloff "] diff --git a/src/bookbuild/__init__.py b/src/bookbuild/__init__.py index e69de29..3ced358 100644 --- a/src/bookbuild/__init__.py +++ b/src/bookbuild/__init__.py @@ -0,0 +1 @@ +__version__ = "0.2.1" diff --git a/src/bookbuild/__main__.py b/src/bookbuild/__main__.py index 2144bde..e8c71df 100644 --- a/src/bookbuild/__main__.py +++ b/src/bookbuild/__main__.py @@ -2,3 +2,7 @@ from .main import app app(prog_name="bookbuild") + +#if __name__ == "__main__": +# app() + diff --git a/src/bookbuild/defaults.py b/src/bookbuild/defaults.py index c725857..9c6a46e 100644 --- a/src/bookbuild/defaults.py +++ b/src/bookbuild/defaults.py @@ -66,7 +66,7 @@ def add_presuffix(path: Path|str, presuffix: str) -> Path: return path.parent / f"{path.stem}{presuffix}{path.suffix}" -def get_data_from_yaml(input_file: str, key: str) -> str|list|dict: +def get_data_from_yaml(input_file: str, key: str) -> str|list|dict|None: with open(input_file, "r") as file: data = yaml.load(file, Loader=yaml.Loader) return data.get(key) @@ -74,7 +74,7 @@ def get_data_from_yaml(input_file: str, key: str) -> str|list|dict: def __get_executable(cmd: str, optional: bool = False) -> str|None: """ - Returns the path to a given shell command. If the command doesn't exist in path, the function exits unless optional is True, in which case the return value is None. + Returns the path to a given shell command as a string. If the command doesn't exist in path, the function exits unless optional is True, in which case the return value is None. """ exe = which(cmd) if not exe: @@ -93,24 +93,26 @@ def get_input_files(target_format: str) -> list: if list_file.is_file(): with open(list_file, "r") as file: return [line.strip() for line in file if line[0] != "#"] - # use all files otherwise; ignore tredition flag + # use all files otherwise else: paths = CONTENT_DIR.glob('**/*.md') return list(map(str, sorted(paths))) def merge_pdf_with_covers(frontcover: str, content: str, backcover: str, keep_coverless: bool=False): - pdflist = [] - - # check if files exist - for filename in [frontcover, content, backcover]: - if Path(filename).is_file(): - pdflist.append(filename) +# pdflist = [] +# +# # check if files exist +# for filename in [frontcover, content, backcover]: +# if Path(filename).is_file(): +# pdflist.append(filename) # merge files wwith pypdf + LOGGER.debug("merge_pdf_with_covers() with new code stuff") merger = PdfWriter() - for pdf in pdflist: - merger.append(pdf) + for pdf in [frontcover, content, backcover]: + if pdf and Path(pdf).is_file(): + merger.append(pdf) # write merged file outfile = str(add_presuffix(content, ".with-covers")) if keep_coverless else content diff --git a/src/bookbuild/main.py b/src/bookbuild/main.py index dae4db9..404bc6b 100644 --- a/src/bookbuild/main.py +++ b/src/bookbuild/main.py @@ -26,6 +26,8 @@ from .pdf import pdf_app app.add_typer(pdf_app) from .all import all_app app.add_typer(all_app) +from .version import version_app +app.add_typer(version_app) # Make CLI runnable from source tree with python src/package if not __package__: diff --git a/src/bookbuild/version.py b/src/bookbuild/version.py new file mode 100644 index 0000000..ddde64d --- /dev/null +++ b/src/bookbuild/version.py @@ -0,0 +1,19 @@ +import typer + +from . import __version__ + +# instantiate typer app +version_app = typer.Typer() + + +# ############## +# TYPER COMMANDS +# ############## + +@version_app.command() +def version(): + """ + Print the version number and exit. + """ + print(f"bookbuild v{__version__}") + \ No newline at end of file