Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
10d5e95855 | ||
| 99161c82d2 | |||
| 671cca0b51 | |||
| 2be58297f9 |
60
README.md
60
README.md
@ -2,5 +2,61 @@
|
|||||||
|
|
||||||
## Dependencies
|
## Dependencies
|
||||||
|
|
||||||
python>=3.x
|
* python>=3.x
|
||||||
python-poetry>=1.1.0
|
* 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
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,22 +1,28 @@
|
|||||||
[tool.poetry]
|
[tool.poetry]
|
||||||
name = "bookbuild"
|
name = "bookbuild"
|
||||||
version = "0.2.0"
|
|
||||||
description = "Build script for my book projects"
|
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>"]
|
authors = ["Tobias Radloff <mail@tobias-radloff.de>"]
|
||||||
license = "GPLv3"
|
|
||||||
packages = [{ include = "bookbuild", from = "src" }]
|
packages = [{ include = "bookbuild", from = "src" }]
|
||||||
|
|
||||||
|
|
||||||
|
[tool.poetry.urls]
|
||||||
|
repository = "https://git.unterdemradar.de/tobias/bookbuild"
|
||||||
|
|
||||||
|
|
||||||
[tool.poetry.dependencies]
|
[tool.poetry.dependencies]
|
||||||
python = "^3.10"
|
python = "^3.10"
|
||||||
pypdf = "^6.1.2"
|
pypdf = "^6.1.2"
|
||||||
PyYAML = "^6.0.3"
|
PyYAML = "^6.0.3"
|
||||||
typer = "^0.19.2"
|
typer = "^0.19.2"
|
||||||
|
|
||||||
[tool.poetry.dev-dependencies]
|
|
||||||
|
|
||||||
[tool.poetry.scripts]
|
[tool.poetry.scripts]
|
||||||
bookbuild = 'bookbuild.main:app'
|
bookbuild = 'bookbuild.main:app'
|
||||||
|
|
||||||
|
|
||||||
[build-system]
|
[build-system]
|
||||||
requires = ["poetry-core>=1.0.0"]
|
requires = ["poetry-core>=1.0.8"]
|
||||||
build-backend = "poetry.core.masonry.api"
|
build-backend = "poetry.core.masonry.api"
|
||||||
|
|||||||
@ -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__:
|
||||||
|
|||||||
@ -1,4 +1,3 @@
|
|||||||
from logging import Logger
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Annotated
|
from typing import Annotated
|
||||||
|
|
||||||
|
|||||||
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