Skip to content

Commit

Permalink
Merge branch 'main' into pre-commit-ci-update-config
Browse files Browse the repository at this point in the history
  • Loading branch information
ouhammmourachid authored Nov 25, 2024
2 parents 2bbcf6e + e697306 commit ea3114a
Show file tree
Hide file tree
Showing 7 changed files with 125 additions and 70 deletions.
22 changes: 19 additions & 3 deletions .github/workflows/make-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ on:

jobs:
lint:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Lint code
Expand All @@ -30,8 +28,26 @@ jobs:
with:
python-version: ${{ matrix.python-version }}

test-with-local-mermaid-server:
needs: lint
strategy:
matrix:
python-version: ["3.9", "3.10", "3.11", "3.12","3.13"]

runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: setup mermaid.ink server
run: docker run -p 3000:3000 -d --cap-add=SYS_ADMIN ghcr.io/jihchi/mermaid.ink
- name: Test on Python ${{ matrix.python-version }} with local mermaid server
uses: ./.github/actions/test
env:
MERMAID_INK_SERVER: http://localhost:3000
with:
python-version: ${{ matrix.python-version }}

codecov:
needs: test
needs: [test,test-with-local-mermaid-server]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand Down
11 changes: 11 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# variables
POETRY_RUN := poetry run
PRE_COMMIT_CMD := $(POETRY_RUN) pre-commit
MERMAID_INK_CONTAINER := ghcr.io/jihchi/mermaid.ink

.PHONY: install
install:
Expand Down Expand Up @@ -36,6 +37,14 @@ lint:
coverage:
$(POETRY_RUN) pytest --cov ./mermaid --cov-report=xml

.PHONY: mermaid.ink/up
mermaid.ink/up:
docker run -p 3000:3000 -d --cap-add=SYS_ADMIN $(MERMAID_INK_CONTAINER)

.PHONY: mermaid.ink/down
mermaid.ink/down:
docker stop $(shell docker ps -q --filter ancestor=$(MERMAID_INK_CONTAINER))

.PHONY: bumpversion
bumpversion:
$(eval name=$(filter-out $@,$(MAKECMDGOALS)))
Expand All @@ -60,3 +69,5 @@ help:
@echo " bumpversion bump version"
@echo " help show this help message"
@echo ""
@echo " mermaid.ink/up start mermaid.ink Local server"
@echo " mermaid.ink/down stop mermaid.ink local server"
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,11 @@ diagram
```
- more examples on [mermaid](https://www.kaggle.com/code/ouhammourachid/mermaid-py) and [test-mermaid](https://www.kaggle.com/code/ouhammourachid/testing-mermaid-py)

## Server

By default, the library uses the mermaid.ink service [github](https://github.com/jihchi/mermaid.ink) for generating diagrams. The service can be run locally using docker, following instructions [here](https://github.com/jihchi/mermaid.ink?tab=readme-ov-file#launch-a-container).

The `MERMAID_INK_SERVER` environment variable can be used to specify the server to use, for example.

## List of Diagrames
- [x] [~~FlowChart~~](https://mermaid.js.org/syntax/flowchart.html)
Expand All @@ -99,6 +103,7 @@ diagram
- [ ] [XYChart 🔥](https://mermaid.js.org/syntax/xyChart.html)
- [ ] [Block Diagram 🔥](https://mermaid.js.org/syntax/block.html)
- [ ] [Packet 🔥](https://mermaid.js.org/syntax/packet.html)
- [ ] [Kanban 🔥](https://mermaid.js.org/syntax/kanban.html)
- [ ] [Architecture 🔥](https://mermaid.js.org/syntax/architecture.html)

## License
Expand Down
8 changes: 6 additions & 2 deletions mermaid/__main__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import base64
import os
from enum import Enum
from pathlib import Path
from typing import Optional, Union
Expand Down Expand Up @@ -124,12 +125,15 @@ def _make_request_to_mermaid(self) -> None:
Make GET requests to the Mermaid SVG and IMG APIs using
the base64 encoded string of the Mermaid diagram script.
"""
mermaid_server_adress: str = os.getenv(
"MERMAID_INK_SERVER", "https://mermaid.ink"
)

self.svg_response: Response = requests.get(
"https://mermaid.ink/svg/" + self._diagram
mermaid_server_adress + "/svg/" + self._diagram
)
self.img_response: Response = requests.get(
"https://mermaid.ink/img/" + self._diagram
mermaid_server_adress + "/img/" + self._diagram
)

def to_svg(self, path: Union[str, Path]) -> None:
Expand Down
Loading

0 comments on commit ea3114a

Please sign in to comment.