8000 Generate the release cycle chart directly as SVG by encukou · Pull Request #1034 · python/devguide · GitHub
[go: up one dir, main page]

Skip to content

Generate the release cycle chart directly as SVG #1034

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

Merged
merged 20 commits into from
Feb 1, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Apply suggestions from code review
Co-authored-by: C.A.M. Gerlach <CAM.Gerlach@Gerlach.CAM>
  • Loading branch information
hugovk and CAM-Gerlach authored Jan 22, 2023
commit ae1184ee88855b79adb735fea005949891ca52cb
1 change: 1 addition & 0 deletions .github/workflows/release-cycle.yml
10000
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ jobs:
with:
python-version: "3"
cache: pip
cache-dependency-path: .github/workflows/release-cycle.yml

- name: Install Jinja
run: python -m pip install jinja2
Expand Down
17 changes: 10 additions & 7 deletions _tools/generate_release_cycle.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Read in a JSON and generate two CSVs and a SVG file."""
"""Read in a JSON and generate two CSVs and an SVG file."""
from __future__ import annotations

import csv
Expand Down Expand Up @@ -69,6 +69,8 @@ def write_svg(self) -> None:
env = jinja2.Environment(
loader=jinja2.FileSystemLoader('_tools/'),
autoescape=True,
lstrip_blocks=True,
trim_blocks=True,
undefined=jinja2.StrictUndefined,
)
template = env.get_template("release_cycle_template.svg")
Expand All @@ -87,7 +89,7 @@ def write_svg(self) -> None:
RIGHT_MARGIN = 0.5

# Height of one line. If you change this you'll need to tweak
# some positioning nombers in the template as well.
# some positioning numbers in the template as well.
LINE_HEIGHT = 1.5

first_date = min(
Expand All @@ -98,23 +100,24 @@ def write_svg(self) -> None:
)

def date_to_x(date):
"""Convert datetime.date to a SVG X coordinate"""
def date_to_x(date: dt.date) -> float:
"""Convert datetime.date to an SVG X coordinate"""
num_days = (date - first_date).days
total_days = (last_date - first_date).days
ratio = num_days / total_days
x = ratio * (DIAGRAM_WIDTH - LEGEND_WIDTH - RIGHT_MARGIN)
return x + LEGEND_WIDTH

def year_to_x(year):
"""Convert year number to a SVG X coordinate of 1st January"""
def year_to_x(year: int) -> float:
"""Convert year number to an SVG X coordinate of 1st January"""
return date_to_x(dt.date(year, 1, 1))

def format_year(year):
def format_year(year: int) -> str:
"""Format year number for display"""
return f"'{year % 100:02}"

with open(
"include/release-cycle.svg", "w", encoding="UTF-8",
"include/release-cycle.svg", "w", encoding="UTF-8", newline="\n"
) as f:
template.stream(
SCALE=SCALE,
Expand Down
0