Skip to content
Merged

Dev #46

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
32 changes: 32 additions & 0 deletions .github/workflows/doc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Documentation
on:
push:
branches:
- main
permissions:
contents: write
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: actions/setup-python@v6
with:
python-version: 3.x

- name: Install uv
uses: astral-sh/setup-uv@v5
with:
enable-cache: true

- name: Install the project
run: uv sync --all-groups

- run: uv run zensical build --clean

- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v4
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_branch: gh-pages
publish_dir: ./site
49 changes: 0 additions & 49 deletions .github/workflows/site.yaml

This file was deleted.

10 changes: 7 additions & 3 deletions .github/workflows/type.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
name: Check Static Typing

on:
push:
branches: [main]
pull_request:
branches:
- main
branches: [main]

jobs:
check-formatting:
Expand All @@ -21,5 +22,8 @@ jobs:
- name: Install the project
run: uv sync --all-groups

- name: Run tests
- name: ty
run: uv run ty check

- name: pyrefly
run: uv run pyrefly check
2 changes: 1 addition & 1 deletion .github/workflows/unit-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:

strategy:
matrix:
python-version: [3.9, 3.13]
python-version: [3.9, 3.14]

steps:
- name: Checkout code
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,5 @@ uv.lock
*.zip

release.sh

site
20 changes: 0 additions & 20 deletions .pre-commit-config.yaml

This file was deleted.

1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ A simple-to-use Python library to build **calendar heatmaps** with ease.
It's built on top of **matplotlib** and leverages it to access high customization possibilities.

[![PyPI Downloads](https://static.pepy.tech/badge/dayplot)](https://pepy.tech/projects/dayplot)
![Coverage](coverage-badge.svg)

<br>

Expand Down
67 changes: 67 additions & 0 deletions dayplot/_docs_matplotlib.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import base64
import tempfile
from typing import Any

import matplotlib
from bs4 import BeautifulSoup, Tag
from markdown import Markdown
from markdown.extensions import Extension
from markdown.postprocessors import Postprocessor
from mkdocs_matplotlib.plugin import (
HIDECODE_SWITCH,
HIDEOUTPUT_SWITCH,
RENDER_SWITCH,
_rendered_image_to_dir,
)


class MatplotlibRenderPostprocessor(Postprocessor):
def run(self, text: str) -> str:
soup = BeautifulSoup(text, features="html.parser")
global_namespace: dict[str, Any] = {}
local_namespace: dict[str, Any] = {}

for code_tag in soup.find_all("code"):
parent_code_tag = code_tag.parent
if not isinstance(parent_code_tag, Tag) or parent_code_tag.name != "pre":
continue

raw_code = code_tag.text
code_lines = raw_code.splitlines()
if RENDER_SWITCH not in code_lines:
continue

is_hidecode = HIDECODE_SWITCH in code_lines
is_hideoutput = HIDEOUTPUT_SWITCH in code_lines

matplotlib.use("Agg", force=True)
temp_file = tempfile.NamedTemporaryFile(suffix=".svg").name
is_empty = _rendered_image_to_dir(
temp_file, raw_code, global_namespace, local_namespace
)

if not is_hideoutput and not is_empty:
with open(temp_file, "rb") as file:
encoded = base64.b64encode(file.read()).decode("ascii")
img_tag = soup.new_tag(
"img",
src="data:image/svg+xml;base64," + encoded,
)
parent_code_tag.insert_after(img_tag)
img_tag.wrap(soup.new_tag("center"))

if is_hidecode:
parent_code_tag.decompose()

return str(soup)


class MatplotlibRenderExtension(Extension):
def extendMarkdown(self, md: Markdown) -> None:
md.postprocessors.register(
MatplotlibRenderPostprocessor(md), "matplotlib_render", 5
)


def makeExtension(**kwargs: Any) -> MatplotlibRenderExtension:
return MatplotlibRenderExtension(**kwargs)
Loading
Loading