1
- """Read in a JSON and generate two CSVs and a SVG file."""
1
+ """Read in a JSON and generate two CSVs and an SVG file."""
2
2
from __future__ import annotations
3
3
4
4
import csv
@@ -69,6 +69,8 @@ def write_svg(self) -> None:
69
69
env = jinja2 .Environment (
70
70
loader = jinja2 .FileSystemLoader ('_tools/' ),
71
71
autoescape = True ,
72
+ lstrip_blocks = True ,
73
+ trim_blocks = True ,
72
74
undefined = jinja2 .StrictUndefined ,
73
75
)
74
76
template = env .get_template ("release_cycle_template.svg" )
@@ -87,7 +89,7 @@ def write_svg(self) -> None:
87
89
RIGHT_MARGIN = 0.5
88
90
89
91
# Height of one line. If you change this you'll need to tweak
90
- # some positioning nombers in the template as well.
92
+ # some positioning numbers in the template as well.
91
93
LINE_HEIGHT = 1.5
92
94
93
95
first_date = min (
@@ -98,23 +100,24 @@ def write_svg(self) -> None:
98
100
)
99
101
100
102
def date_to_x (date ):
101
- """Convert datetime.date to a SVG X coordinate"""
103
+ def date_to_x (date : dt .date ) -> float :
104
+ """Convert datetime.date to an SVG X coordinate"""
102
105
num_days = (date - first_date ).days
103
106
total_days = (last_date - first_date ).days
104
107
ratio = num_days / total_days
105
108
x = ratio * (DIAGRAM_WIDTH - LEGEND_WIDTH - RIGHT_MARGIN )
106
109
return x + LEGEND_WIDTH
107
110
108
- def year_to_x (year ) :
109
- """Convert year number to a SVG X coordinate of 1st January"""
111
+ def year_to_x (year : int ) -> float :
112
+ """Convert year number to an SVG X coordinate of 1st January"""
110
113
return date_to_x (dt .date (year , 1 , 1 ))
111
114
112
- def format_year (year ) :
115
+ def format_year (year : int ) -> str :
113
116
"""Format year number for display"""
114
117
return f"'{ year % 100 :02} "
115
118
116
119
with open (
117
- "include/release-cycle.svg" , "w" , encoding = "UTF-8" ,
120
+ "include/release-cycle.svg" , "w" , encoding = "UTF-8" , newline = " \n "
118
121
) as f :
119
122
template .stream (
120
123
SCALE = SCALE ,
0 commit comments