Skip to content

Commit fb691fe

Browse files
committed
format code
1 parent c7d768f commit fb691fe

File tree

6 files changed

+181
-132
lines changed

6 files changed

+181
-132
lines changed

_extensions/gh_repo.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,12 @@
99

1010

1111
# https://docutils.readthedocs.io/en/sphinx-docs/howto/rst-roles.html
12-
def gh_repo(name, rawtext, text, lineno, inliner,
13-
options=None, content=None):
12+
def gh_repo(name, rawtext, text, lineno, inliner, options=None, content=None):
1413
url = f"https://github.com/{text}"
15-
node = nodes.reference(rawtext, f'{text}', refuri=url, **(options or {}))
14+
node = nodes.reference(rawtext, f"{text}", refuri=url, **(options or {}))
1615
return [node], []
1716

1817

1918
def setup(app):
20-
app.add_role('gh-repo', gh_repo)
21-
return {'version': '1.0', 'parallel_read_safe': True}
19+
app.add_role("gh-repo", gh_repo)
20+
return {"version": "1.0", "parallel_read_safe": True}

_extensions/slack.py

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,32 +13,46 @@
1313
import strictyaml as yaml
1414

1515

16-
BOARD_HISTORY_SCHEMA = yaml.Seq(yaml.Map({
17-
'from': yaml.Datetime(),
18-
'members': yaml.MapPattern(yaml.Str(), yaml.Str()),
19-
}))
20-
BOARD_HISTORY_PATH = Path(__file__).parent.parent / 'board.yml'
21-
BOARD_HISTORY = sorted(yaml.load(BOARD_HISTORY_PATH.read_text(),
22-
BOARD_HISTORY_SCHEMA).data,
23-
key=itemgetter('from'), reverse=True)
16+
BOARD_HISTORY_SCHEMA = yaml.Seq(
17+
yaml.Map(
18+
{
19+
"from": yaml.Datetime(),
20+
"members": yaml.MapPattern(yaml.Str(), yaml.Str()),
21+
}
22+
)
23+
)
24+
BOARD_HISTORY_PATH = Path(__file__).parent.parent / "board.yml"
25+
BOARD_HISTORY = sorted(
26+
yaml.load(BOARD_HISTORY_PATH.read_text(), BOARD_HISTORY_SCHEMA).data,
27+
key=itemgetter("from"),
28+
reverse=True,
29+
)
2430

2531

2632
# https://docutils.readthedocs.io/en/sphinx-docs/howto/rst-roles.html
27-
def slack(name, rawtext, text, lineno, inliner,
28-
options=None, content=None, pyvec_board_years=None):
29-
text = text.lstrip('#')
30-
31-
if pyvec_board_years and text.startswith('pyvec-board'):
32-
text = f'pyvec-board-{pyvec_board_years[0]}-{pyvec_board_years[1]}'
33+
def slack(
34+
name,
35+
rawtext,
36+
text,
37+
lineno,
38+
inliner,
39+
options=None,
40+
content=None,
41+
pyvec_board_years=None,
42+
):
43+
text = text.lstrip("#")
44+
45+
if pyvec_board_years and text.startswith("pyvec-board"):
46+
text = f"pyvec-board-{pyvec_board_years[0]}-{pyvec_board_years[1]}"
3347

3448
url = f"https://pyvec.slack.com/app_redirect?channel={text}"
35-
node = nodes.reference(rawtext, f'#{text}', refuri=url, **(options or {}))
49+
node = nodes.reference(rawtext, f"#{text}", refuri=url, **(options or {}))
3650
return [node], []
3751

3852

3953
def setup(app):
40-
board_year_from = BOARD_HISTORY[0]['from'].year
54+
board_year_from = BOARD_HISTORY[0]["from"].year
4155
board_years = (board_year_from, board_year_from + 3)
4256

43-
app.add_role('slack', functools.partial(slack, pyvec_board_years=board_years))
44-
return {'version': '1.0', 'parallel_read_safe': True}
57+
app.add_role("slack", functools.partial(slack, pyvec_board_years=board_years))
58+
return {"version": "1.0", "parallel_read_safe": True}

_extensions/test_slack.py

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,30 @@
33

44

55
def test_slack():
6-
nodes, _ = slack('slack', ':slack:`#pyvo`', '#pyvo', None, None)
6+
nodes, _ = slack("slack", ":slack:`#pyvo`", "#pyvo", None, None)
77

8-
assert nodes[0]['refuri'] == 'https://pyvec.slack.com/app_redirect?channel=pyvo'
8+
assert nodes[0]["refuri"] == "https://pyvec.slack.com/app_redirect?channel=pyvo"
99

1010

