Skip to content

Commit b22d2b5

Browse files
authored
Merge branch 'main' into translators-align-sort
2 parents f1acc06 + 302f8b9 commit b22d2b5

10 files changed

+111
-26
lines changed

.github/workflows/lint.yml

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: Lint
2+
3+
on: [push, pull_request, workflow_dispatch]
4+
5+
env:
6+
FORCE_COLOR: 1
7+
8+
jobs:
9+
lint:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- uses: actions/checkout@v4
14+
with:
15+
persist-credentials: false
16+
- uses: actions/setup-python@v5
17+
with:
18+
python-version: "3.x"
19+
- uses: tox-dev/action-pre-commit-uv@v1

.github/workflows/update.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
- uses: actions/setup-python@v5
1616
with:
1717
python-version: "3.x"
18-
- uses: astral-sh/setup-uv@v4
18+
- uses: astral-sh/setup-uv@v5
1919
- uses: actions/checkout@v4
2020
- run: sudo apt-get install -y gettext
2121
- run: uv run generate.py # generates "index.html"

.pre-commit-config.yaml

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
repos:
2+
- repo: https://github.com/astral-sh/ruff-pre-commit
3+
rev: v0.8.6
4+
hooks:
5+
- id: ruff
6+
args: [--fix, --exit-non-zero-on-fix]
7+
- id: ruff-format
8+
9+
- repo: https://github.com/pre-commit/pre-commit-hooks
10+
rev: v5.0.0
11+
hooks:
12+
- id: check-added-large-files
13+
- id: check-case-conflict
14+
- id: check-merge-conflict
15+
- id: check-toml
16+
- id: check-yaml
17+
- id: debug-statements
18+
- id: end-of-file-fixer
19+
- id: forbid-submodules
20+
- id: trailing-whitespace
21+
22+
- repo: https://github.com/python-jsonschema/check-jsonschema
23+
rev: 0.30.0
24+
hooks:
25+
- id: check-github-workflows
26+
27+
- repo: https://github.com/rhysd/actionlint
28+
rev: v1.7.6
29+
hooks:
30+
- id: actionlint
31+
32+
- repo: meta
33+
hooks:
34+
- id: check-hooks-apply
35+
- id: check-useless-excludes
36+
37+
ci:
38+
autoupdate_schedule: quarterly

completion.py

+9-3
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,17 @@ def branches_from_devguide(devguide_dir: Path) -> list[str]:
1414
p = devguide_dir.joinpath('include/release-cycle.json')
1515
data = json.loads(p.read_text())
1616
return [
17-
branch for branch in data if data[branch]["status"] in ("bugfix", "security")
17+
branch for branch in data if data[branch]['status'] in ('bugfix', 'security')
1818
]
1919

2020

2121
def get_completion(clones_dir: str, repo: str) -> tuple[float, int]:
2222
clone_path = Path(clones_dir, repo)
2323
for branch in branches_from_devguide(Path(clones_dir, 'devguide')) + ['master']:
2424
try:
25-
git.Repo.clone_from(f'https://github.com/{repo}.git', clone_path, branch=branch)
25+
git.Repo.clone_from(
26+
f'https://github.com/{repo}.git', clone_path, branch=branch
27+
)
2628
except git.GitCommandError:
2729
print(f'failed to clone {repo} {branch}')
2830
translators_number = 0
@@ -32,6 +34,10 @@ def get_completion(clones_dir: str, repo: str) -> tuple[float, int]:
3234
break
3335
with TemporaryDirectory() as tmpdir:
3436
completion = potodo.merge_and_scan_path(
35-
clone_path, pot_path=Path(clones_dir, 'cpython/Doc/build/gettext'), merge_path=Path(tmpdir), hide_reserved=False, api_url=''
37+
clone_path,
38+
pot_path=Path(clones_dir, 'cpython/Doc/build/gettext'),
39+
merge_path=Path(tmpdir),
40+
hide_reserved=False,
41+
api_url='',
3642
).completion
3743
return completion, translators_number

generate.py

+16-5
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,22 @@
2525
generation_time = datetime.now(timezone.utc)
2626

