Skip to content

Commit 1b3cdf9

Browse files
Merge branch 'main' into css-improvements
2 parents 4af35c6 + 174c661 commit 1b3cdf9

File tree

8 files changed

+166
-32
lines changed

8 files changed

+166
-32
lines changed

.github/workflows/run-tests.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: Run test suite
2+
on:
3+
pull_request:
4+
workflow_dispatch:
5+
push:
6+
branches:
7+
- main
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- uses: actions/checkout@v4
15+
with:
16+
persist-credentials: false
17+
- uses: actions/setup-python@v5
18+
with:
19+
python-version: "3.x"
20+
- run: pip install -r requirements.txt
21+
- run: python -m unittest discover -s tests

build_warnings.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,11 @@ def number(clones_dir: str, repo: str, language_code: str) -> int:
3333
f'./sphinxbuild/{language_code}', # outputdir
3434
)
3535
)
36+
prefix = f'{Path(clones_dir).resolve()}/cpython/Doc/'
37+
log = '\n'.join(
38+
line.removeprefix(prefix)
39+
for line in Path(warning_file).read_text().splitlines()
40+
)
41+
Path(warning_file).write_text(log)
3642
copyfile(warning_file, f'build/warnings-{language_code}.txt')
3743
return len(findall('ERROR|WARNING', Path(warning_file).read_text()))

repositories.py

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@
22
from collections.abc import Iterator
33
from dataclasses import dataclass
44
from pathlib import Path
5-
from tempfile import TemporaryDirectory
65

76
from docutils import core
87
from docutils.nodes import table, row
9-
from git import Repo
108

119