11-
@pytest.mark.parametrize('text, expected', [
12-
("pyvo", "pyvo"),
13-
("pyvec-board", "pyvec-board-2000-3000"),
14-
("pyvec-board-", "pyvec-board-2000-3000"),
15-
("pyvec-board-1987-4587", "pyvec-board-2000-3000"),
16-
])
11+
@pytest.mark.parametrize(
12+
"text, expected",
13+
[
14+
("pyvo", "pyvo"),
15+
("pyvec-board", "pyvec-board-2000-3000"),
16+
("pyvec-board-", "pyvec-board-2000-3000"),
17+
("pyvec-board-1987-4587", "pyvec-board-2000-3000"),
18+
],
19+
)
1720
def test_slack_board(text, expected):
18-
nodes, _ = slack('slack', f':slack:`#{text}`', f'#{text}', None, None,
19-
pyvec_board_years=(2000, 3000))
21+
nodes, _ = slack(
22+
"slack",
23+
f":slack:`#{text}`",
24+
f"#{text}",
25+
None,
26+
None,
27+
pyvec_board_years=(2000, 3000),
28+
)
2029

21-
assert nodes[0]['refuri'] == f'https://pyvec.slack.com/app_redirect?channel={expected}'
30+
assert (
31+
nodes[0]["refuri"] == f"https://pyvec.slack.com/app_redirect?channel={expected}"
32+
)

_extensions/twitter.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,13 @@
99

1010

1111
# https://docutils.readthedocs.io/en/sphinx-docs/howto/rst-roles.html
12-
def twitter(name, rawtext, text, lineno, inliner,
13-
options=None, content=None):
14-
text = text.lstrip('@')
12+
def twitter(name, rawtext, text, lineno, inliner, options=None, content=None):
13+
text = text.lstrip("@")
1514
url = f"https://twitter.com/{text}"
16-
node = nodes.reference(rawtext, f'@{text}', refuri=url, **(options or {}))
15+
node = nodes.reference(rawtext, f"@{text}", refuri=url, **(options or {}))
1716
return [node], []
1817

1918

2019
def setup(app):
21-
app.add_role('twitter', twitter)
22-
return {'version': '1.0', 'parallel_read_safe': True}
20+
app.add_role("twitter", twitter)
21+
return {"version": "1.0", "parallel_read_safe": True}

_scripts/generate_grants.py

Lines changed: 70 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -9,104 +9,119 @@
99
import strictyaml as yaml
1010

1111

12-
GITHUB_TOKEN = os.getenv('GITHUB_TOKEN')
13-
GITHUB_API_HEADERS = {'Accept': 'application/vnd.github.squirrel-girl-preview',
14-
'Authorization': f'token {GITHUB_TOKEN}'}
15-
GITHUB_API_URL = 'https://api.github.com/repos/pyvec/money/issues'
16-
REACTIONS_MAPPING = {'+1': 'ano', '-1': 'ne', 'eyes': 'zdržel(a) se'}
12+
GITHUB_TOKEN = os.getenv("GITHUB_TOKEN")
13+
GITHUB_API_HEADERS = {
14+
"Accept": "application/vnd.github.squirrel-girl-preview",
15+
"Authorization": f"token {GITHUB_TOKEN}",
16+
}
17+
GITHUB_API_URL = "https://api.github.com/repos/pyvec/money/issues"
18+
REACTIONS_MAPPING = {"+1": "ano", "-1": "ne", "eyes": "zdržel(a) se"}
1719
CONTENT_PATH = Path(__file__).parent.parent
1820

19-
BOARD_HISTORY_SCHEMA = yaml.Seq(yaml.Map({
20-
'from': yaml.Datetime(),
21-
'members': yaml.MapPattern(yaml.Str(), yaml.Str()),
22-
}))
23-
BOARD_HISTORY_PATH = Path(__file__).parent.parent / 'board.yml'
24-
BOARD_HISTORY = sorted(yaml.load(BOARD_HISTORY_PATH.read_text(),
25-
BOARD_HISTORY_SCHEMA).data,
26-
key=itemgetter('from'), reverse=True)
21+
BOARD_HISTORY_SCHEMA = yaml.Seq(
22+
yaml.Map(
23+
{
24+
"from": yaml.Datetime(),
25+
"members": yaml.MapPattern(yaml.Str(), yaml.Str()),
26+
}
27+
)
28+
)
29+
BOARD_HISTORY_PATH = Path(__file__).parent.parent / "board.yml"
30+
BOARD_HISTORY = sorted(
31+
yaml.load(BOARD_HISTORY_PATH.read_text(), BOARD_HISTORY_SCHEMA).data,
32+
key=itemgetter("from"),
33+
reverse=True,
34+
)
2735

2836

2937
def to_date(iso_datetime_string):
30-
iso_date_string, _ = iso_datetime_string.split('T')
38+
iso_date_string, _ = iso_datetime_string.split("T")
3139
return date.fromisoformat(iso_date_string)
3240

3341

