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
This commit is contained in:
parent
671cca0b51
commit
99161c82d2
32
README.md
32
README.md
@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
Im lokalen `bookbuild`-Repository (Development):
|
Im lokalen `bookbuild`-Repository (Development) **fkt. nicht: der Befehl installiert nur die dependencies, nicht bookbuild selbst**:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ poetry build
|
$ poetry build
|
||||||
@ -30,3 +30,33 @@ Systemweit (fkt. noch nicht):
|
|||||||
$ pip install -e git+https://git.unterdemradar.de/tobias/bookbuild#egg=bookbuild
|
$ 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
2
poetry.lock
generated
@ -131,7 +131,7 @@ python-versions = ">=3.9"
|
|||||||
[metadata]
|
[metadata]
|
||||||
lock-version = "1.1"
|
lock-version = "1.1"
|
||||||
python-versions = "^3.10"
|
python-versions = "^3.10"
|
||||||
content-hash = "6fbf8536c3d7c8fe08a1342d50c3fee906261965039e443c8b323a381ceb9b4c"
|
content-hash = "58dd26373197ceffe88b78af71c4a7316fa3d383b8ab14180fb85b5af1ecbdef"
|
||||||
|
|
||||||
[metadata.files]
|
[metadata.files]
|
||||||
click = []
|
click = []
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
[tool.poetry]
|
[tool.poetry]
|
||||||
name = "bookbuild"
|
name = "bookbuild"
|
||||||
description = "Build script for my book projects"
|
description = "Build script for my book projects"
|
||||||
version = "0.2.0"
|
version = "0.2.1"
|
||||||
license = "GPL-3.0-or-later"
|
license = "GPL-3.0-or-later"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
authors = ["Tobias Radloff <mail@tobias-radloff.de>"]
|
authors = ["Tobias Radloff <mail@tobias-radloff.de>"]
|
||||||
|
|||||||
@ -0,0 +1 @@
|
|||||||
|
__version__ = "0.2.1"
|
||||||
@ -2,3 +2,7 @@
|
|||||||
|
|
||||||
from .main import app
|
from .main import app
|
||||||
app(prog_name="bookbuild")
|
app(prog_name="bookbuild")
|
||||||
|
|
||||||
|
#if __name__ == "__main__":
|
||||||
|
# app()
|
||||||
|
|
||||||
|
|||||||
@ -66,7 +66,7 @@ def add_presuffix(path: Path|str, presuffix: str) -> Path:
|
|||||||
return path.parent / f"{path.stem}{presuffix}{path.suffix}"
|
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:
|
with open(input_file, "r") as file:
|
||||||
data = yaml.load(file, Loader=yaml.Loader)
|
data = yaml.load(file, Loader=yaml.Loader)
|
||||||
return data.get(key)
|
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:
|
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)
|
exe = which(cmd)
|
||||||
if not exe:
|
if not exe:
|
||||||
@ -93,24 +93,26 @@ def get_input_files(target_format: str) -> list:
|
|||||||
if list_file.is_file():
|
if list_file.is_file():
|
||||||
with open(list_file, "r") as file:
|
with open(list_file, "r") as file:
|
||||||
return [line.strip() for line in file if line[0] != "#"]
|
return [line.strip() for line in file if line[0] != "#"]
|
||||||
# use all files otherwise; ignore tredition flag
|
# use all files otherwise
|
||||||
else:
|
else:
|
||||||
paths = CONTENT_DIR.glob('**/*.md')
|
paths = CONTENT_DIR.glob('**/*.md')
|
||||||
return list(map(str, sorted(paths)))
|
return list(map(str, sorted(paths)))
|
||||||
|
|
||||||
|
|
||||||
def merge_pdf_with_covers(frontcover: str, content: str, backcover: str, keep_coverless: bool=False):
|
def merge_pdf_with_covers(frontcover: str, content: str, backcover: str, keep_coverless: bool=False):
|
||||||
pdflist = []
|
# pdflist = []
|
||||||
|
#
|
||||||
# check if files exist
|
# # check if files exist
|
||||||
for filename in [frontcover, content, backcover]:
|
# for filename in [frontcover, content, backcover]:
|
||||||
if Path(filename).is_file():
|
# if Path(filename).is_file():
|
||||||
pdflist.append(filename)
|
# pdflist.append(filename)
|
||||||
|
|
||||||
# merge files wwith pypdf
|
# merge files wwith pypdf
|
||||||
|
LOGGER.debug("merge_pdf_with_covers() with new code stuff")
|
||||||
merger = PdfWriter()
|
merger = PdfWriter()
|
||||||
for pdf in pdflist:
|
for pdf in [frontcover, content, backcover]:
|
||||||
merger.append(pdf)
|
if pdf and Path(pdf).is_file():
|
||||||
|
merger.append(pdf)
|
||||||
|
|
||||||
# write merged file
|
# write merged file
|
||||||
outfile = str(add_presuffix(content, ".with-covers")) if keep_coverless else content
|
outfile = str(add_presuffix(content, ".with-covers")) if keep_coverless else content
|
||||||
|
|||||||
@ -26,6 +26,8 @@ from .pdf import pdf_app
|
|||||||
app.add_typer(pdf_app)
|
app.add_typer(pdf_app)
|
||||||
from .all import all_app
|
from .all import all_app
|
||||||
app.add_typer(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
|
# Make CLI runnable from source tree with python src/package
|
||||||
if not __package__:
|
if not __package__:
|
||||||
|
|||||||
19
src/bookbuild/version.py
Normal file
19
src/bookbuild/version.py
Normal 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__}")
|
||||||
|
|
||||||
Loading…
Reference in New Issue
Block a user