Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(build): update github actions and build process to better utilize poetry #24

Merged
merged 1 commit into from
Feb 22, 2025
Merged
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
15 changes: 11 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

name: Continuous Integration

on:
Expand All @@ -12,12 +11,20 @@ jobs:
- uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: "3.x"

- name: Install pypa/build
- name: Install poetry
run: python3 -m pip install build poetry --user

- name: Install dependencies
run: poetry install --no-root

- name: Check formatting
run: |
poetry run ruff check .
poetry run black --check .

- name: Test the build
run: python3 -m build
run: poetry build
20 changes: 14 additions & 6 deletions .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,26 @@ jobs:
- uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: "3.x"

- name: Install pypa/build
- name: Install poetry
run: python3 -m pip install build poetry --user

- name: Build a binary wheel and a source tarball
run: python3 -m build
- name: Install dependencies
run: poetry install --no-root

- name: Check formatting
run: |
poetry run ruff check .
poetry run black --check .

- name: Build
run: poetry build

- name: Store the distribution packages
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: python-package-distributions
path: dist/
Expand Down Expand Up @@ -65,7 +73,7 @@ jobs:

steps:
- name: Download all the dists
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: python-package-distributions
path: dist/
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ ipython_config.py
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock
poetry.lock

# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
Expand Down
15 changes: 9 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,12 @@ document$.subscribe(({ body }) => {

## Contribution guide

1. Either use the devcontainer or setup a venv with mkdocs installed
2. Install your current local version: `pip install -e .`
3. Add a test for your changes in the `example` directory
4. Test your changes by starting `mkdocs serve` in the `example` directory
5. Increase the version `pyproject.toml`
6. Open pull request
1. Setup a virtual environment: `python3 -m venv venv && source venv/bin/activate`
2. Install poetry: `pip install poetry`
3. Install dependencies and current version: `poetry install`
4. Make your desired changes
5. Add a test for your changes in the `example` directory
6. Test your changes by starting `mkdocs serve` in the `example` directory
7. Increase the version in `pyproject.toml`
8. Make sure `poetry run ruff check .` and `poetry run black --check .` passing
9. Open your pull request ✨️
37 changes: 25 additions & 12 deletions mkdocs_drawio/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

LOGGER = logging.getLogger("mkdocs.plugins.diagrams")


# ------------------------
# Plugin
# ------------------------
Expand All @@ -28,10 +29,15 @@ class DrawioPlugin(BasePlugin):
"""

config_scheme = (
("viewer_js",mkdocs.config.config_options.Type(str, default="https://viewer.diagrams.net/js/viewer-static.min.js")),
("toolbar",mkdocs.config.config_options.Type(bool, default=True)),
("tooltips",mkdocs.config.config_options.Type(bool, default=True)),
("border",mkdocs.config.config_options.Type(int, default=0)),
(
"viewer_js",
mkdocs.config.config_options.Type(
str, default="https://viewer.diagrams.net/js/viewer-static.min.js"
),
),
("toolbar", mkdocs.config.config_options.Type(bool, default=True)),
("tooltips", mkdocs.config.config_options.Type(bool, default=True)),
("border", mkdocs.config.config_options.Type(int, default=0)),
("edit", mkdocs.config.config_options.Type(bool, default=True)),
)

Expand Down Expand Up @@ -66,7 +72,6 @@ def render_drawio_diagrams(self, output_content, page):
# substitute images with embedded drawio diagram
path = Path(page.file.abs_dest_path).parent


for diagram in diagrams:
if re.search("^https?://", diagram["src"]):
mxgraph = BeautifulSoup(
Expand All @@ -75,10 +80,12 @@ def render_drawio_diagrams(self, output_content, page):
)
else:
mxgraph = BeautifulSoup(
DrawioPlugin.substitute_with_file(diagram_config, path, diagram["src"], diagram["alt"]),
DrawioPlugin.substitute_with_file(
diagram_config, path, diagram["src"], diagram["alt"]
),
"html.parser",
)

diagram.replace_with(mxgraph)

return str(soup)
Expand All @@ -94,11 +101,13 @@ def substitute_with_file(config: Dict, path: Path, src: str, alt: str) -> str:
try:
diagram_xml = etree.parse(path.joinpath(src).resolve())
except Exception:
LOGGER.error(f"Error: Provided diagram file '{src}' on path '{path}' is not a valid diagram")
diagram_xml = etree.fromstring('<invalid/>')
LOGGER.error(
f"Error: Provided diagram file '{src}' on path '{path}' is not a valid diagram"
)
diagram_xml = etree.fromstring("<invalid/>")

diagram = DrawioPlugin.parse_diagram(diagram_xml, alt)
config["xml"]=diagram
config["xml"] = diagram

return SUB_TEMPLATE.substitute(config=escape(json.dumps(config)))

Expand All @@ -120,9 +129,13 @@ def parse_diagram(data, alt, src="", path=None) -> str:
result.append(page[0])
return etree.tostring(result, encoding=str)
else:
LOGGER.warning(f"Warning: Found {len(page)} results for page name '{alt}' for diagram '{src}' on path '{path}'")
LOGGER.warning(
f"Warning: Found {len(page)} results for page name '{alt}' for diagram '{src}' on path '{path}'"
)

return etree.tostring(mxfile, encoding=str)
except Exception:
LOGGER.error(f"Error: Could not properly parse page name '{alt}' for diagram '{src}' on path '{path}'")
LOGGER.error(
f"Error: Could not properly parse page name '{alt}' for diagram '{src}' on path '{path}'"
)
return ""
10 changes: 6 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,17 @@ packages = [
]

[tool.poetry.dependencies]
python = "^3.7.0"
requests = ">=2.0"
Jinja2 = ">=3.0"
python = ">=3.8.0,<4.0"
beautifulsoup4 = ">=4.0"
lxml = ">=4.0"
mkdocs = ">=1.3"

[tool.poetry.dev-dependencies]
[tool.poetry.group.dev.dependencies]
python = ">=3.8.0,<4.0"
black = ">=24.0"
ruff = "^0.9.2"
mkdocs-print-site-plugin = "^2.6.0"
mkdocs-material = "^9.5.50"

[build-system]
requires = ["poetry-core>=1.0.0"]
Expand Down