Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 80 additions & 6 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
name: Docker
name: Deploy Docker image

on:
push:
branches: [ "master" ]
workflow_run:
workflows: ["Python package"]
branches: ["master"]
types:
- completed

workflow_dispatch:

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
VERSION: latest

jobs:
build_publish:
build:
name: Build Docker image
runs-on: ubuntu-latest
permissions:
contents: read
Expand All @@ -29,7 +36,7 @@ jobs:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login against Container registry
- name: Login to container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
Expand All @@ -42,11 +49,78 @@ jobs:
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

- name: Build and push Docker image
- name: Build Docker image
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
platforms: linux/amd64, linux/arm64

test:
name: Test Docker image
needs: build
runs-on: ubuntu-latest
permissions:
contents: read
packages: read
strategy:
matrix:
build-command: ["", "--fancy --tex-template --feats-by-type --spells-by-level", "--output-format=epub"]

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Login to container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

- name: Run Tests
run: |
docker run -v ${{ github.workspace }}/examples:/build ${{ steps.meta.outputs.tags }} ${{ matrix.build-command }}

push:
name: Deploy Docker image
needs: [build, test]
if: ${{ github.ref == 'refs/heads/master' }}
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:

- name: Login to container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

- name: Pull Docker image from GHCR
run: docker pull ${{ steps.meta.outputs.tags }}

- name: Lowercase reponame
run: echo "IMAGE_NAME_LC=${GITHUB_REPOSITORY@L}" >> "${GITHUB_ENV}"

- name: Tag and push Docker image to GHCR (final)
run: |
docker tag ${{ steps.meta.outputs.tags }} ${{ env.REGISTRY }}/${{ env.IMAGE_NAME_LC }}:${{ env.VERSION }}
docker push ${{ steps.meta.outputs.tags }}
docker push ${{ env.REGISTRY }}/${{ env.IMAGE_NAME_LC }}:${{ env.VERSION }}
43 changes: 0 additions & 43 deletions .github/workflows/python-ci.yml

This file was deleted.

84 changes: 84 additions & 0 deletions .github/workflows/python_ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
name: Python package

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
build:
name: "Run test suite"
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest]
python-version: ['3.9', '3.10', '3.11']

steps:
- uses: actions/checkout@v4
with:
submodules: recursive

- name: Set up required system dependencies
run: |
sudo apt-get update
sudo apt-get -y install pdftk texlive-latex-base texlive-latex-extra texlive-fonts-recommended texlive-fonts-extra texlive-luatex texlive-pstricks

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: pip

- name: Install dependencies and do a local pip install
run: |
python -m pip install --upgrade pip
pip install -e ".[dev]"

- name: Run flake
run: flake8 dungeonsheets/ --exit-zero

- name: Run tests
run: pytest --cov=dungeonsheets tests/

render_examples:
name: "Test python-3.12, render all examples"
runs-on: ubuntu-latest
needs: [build]
strategy:
matrix:
build-command: ["", "--fancy --tex-template --spells-by-level --feats-by-type", "--output-format=epub"]

steps:
- uses: actions/checkout@v4
name: Checkout Repo
with:
submodules: recursive

- name: Set up required system dependencies
run: |
sudo apt-get update
sudo apt-get -y install pdftk texlive-latex-base texlive-latex-extra texlive-fonts-recommended texlive-fonts-extra texlive-luatex texlive-pstricks

- name: Set up Python 3.12
uses: actions/setup-python@v5
with:
python-version: 3.12
cache: pip

- name: Install dependencies and do a local pip install
run: |
python -m pip install --upgrade pip
pip install -e ".[dev]"

- name: Run flake
run: flake8 dungeonsheets/ --exit-zero

- name: Run tests
run: pytest --cov=dungeonsheets tests/

- name: Render examples with ${{ matrix.build-command }}
run: |
cd examples
makesheets --debug ${{ matrix.build-command }}
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[submodule "dungeonsheets/modules/DND-5e-LaTeX-Template"]
path = dungeonsheets/modules/DND-5e-LaTeX-Template
url = https://github.com/rpgtex/DND-5e-LaTeX-Template.git
[submodule "dungeonsheets/modules/DND-5e-LaTeX-Character-Sheet-Template"]
path = dungeonsheets/modules/DND-5e-LaTeX-Character-Sheet-Template
url = https://github.com/matsavage/DND-5e-LaTeX-Character-Sheet-Template
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM python:latest

