Skip to content

Commit

Permalink
Fix miscellaneous issues
Browse files Browse the repository at this point in the history
  • Loading branch information
hunyadi committed Sep 30, 2024
1 parent 4b18d85 commit 5518b11
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 13 deletions.
7 changes: 7 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
__pycache__
/.env
/.envrc
/.idea
/.mypy_cache
/.venv
/*.egg-info
7 changes: 4 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
__pycache__
/.env
/.envrc
/.idea
/.mypy_cache
/.venv
/dist
/*.egg-info
.envrc
.venv
.idea
10 changes: 5 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ FROM python:${PYTHON_VERSION}-alpine as builder

COPY ./ ./

RUN python3 -m pip install --upgrade pip && \
pip install build && \
python -m build --wheel
RUN PIP_DISABLE_PIP_VERSION_CHECK=1 python3 -m pip install --upgrade pip && \
pip install build
RUN python -m build --wheel

FROM python:${PYTHON_VERSION}-alpine as host

RUN apk add --update nodejs npm && \
npm install -g @mermaid-js/mermaid-cli
RUN apk add --update nodejs npm
RUN npm install -g @mermaid-js/mermaid-cli

FROM host as runner

Expand Down
5 changes: 3 additions & 2 deletions md2conf/mermaid.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,11 @@ def render(source: str, output_format: Literal["png", "svg"] = "png") -> bytes:
stderr=subprocess.PIPE,
text=False,
)
proc.communicate(input=source.encode("utf-8"))
stdout, stderr = proc.communicate(input=source.encode("utf-8"))
if proc.returncode:
raise RuntimeError(
f"failed to convert Mermaid diagram; exit code: {proc.returncode}"
f"failed to convert Mermaid diagram; exit code: {proc.returncode}, "
f"output:\n{stdout.decode('utf-8')}\n{stderr.decode('utf-8')}"
)
with open(filename, "rb") as image:
return image.read()
Expand Down
5 changes: 4 additions & 1 deletion package.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
set -e
#
# Builds a Python package and runs unit tests in Docker
#

PYTHON=python3

Expand All @@ -14,6 +17,6 @@ $PYTHON -m build
for PYTHON_VERSION in 3.8 3.9 3.10 3.11 3.12
do
docker build -f test.dockerfile -t py-$PYTHON_VERSION-image --build-arg PYTHON_VERSION=$PYTHON_VERSION .
docker run -it --env-file .env --rm py-$PYTHON_VERSION-image python3 -m unittest discover tests
docker run -i -t --env-file .env --rm py-$PYTHON_VERSION-image python3 -m unittest discover tests
docker rmi py-$PYTHON_VERSION-image
done
15 changes: 13 additions & 2 deletions test.dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
ARG PYTHON_VERSION=3.9
FROM python:${PYTHON_VERSION}-alpine
RUN PIP_DISABLE_PIP_VERSION_CHECK=1 python3 -m pip install --upgrade pip

FROM python:${PYTHON_VERSION}-alpine as host-alpine

RUN apk add --update nodejs npm
RUN npm install -g @mermaid-js/mermaid-cli

FROM python:${PYTHON_VERSION}-slim as host-slim

RUN apt-get update && apt-get install --yes --no-install-recommends nodejs npm
RUN npm install -g @mermaid-js/mermaid-cli

FROM host-slim as runner

COPY dist/*.whl dist/
RUN python3 -m pip install `ls -1 dist/*.whl`
COPY sample/ sample/
Expand Down

0 comments on commit 5518b11

Please sign in to comment.