Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/pip/coverage-7.6.7
Browse files Browse the repository at this point in the history
  • Loading branch information
ouhammmourachid authored Nov 25, 2024
2 parents d96a226 + 82b516c commit 8693c9c
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 7 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
21 changes: 21 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import os
import shutil


def pytest_configure(config):
"""
A pytest hook to customize the terminal summary.
"""
# Get the environment variable
mermaid_server = os.getenv("MERMAID_INK_SERVER", "Not Set")

mermaid_server = (
f"\033[92m{mermaid_server}\033[0m"
if mermaid_server != "Not Set"
else "\033[91mNot Set\033[0m"
)
# Print the environment variable at the start
word = " Custom Environment Information "
line = word.center(shutil.get_terminal_size(fallback=(80, 20))[0], "=")
print(f"\033[1m{line}\033[0m")
print(f"\033[92mMERMAID_INK_SERVER \033[0m: {mermaid_server}")
2 changes: 0 additions & 2 deletions tests/test_statediagram.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,6 @@ def test_concurrent_with_sub_goups(self):
\tfirst_state : First State
\t[*] --> first_state
}"""
print(expect_string)
print(concurrent)
self.assertEqual(expect_string, str(concurrent))

def test_concurrent_with_sub_goups_and_styles(self):
Expand Down

0 comments on commit 8693c9c

Please sign in to comment.