1210
def get_languages_and_repos(
@@ -15,10 +13,14 @@ def get_languages_and_repos(
1513
translating = devguide_dir.joinpath(
1614
'documentation/translations/translating.rst'
1715
).read_text()
18-
doctree = core.publish_doctree(translating)
19-
20-
for node in doctree.traverse(table):
21-
for row_node in node.traverse(row)[1:]:
16+
doctree = core.publish_doctree(
17+
translating,
18+
settings_overrides={'report_level': 5},
19+
# docutils errors on Sphinx directives, but this does not matter for us
20+
)
21+
22+
for node in doctree.findall(table):
23+
for row_node in list(node.findall(row))[1:]:
2224
language = row_node[0].astext()
2325
repo = row_node[2].astext()
2426
language_match = re.match(r'(.*) \((.*)\)', language)
@@ -39,10 +41,3 @@ def get_languages_and_repos(
3941
class Language:
4042
code: str
4143
name: str
42-
43-
44-
if __name__ == '__main__':
45-
with TemporaryDirectory() as directory:
46-
Repo.clone_from('https://github.com/python/devguide.git', directory, depth=1)
47-
for item in get_languages_and_repos(Path(directory)):
48-
print(item)

src/style.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ td[data-label="warnings"], td[data-label="lint"] {
113113
tr {
114114
border: 1px solid #ccc;
115115
margin-bottom: 5px;
116+
overflow-x: auto;
116117
}
117118
td {
118119
border: none;

templates/build-details.html.jinja

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,27 @@
1313
</thead>
1414
<tbody>
1515
{% for project, metadata in build_details | sort(attribute='0.completion') | reverse %}
16-
<tr>
17-
<td data-label="language">{{ project.language.name }} ({{ project.language.code }})</td>
18-
<td data-label="branch">{{ project.branch }}</td>
19-
<td data-label="updated">{{ metadata[2].strftime('%Y/%m/%d %T') if metadata[2] else '' }}</td>
20-
<td data-label="warnings">
21-
{% if project.completion %}
22-
<a href="warnings-{{ project.language.code }}.txt">{{ metadata[0] }}</a>
23-
{% else %}
24-
{{ metadata[0] }}
25-
{% endif %}
26-
</td>
27-
<td data-label="lint">
28-
{% if project.completion %}
29-
<a href="warnings-lint-{{ project.language.code }}.txt">{{ metadata[1] }}</a>
30-
{% else %}
31-
{{ metadata[1] }}
32-
{% endif %}
33-
</td>
34-
</tr>
16+
{% if project.repository %}
17+
<tr>
18+
<td data-label="language">{{ project.language.name }} ({{ project.language.code }})</td>
19+
<td data-label="branch">{{ project.branch }}</td>
20+
<td data-label="updated">{{ metadata[2].strftime('%Y/%m/%d %T') if metadata[2] else '' }}</td>
21+
<td data-label="warnings">
22+
{% if project.completion %}
23+
<a href="warnings-{{ project.language.code }}.txt">{{ metadata[0] }}</a>
24+
{% else %}
25+
{{ metadata[0] }}
26+
{% endif %}
27+
</td>
28+
<td data-label="lint">
29+
{% if project.completion %}
30+
<a href="warnings-lint-{{ project.language.code }}.txt">{{ metadata[1] }}</a>
31+
{% else %}
32+
{{ metadata[1] }}
33+
{% endif %}
34+
</td>
35+
</tr>
36+
{% endif %}
3537
{% endfor %}
3638
</tbody>
3739
</table>

tests/support.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import sys
2+
import contextlib
3+
4+
# -------------------------------- Imports ----------------------------------- #
5+
6+
7+
# Support functions borrowed from CPython's test.support
8+
@contextlib.contextmanager
9+
def import_scripts(dir='..'):
10+
with DirsOnSysPath(dir) as cm:
11+
yield cm
12+
13+
14+
class DirsOnSysPath(object):
15+
def __init__(self, *paths):
16+
self.original_value = sys.path[:]
17+
self.original_object = sys.path
18+
sys.path.extend(paths)
19+
20+
def __enter__(self):
21+
return self
22+
23+
def __exit__(self, *ignore_exc):
24+
sys.path = self.original_object
25+
sys.path[:] = self.original_value

tests/test_build_status.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import unittest
2+
import support
3+
4+
from urllib3 import PoolManager
5+
6+
with support.import_scripts():
7+
import build_status
8+
9+
10+
class testBuildStatus(unittest.TestCase):
11+
def test_get_languages(self):
12+
result = {
13+
language: translated_name
14+
for language, translated_name in build_status.get_languages(PoolManager())
15+
}
16+
17+
self.assertIn('en', result)
18+
self.assertIn('pl', result)
19+
self.assertIn('zh-cn', result)
20+
21+
self.assertEqual(result.get('en'), None)
22+
self.assertEqual(result.get('pl'), 'polski')
23+
self.assertEqual(result.get('zh-cn'), '简体中文')
24+
25+
26+
if __name__ == '__main__':
27+
unittest.main()

tests/test_repositories.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import unittest
2+
import support
3+
import tempfile
4+
import shutil
5+
6+
from pathlib import Path
7+
from git import Repo
8+
9+
with support.import_scripts():
10+
import repositories
11+
from repositories import Language
12+
13+
14+
class testRepositories(unittest.TestCase):
15+
@classmethod
16+
def setUpClass(cls):
17+
cls.tempdir = tempfile.mkdtemp()
18+
cls.test_repo_path = Path(cls.tempdir) / 'devguide'
19+
cls.test_repo = Repo.clone_from(
20+
'https://github.com/python/devguide',
21+
cls.test_repo_path,
22+
branch='main',
23+
depth=1,
24+
)
25+
26+
@classmethod
27+
def tearDownClass(cls):
28+
shutil.rmtree(cls.tempdir)
29+
30+
def test_get_languages_and_repos(self):
31+
result = list(repositories.get_languages_and_repos(self.test_repo_path))
32+
33+
for entry in result:
34+
info, repo = entry
35+
self.assertIsInstance(info, Language)
36+
37+
self.assertIn(
38+
(Language(code='tr', name='Turkish'), 'python/python-docs-tr'), result
39+
)
40+
self.assertIn(
41+
(Language(code='es', name='Spanish'), 'python/python-docs-es'), result
42+
)
43+
self.assertIn(
44+
(Language(code='pl', name='Polish'), 'python/python-docs-pl'), result
45+
)
46+
self.assertIn(
47+
(
48+
Language(code='zh-tw', name='Traditional Chinese'),
49+
'python/python-docs-zh-tw',
50+
),
51+
result,
52+
)
53+
self.assertIn(
54+
(Language(code='it', name='Italian'), 'python/python-docs-it'), result
55+
)
56+
57+
self.assertGreater(len(result), 23 - 1)

0 commit comments

Comments
 (0)