2727
with TemporaryDirectory() as clones_dir:
28-
Repo.clone_from(f'https://github.com/python/devguide.git', devguide_dir := Path(clones_dir, 'devguide'), depth=1)
28+
Repo.clone_from(
29+
'https://github.com/python/devguide.git',
30+
devguide_dir := Path(clones_dir, 'devguide'),
31+
depth=1,
32+
)
2933
latest_branch = branches_from_devguide(devguide_dir)[0]
3034
Repo.clone_from(
31-
f'https://github.com/python/cpython.git', Path(clones_dir, 'cpython'), depth=1, branch=latest_branch
35+
'https://github.com/python/cpython.git',
36+
Path(clones_dir, 'cpython'),
37+
depth=1,
38+
branch=latest_branch,
3239
)
3340
subprocess.run(['make', '-C', Path(clones_dir, 'cpython/Doc'), 'venv'], check=True)
34-
subprocess.run(['make', '-C', Path(clones_dir, 'cpython/Doc'), 'gettext'], check=True)
41+
subprocess.run(
42+
['make', '-C', Path(clones_dir, 'cpython/Doc'), 'gettext'], check=True
43+
)
3544
switcher_languages = list(switcher.get_languages())
3645
for language, repo in repositories.get_languages_and_repos(devguide_dir):
3746
if repo:
@@ -108,7 +117,9 @@
108117
"""
109118
)
110119

111-
output = template.render(completion_progress=completion_progress, generation_time=generation_time)
120+
output = template.render(
121+
completion_progress=completion_progress, generation_time=generation_time
122+
)
112123

113-
with open("index.html", "w") as file:
124+
with open('index.html', 'w') as file:
114125
file.write(output)

repositories.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import tempfile
21
import pathlib
32
import re
43
from typing import Generator, Optional
@@ -7,14 +6,18 @@
76
from docutils.nodes import table, row
87

98

10-
def get_languages_and_repos(devguide_dir: pathlib.Path) -> Generator[tuple[str, Optional[str]], None, None]:
9+
def get_languages_and_repos(
10+
devguide_dir: pathlib.Path,
11+
) -> Generator[tuple[str, Optional[str]], None, None]:
1112
translating = devguide_dir.joinpath('documentation/translating.rst').read_text()
1213
doctree = core.publish_doctree(translating)
1314

1415
for node in doctree.traverse(table):
1516
for row_node in node.traverse(row)[1:]:
1617
language = row_node[0].astext()
1718
repo = row_node[2].astext()
18-
language_code = re.match(r'.* \((.*)\)', language).group(1).lower().replace('_', '-')
19+
language_code = (
20+
re.match(r'.* \((.*)\)', language).group(1).lower().replace('_', '-')
21+
)
1922
repo_match = re.match(':github:`GitHub <(.*)>`', repo)
2023
yield language_code, repo_match and repo_match.group(1)

ruff.toml

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[format]
2+
quote-style = "single"

switcher.py

+9-10
Original file line numberDiff line numberDiff line change
@@ -6,32 +6,31 @@
66
"""
77

88
import tomllib
9-
from collections import defaultdict
109
from typing import Generator
1110

1211
import requests
1312

1413

1514
def get_languages() -> Generator[str, None, None]:
1615
data = requests.get(
17-
"https://raw.githubusercontent.com/"
18-
"python/docsbuild-scripts/refs/heads/main/config.toml",
16+
'https://raw.githubusercontent.com/'
17+
'python/docsbuild-scripts/refs/heads/main/config.toml',
1918
timeout=10,
2019
).text
2120
config = tomllib.loads(data)
22-
languages = config["languages"]
23-
defaults = config["defaults"]
21+
languages = config['languages']
22+
defaults = config['defaults']
2423
for code, language in languages.items():
25-
if language.get("in_prod", defaults["in_prod"]):
26-
yield code.lower().replace("_", "-")
24+
if language.get('in_prod', defaults['in_prod']):
25+
yield code.lower().replace('_', '-')
2726

2827

2928
def main() -> None:
3029
languages = list(get_languages())
3130
print(languages)
32-
for code in ("en", "pl", "ar", "zh-cn"):
33-
print(f"{code}: {code in languages}")
31+
for code in ('en', 'pl', 'ar', 'zh-cn'):
32+
print(f'{code}: {code in languages}')
3433

3534

36-
if __name__ == "__main__":
35+
if __name__ == '__main__':
3736
main()

translators.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@ def get_number(path: Path) -> int:
1010
from_git_history = get_number_from_git_history(path)
1111
return max(from_headers, from_git_history)
1212

13+
1314
def get_number_from_git_history(path: Path) -> int:
1415
return len(Repo(path).git.shortlog('-s', 'HEAD').splitlines())
1516

17+
1618
def yield_from_headers(path: Path) -> Generator[str, None, None]:
1719
for file in path.rglob('*.po'):
1820
try:
@@ -21,7 +23,7 @@ def yield_from_headers(path: Path) -> Generator[str, None, None]:
2123
continue
2224
if 'Translators:' not in header:
2325
continue
24-
for translator_record in header[header.index('Translators:') + 1:]:
26+
for translator_record in header[header.index('Translators:') + 1 :]:
2527
try:
2628
translator, _year = translator_record.split(', ')
2729
except ValueError:

visitors.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,13 @@
77

88

99
def get_number_of_visitors(language: str) -> int:
10-
param = urllib.parse.urlencode({'filters': f'[["contains","event:page",["/{language}/"]]]'})
10+
param = urllib.parse.urlencode(
11+
{'filters': f'[["contains","event:page",["/{language}/"]]]'}
12+
)
1113
r = requests.get(f'https://plausible.io/docs.python.org/export?{param}', timeout=10)
12-
with zipfile.ZipFile(io.BytesIO(r.content), 'r') as z, z.open('visitors.csv') as csv_file:
14+
with (
15+
zipfile.ZipFile(io.BytesIO(r.content), 'r') as z,
16+
z.open('visitors.csv') as csv_file,
17+
):
1318
csv_reader = csv.DictReader(io.TextIOWrapper(csv_file))
14-
return sum(int(row["visitors"]) for row in csv_reader)
19+
return sum(int(row['visitors']) for row in csv_reader)

0 commit comments

Comments
 (0)