Compare commits

...

4 Commits
v0.2.0 ... main

9 changed files with 108 additions and 19 deletions

View File

@ -2,5 +2,61 @@
## Dependencies
python>=3.x
python-poetry>=1.1.0
* python>=3.x
* python-poetry>=1.1.0
## Installation
Im lokalen `bookbuild`-Repository (Development) **fkt. nicht: der Befehl installiert nur die dependencies, nicht bookbuild selbst**:
```bash
$ poetry build
$ poetry install
```
In einem `book`-Repository und nur auf dieses begrenzt:
```bash
$ python -m venv .venv
$ source .venv/bin/activate
$ cd ~/path/to/bookbuild
$ poetry build
$ poetry install # alternativ: pip install dist/bookbuild-x.y.z-py3-none-any.whl
```
Systemweit (fkt. noch nicht):
```bash
$ 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
```

2
poetry.lock generated
View File

@ -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 = []

View File

@ -1,22 +1,28 @@
[tool.poetry]
name = "bookbuild"
version = "0.2.0"
description = "Build script for my book projects"
version = "0.2.1"
license = "GPL-3.0-or-later"
readme = "README.md"
authors = ["Tobias Radloff <mail@tobias-radloff.de>"]
license = "GPLv3"
packages = [{ include = "bookbuild", from = "src" }]
[tool.poetry.urls]
repository = "https://git.unterdemradar.de/tobias/bookbuild"
[tool.poetry.dependencies]
python = "^3.10"
pypdf = "^6.1.2"
PyYAML = "^6.0.3"
typer = "^0.19.2"
[tool.poetry.dev-dependencies]
[tool.poetry.scripts]
bookbuild = 'bookbuild.main:app'
[build-system]
requires = ["poetry-core>=1.0.0"]
requires = ["poetry-core>=1.0.8"]
build-backend = "poetry.core.masonry.api"

View File

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

View File

@ -2,3 +2,7 @@
from .main import app
app(prog_name="bookbuild")
#if __name__ == "__main__":
# app()

View File

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

View File

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

View File

@ -1,4 +1,3 @@
from logging import Logger
from pathlib import Path
from typing import Annotated

19
src/bookbuild/version.py Normal file
View File

@ -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__}")