2
2
# Copyright (c) Jupyter Development Team.
3
3
# Distributed under the terms of the Modified BSD License.
4
4
import argparse
5
+ import datetime
5
6
import logging
6
7
import shutil
7
8
from pathlib import Path
8
9
9
- LOGGER = logging .getLogger (__name__ )
10
+ import plumbum
11
+ from dateutil import relativedelta
10
12
13
+ git = plumbum .local ["git" ]
11
14
12
- def regenerate_home_wiki_page (wiki_dir : Path ) -> None :
13
- YEAR_MONTHLY_TABLES = "<!-- YEAR_MONTHLY_TABLES -->\n "
15
+ LOGGER = logging .getLogger (__name__ )
14
16
15
- YEAR_TABLE_HEADER = """\
17
+ YEAR_TABLE_HEADER = """\
16
18
## {year}
17
19
18
- | Month | Builds | Images |
19
- | ---------------------- | ------ | ------ |
20
+ | Month | Builds | Images | Commits |
21
+ | ---------------------- | ------ | ------ | ------- |
20
22
"""
21
23
24
+
25
+ def build_monthly_table_line (year_month_file : Path ) -> str :
26
+ year_month_file_content = year_month_file .read_text ()
27
+ images = year_month_file_content .count ("Build manifest" )
28
+ builds = sum (
29
+ "jupyter/base-notebook" in line and "aarch64" not in line
30
+ for line in year_month_file_content .split ("\n " )
31
+ )
32
+ year_month = year_month_file .stem
33
+ current_month = datetime .date (
34
+ year = int (year_month [:4 ]), month = int (year_month [5 :]), day = 1
35
+ )
36
+ next_month = current_month + relativedelta .relativedelta (months = 1 )
37
+ future = (
38
+ git ["log" , "--oneline" , "--since" , current_month , "--until" , next_month ]
39
+ & plumbum .BG
40
+ )
41
+ future .wait ()
42
+ commits = len (future .stdout .splitlines ())
43
+
44
+ return f"| [`{ year_month } `](./{ year_month } ) | { builds : <6} | { images : <6} | { commits : <7} |\n "
45
+
46
+
47
+ def regenerate_home_wiki_page (wiki_dir : Path ) -> None :
48
+ YEAR_MONTHLY_TABLES = "<!-- YEAR_MONTHLY_TABLES -->\n "
49
+
22
50
wiki_home_file = wiki_dir / "Home.md"
23
51
wiki_home_content = wiki_home_file .read_text ()
24
52
@@ -27,22 +55,10 @@ def regenerate_home_wiki_page(wiki_dir: Path) -> None:
27
55
: wiki_home_content .find (YEAR_MONTHLY_TABLES ) + len (YEAR_MONTHLY_TABLES )
28
56
]
29
57
30
- all_year_dirs = sorted ((wiki_dir / "monthly-files" ).glob ("*" ), reverse = True )
31
- for year_dir in all_year_dirs :
58
+ for year_dir in sorted ((wiki_dir / "monthly-files" ).glob ("*" ), reverse = True ):
32
59
wiki_home_content += "\n " + YEAR_TABLE_HEADER .format (year = year_dir .name )
33
-
34
- all_year_month_files = sorted (year_dir .glob ("*.md" ), reverse = True )
35
- for year_month_file in all_year_month_files :
36
- year_month_file_content = year_month_file .read_text ()
37
- images = year_month_file_content .count ("Build manifest" )
38
- builds = sum (
39
- "jupyter/base-notebook" in line and "aarch64" not in line
40
- for line in year_month_file_content .split ("\n " )
41
- )
42
- year_month = year_month_file .stem
43
- wiki_home_content += (
44
- f"| [`{ year_month } `](./{ year_month } ) | { builds : <6} | { images : <6} |\n "
45
- )
60
+ for year_month_file in sorted (year_dir .glob ("*.md" ), reverse = True ):
61
+ wiki_home_content += build_monthly_table_line (year_month_file )
46
62
47
63
wiki_home_file .write_text (wiki_home_content )
48
64
LOGGER .info ("Updated Home page" )
0 commit comments