3442
def remove_comments(html):
35-
return re.sub(r'<!--[^<]+-->', '', html).strip()
43+
return re.sub(r"<!--[^<]+-->", "", html).strip()
3644

3745

3846
def get_board_member_name(username, voted_at, board_history=None):
3947
board_history = board_history or BOARD_HISTORY
4048
for board in board_history: # sorted from the most recent
41-
if voted_at > board['from'].date():
42-
return board['members'].get(username)
49+
if voted_at > board["from"].date():
50+
return board["members"].get(username)
4351
return None
4452

4553

4654
def get_votes(reactions, voted_at, board_history=None):
4755
for reaction in reactions:
48-
username = reaction['user']['login']
56+
username = reaction["user"]["login"]
4957
name = get_board_member_name(username, voted_at, board_history)
5058
if name: # else not reaction from a board member
51-
text = REACTIONS_MAPPING.get(reaction['content'])
59+
text = REACTIONS_MAPPING.get(reaction["content"])
5260
if text:
53-
yield {'name': name, 'text': text}
61+
yield {"name": name, "text": text}
5462

5563

5664
def get_lock_date(events):
5765
for event in reversed(events):
58-
if event['event'] == 'locked':
59-
return to_date(event['created_at'])
66+
if event["event"] == "locked":
67+
return to_date(event["created_at"])
6068

6169

62-
if __name__ == '__main__':
63-
res = requests.get(GITHUB_API_URL, headers=GITHUB_API_HEADERS,
64-
params={'per_page': 100, 'state': 'closed'})
70+
if __name__ == "__main__":
71+
res = requests.get(
72+
GITHUB_API_URL,
73+
headers=GITHUB_API_HEADERS,
74+
params={"per_page": 100, "state": "closed"},
75+
)
6576
res.raise_for_status()
6677

6778
grants = []
6879
for issue in res.json():
69-
70-
labels = [label['name'] for label in issue['labels']]
71-
if 'approved' not in labels and 'rejected' not in labels:
80+
labels = [label["name"] for label in issue["labels"]]
81+
if "approved" not in labels and "rejected" not in labels:
7282
# skip unlabeled, e.g. https://github.com/pyvec/money/issues/1
7383
continue
7484

75-
if issue['locked']:
76-
res = requests.get(issue['events_url'],
77-
headers=GITHUB_API_HEADERS,
78-
params={'per_page': 100})
85+
if issue["locked"]:
86+
res = requests.get(
87+
issue["events_url"],
88+
headers=GITHUB_API_HEADERS,
89+
params={"per_page": 100},
90+
)
7991
res.raise_for_status()
8092

81-
if res.headers.get('link'):
82-
raise NotImplementedError(f"The number of events of issue #{issue['number']} "
83-
"is paginated and this code isn't yet designed "
84-
"to handle this!")
93+
if res.headers.get("link"):
94+
raise NotImplementedError(
95+
f"The number of events of issue #{issue['number']} "
96+
"is paginated and this code isn't yet designed "
97+
"to handle this!"
98+
)
8599
else:
86100
voted_at = get_lock_date(res.json())
87101
else:
88-
voted_at = to_date(issue['closed_at'])
102+
voted_at = to_date(issue["closed_at"])
89103

90-
res = requests.get(issue['reactions']['url'],
91-
headers=GITHUB_API_HEADERS)
104+
res = requests.get(issue["reactions"]["url"], headers=GITHUB_API_HEADERS)
92105
res.raise_for_status()
93106
votes = list(get_votes(res.json(), voted_at))
94107

95-
grants.append({
96-
'title': issue['title'],
97-
'description': remove_comments(issue['body']),
98-
'url': issue['html_url'],
99-
'user': {
100-
'username': issue['user']['login'],
101-
'url': issue['user']['html_url'],
102-
},
103-
'is_approved': 'approved' in labels,
104-
'filed_at': to_date(issue['created_at']),
105-
'voted_at': voted_at,
106-
'votes': votes,
107-
})
108-
grants = sorted(grants, key=itemgetter('voted_at'), reverse=True)
109-
110-
tpl_path = CONTENT_PATH / 'operations' / 'grants.rst.jinja'
108+
grants.append(
109+
{
110+
"title": issue["title"],
111+
"description": remove_comments(issue["body"]),
112+
"url": issue["html_url"],
113+
"user": {
114+
"username": issue["user"]["login"],
115+
"url": issue["user"]["html_url"],
116+
},
117+
"is_approved": "approved" in labels,
118+
"filed_at": to_date(issue["created_at"]),
119+
"voted_at": voted_at,
120+
"votes": votes,
121+
}
122+
)
123+
grants = sorted(grants, key=itemgetter("voted_at"), reverse=True)
124+
125+
tpl_path = CONTENT_PATH / "operations" / "grants.rst.jinja"
111126
tpl = Template(tpl_path.read_text())
112127
print(tpl.render(grants=grants))

0 commit comments

Comments
 (0)