1
1
import csv
2
+ import io
2
3
import re
3
4
import tarfile
4
5
from dataclasses import dataclass
8
9
import requests
9
10
10
11
11
- REPO_URL = "https://github.com/conda-forge/cfep"
12
- REPO_ARCHIVE = "https://github.com/conda-forge/cfep/archive/main.tar.gz"
13
- REPO_CONTENTS = "https://api.github.com/repos/conda-forge/cfep/contents/"
14
- TITLE_PATTERN = "<td>\s*Title\s*</td><td>\s*(.*)\s*</td>"
15
- STATUS_PATTERN = "<td>\s*Status\s*</td><td>\s*(.*)\s*</td>"
12
+ CFEP_REPO_URL = "https://github.com/conda-forge/cfep"
13
+ CFEP_REPO_ARCHIVE = "https://github.com/conda-forge/cfep/archive/main.tar.gz"
14
+ CFEP_REPO_CONTENTS = "https://api.github.com/repos/conda-forge/cfep/contents/"
15
+ GOVERNANCE_REPO_URL = "https://github.com/conda-forge/governance"
16
+ TITLE_PATTERN = r"<td>\s*Title\s*</td><td>\s*(.*)\s*</td>"
17
+ STATUS_PATTERN = r"<td>\s*Status\s*</td><td>\s*(.*)\s*</td>"
16
18
REPO_DIR = Path (__file__ ).parents [1 ].absolute ()
17
19
CFEP_INDEX_MD_TMPL = REPO_DIR / "community" / "cfep-index.md.tmpl"
18
20
CFEP_INDEX_MD = REPO_DIR / "community" / "cfep-index.md"
19
21
GOVERNANCE_MD_TMPL = REPO_DIR / "community" / "governance.md.tmpl"
20
22
GOVERNANCE_MD = REPO_DIR / "community" / "governance.md"
21
- CORE_CSV = REPO_DIR / "src " / "core.csv "
22
- EMERITUS_CSV = REPO_DIR / "src " / "emeritus.csv "
23
+ CODE_OF_CONDUCT_MD_TMPL = REPO_DIR / "community " / "code-of-conduct.md.tmpl "
24
+ CODE_OF_CONDUCT_MD = REPO_DIR / "community " / "code-of-conduct.md "
23
25
24
26
25
27
@dataclass
@@ -46,7 +48,7 @@ def md_link(self) -> str:
46
48
def get_cfeps_from_gh_api ():
47
49
"""Generator that returns all CFEPs from GitHub repo"""
48
50
response = requests .get (
49
- REPO_CONTENTS , headers = {"Accept" : "application/vnd.github.v3+json" }
51
+ CFEP_REPO_CONTENTS , headers = {"Accept" : "application/vnd.github.v3+json" }
50
52
)
51
53
response .raise_for_status ()
52
54
for content in response .json ():
@@ -70,7 +72,7 @@ def get_cfeps_from_gh_api():
70
72
71
73
def get_cfeps ():
72
74
"""Return a generator of CFEPs, by traversing the contents of the repo archive"""
73
- r = requests .get (REPO_ARCHIVE , stream = True )
75
+ r = requests .get (CFEP_REPO_ARCHIVE , stream = True )
74
76
r .raise_for_status ()
75
77
with TemporaryDirectory () as tmp :
76
78
# Write the tarball to a temporary directory
@@ -86,7 +88,7 @@ def get_cfeps():
86
88
# Traverse the extracted directory and return all CFEPs
87
89
for cfep in sorted (extracted_dir .rglob ("cfep-*.md" )):
88
90
name = cfep .name
89
- url = f"{ REPO_URL } /blob/main/{ name } "
91
+ url = f"{ CFEP_REPO_URL } /blob/main/{ name } "
90
92
if name == "cfep-00.md" :
91
93
# Hardcode title and status for CFEP-00
92
94
yield Cfep (name , "CFEP Template" , "Proposed" , url )
@@ -106,26 +108,43 @@ def write_cfep_index():
106
108
CFEP_INDEX_MD .write_text (contents )
107
109
108
110
109
- def _get_formatted_names (path_file ):
110
- with open ( path_file , "r" ) as csv_file :
111
- dict_csv = csv .DictReader (csv_file )
112
- sorted_csv = sorted (dict_csv , key = lambda d : d ["name" ])
111
+ def _get_formatted_names (csv_contents ):
112
+ memfile = io . StringIO ( csv_contents )
113
+ dict_csv = csv .DictReader (memfile )
114
+ sorted_csv = sorted (dict_csv , key = lambda d : d ["name" ])
113
115
return "\n " .join (
114
116
f"- [{ m ['name' ]} @{ m ['github_username' ]} ]"
115
117
f"(https://github.com/{ m ['github_username' ]} )"
116
118
for m in sorted_csv
117
119
)
118
120
119
121
120
- def write_core_members ():
122
+ def write_code_of_conduct ():
123
+ r = requests .get (f"{ GOVERNANCE_REPO_URL } /raw/main/CODE_OF_CONDUCT.md" )
124
+ r .raise_for_status ()
125
+ contents = CODE_OF_CONDUCT_MD_TMPL .read_text ()
126
+ contents += r .text
127
+ CODE_OF_CONDUCT_MD .write_text (contents )
128
+
129
+
130
+ def write_governance ():
131
+ readme = requests .get (f"{ GOVERNANCE_REPO_URL } /raw/main/README.md" )
132
+ readme .raise_for_status ()
133
+ core = requests .get (f"{ GOVERNANCE_REPO_URL } /raw/main/teams/core.csv" )
134
+ core .raise_for_status ()
135
+ emeritus = requests .get (f"{ GOVERNANCE_REPO_URL } /raw/main/teams/emeritus.csv" )
136
+ emeritus .raise_for_status ()
121
137
contents = GOVERNANCE_MD_TMPL .read_text ()
122
- contents = contents .replace ("{{ core_members }}" , _get_formatted_names (CORE_CSV ))
138
+ contents += readme .text
139
+ contents = contents .replace ("{{ core_members }}" , _get_formatted_names (core .text ))
123
140
contents = contents .replace (
124
- "{{ emeritus_members }}" , _get_formatted_names (EMERITUS_CSV )
141
+ "{{ emeritus_members }}" , _get_formatted_names (emeritus . text )
125
142
)
143
+ contents = contents .replace ("(./CODE_OF_CONDUCT.md)" , "(./code-of-conduct.md)" )
126
144
GOVERNANCE_MD .write_text (contents )
127
145
128
146
129
147
if __name__ == "__main__" :
130
148
write_cfep_index ()
131
- write_core_members ()
149
+ write_governance ()
150
+ write_code_of_conduct ()
0 commit comments