RUN apt-get update && apt-get install -y pdftk texlive-latex-base texlive-latex-extra texlive-fonts-recommended texlive-fonts-extra
RUN apt-get update && apt-get install -y pdftk texlive-latex-base texlive-latex-extra texlive-fonts-recommended texlive-fonts-extra texlive-luatex texlive-pstricks

WORKDIR /app

Expand Down
13 changes: 11 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Run the following in a directory with valid character files (such as the example

.. code:: bash

$ docker run -it -v $(pwd):/build ghcr.io/canismarko/dungeon-sheets:master
$ docker run -it -v $(pwd):/build ghcr.io/canismarko/dungeon-sheets:latest


Installation
Expand Down Expand Up @@ -109,7 +109,16 @@ so attack bonuses and damage can be calculated automatically.

Consider using the ``-F`` option to include the excellent D&D 5e
template for rendering spellbooks, druid wild forms and features
pages (https://github.com/rpgtex/DND-5e-LaTeX-Template).
pages (https://github.com/rpgtex/DND-5e-LaTeX-Template). dungeon-
sheets includes its own version of the template, but will use a
local one if it is installed.

Consider using the ``-T`` option to use the beautiful latex character
sheet
(https://github.com/matsavage/DND-5e-LaTeX-Character-Sheet-Template).
This does require lualatex as well as a fairly recent version of
texlive. dungeon-sheets includes its own version of the latex character
template, but will use a local one if it is installed.

By default, your character's spells are ordered alphabetically. If you
would like your spellbook to be ordered by level, you can use the ``-S``
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
\usepackage{ifthen}
\usepackage{pstricks}

\usepackage[UKenglish]{babel}

\usepackage{dndtemplate}
\usepackage{bookmark}

Expand Down
39 changes: 33 additions & 6 deletions dungeonsheets/latex.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import re
import subprocess
import logging
import warnings

from docutils import core
from docutils.writers.latex2e import Writer, Table, LaTeXTranslator
Expand Down Expand Up @@ -50,7 +51,8 @@ def create_latex_pdf(
basename: str,
keep_temp_files: bool = False,
use_dnd_decorations: bool = False,
comm1: str = "pdflatex"
use_tex_template: bool = False,
comm1: str = "pdflatex",
):
# Create tex document
tex_file = f"{basename}.tex"
Expand All @@ -69,14 +71,39 @@ def create_latex_pdf(
str(tex_file),
]

environment = os.environ
# Deal with TEXINPUTS and add paths to latex modules
environment = os.environ.copy()
tex_env = environment.get('TEXINPUTS', '')
module_root = Path(__file__).parent / "modules/"
module_dirs = [module_root / mdir for mdir in ["DND-5e-LaTeX-Template"]]
module_dirs = []

# Load locally installed latex packages if they exist, to allow for
# local latex customisation
for module in ["dnd.sty", "dndtemplate.sty"]:
kpsewhich_command = [
"kpsewhich",
module,
]
try:
module_check = subprocess.run(kpsewhich_command, capture_output=True, env=environment, text=True)
if module in module_check.stdout:
module_dirs.append(Path(module_check.stdout).parent)
except FileNotFoundError:
msg = ('Could not run kpsewhich. Something seems strange with your latex installation.')
warnings.warn(msg)

module_dirs.extend(
[module_root / mdir for mdir in ["DND-5e-LaTeX-Template", "DND-5e-LaTeX-Character-Sheet-Template"]]
)
log.debug(f"Loading additional modules from {module_dirs}.")
texinputs = ['.', *module_dirs, module_root, tex_env]
separator = ';' if isinstance(module_root, pathlib.WindowsPath) else ':'
# Two (back-)slashes at the end of each path to recursively add all subdirectories
separator = '\\\\;' if isinstance(module_root, pathlib.WindowsPath) else '//:'
environment['TEXINPUTS'] = separator.join(str(path) for path in texinputs)
if use_tex_template:
environment['TTFONTS'] = environment['TEXINPUTS']

# Prepare the latex subprocess
passes = 2 if use_dnd_decorations else 1
log.debug(tex_command_line)
log.debug("LaTeX command: %s" % " ".join(tex_command_line))
Expand Down Expand Up @@ -264,8 +291,8 @@ def rst_to_boxlatex(rst):
return tex


def msavage_spell_info(char):
"""Generates the spellsheet for msavage template."""
def latex_character_spell_info(char):
"""Generates the spellsheet for the latex character template."""
headinfo = char.spell_casting_info["head"]
font_options = {1:"", 2:r"\Large ", 3:r"\large "}
selector = min(len(char.spellcasting_classes), 3)
Expand Down
Loading