Skip to content

Commit 2495e81

Browse files
committed
Simplify spellcheck metadata and exclude obsolete catalogs
1 parent a957207 commit 2495e81

4 files changed

Lines changed: 95 additions & 18 deletions

File tree

‎.github/workflows/spellcheck.yml‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ permissions:
2727

2828
jobs:
2929
pospell:
30+
# Fork PRs cannot access TX_TOKEN; forks can run manually with their own secret.
31+
if: ${{ github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository }}
3032
runs-on: ubuntu-latest
3133
continue-on-error: ${{ inputs.advisory || github.event_name == 'pull_request' || github.event_name == 'workflow_dispatch' }}
3234
timeout-minutes: 15
@@ -117,10 +119,10 @@ jobs:
117119
# CPython 3.10 and 3.11 do not have a dedicated gettext target.
118120
make build BUILDER=gettext SPHINXOPTS="-D gettext_additional_targets=index -D gettext_compact=0"
119121
fi
120-
- name: Record original translation checksums
122+
- name: Select current catalogs and record original checksums
121123
run: >
122124
python "$GITHUB_WORKSPACE/spellcheck-tools/spellcheck_report.py" snapshot
123-
--translations locales/pl/LC_MESSAGES --cpython .
125+
--translations locales/pl/LC_MESSAGES --cpython . --pot-dir build/gettext
124126
--output "$RUNNER_TEMP/spellcheck-source.json"
125127
- name: Update temporary PO files
126128
# Drop obsolete entries so removed literal blocks are not spellchecked.

‎SPELLCHECK_REPORT.md‎

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,19 @@ is published.
2323
- `translations_revision` and `cpython_revision`: the checked-out Git commits.
2424

2525
Catalog paths are relative to `locales/pl/LC_MESSAGES`, such as
26-
`tutorial/guide.po`. Each catalog's `source_sha256` is replaced with the checksum
27-
of the original PO, recorded before the temporary `sphinx-intl update`. This lets
28-
consumers compare coverage with their repository checkout. Pospell's checksum of
29-
the temporarily updated PO is retained as `scanned_sha256`.
30-
31-
Only catalogs present both in the original checkout and in pospell's report are
32-
published; unscanned files are not added as clean. The scan covers prose and
33-
excludes literal blocks through the temporary gettext update.
34-
35-
`potodo-docs-priority` downloads the artifact separately. It validates the source
36-
run, selects complete reports for its requested branch, and checks local entry
37-
identities and fingerprints. This workflow requires no dispatch to that project.
26+
`tutorial/guide.po`. Each catalog retains pospell's `source_sha256`, the checksum
27+
of the temporarily updated PO that was scanned. `checkout_sha256` records the
28+
original repository PO before `sphinx-intl update`, so consumers can check
29+
freshness against their checkout.
30+
31+
Before the temporary update, catalogs with no matching current POT are removed
32+
from the disposable checkout; otherwise old catalogs would retain literal blocks.
33+
`sphinx.po` is kept separately for Sphinx's template messages. Only catalogs
34+
present both in the original snapshot and pospell's report are published;
35+
unscanned files are not added as clean.
36+
37+
The translation dashboard downloads `spellcheck-pl/spellcheck.json` and publishes
38+
the complete report at `https://translations.python.org/spellcheck-pl.json`, or
39+
JSON `null` when unavailable. `potodo-docs-priority` reads that public file and
40+
checks local entry identities and translation fingerprints. Only the dashboard
41+
needs a token for cross-repository Actions access.

‎spellcheck_report.py‎

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,7 @@ def prepare_report(
5353
'catalogs': {
5454
resource: {
5555
**catalog,
56-
'scanned_sha256': catalog['source_sha256'],
57-
'source_sha256': snapshot['catalogs'][resource],
56+
'checkout_sha256': snapshot['catalogs'][resource],
5857
}
5958
for resource, catalog in report['catalogs'].items()
6059
# Newly created catalogs have no corresponding repository file.
@@ -69,6 +68,7 @@ def main() -> None:
6968
snapshot_parser = commands.add_parser('snapshot')
7069
snapshot_parser.add_argument('--translations', type=Path, required=True)
7170
snapshot_parser.add_argument('--cpython', type=Path, required=True)
71+
snapshot_parser.add_argument('--pot-dir', type=Path, required=True)
7272
snapshot_parser.add_argument('--output', type=Path, required=True)
7373
report_parser = commands.add_parser('prepare')
7474
report_parser.add_argument('--input', type=Path, required=True)
@@ -77,6 +77,17 @@ def main() -> None:
7777
report_parser.add_argument('--output', type=Path, required=True)
7878
args = parser.parse_args()
7979
if args.command == 'snapshot':
80+
if not args.pot_dir.is_dir():
81+
parser.error(f'POT directory does not exist: {args.pot_dir}')
82+
# Only current POT catalogs have had literal blocks excluded. Sphinx's
83+
# template messages are maintained separately from the documentation.
84+
for path in args.translations.rglob('*.po'):
85+
resource = path.relative_to(args.translations)
86+
if (
87+
resource != Path('sphinx.po')
88+
and not (args.pot_dir / resource.with_suffix('.pot')).is_file()
89+
):
90+
path.unlink()
8091
data = snapshot_catalogs(args.translations, args.cpython)
8192
else:
8293
data = prepare_report(

‎tests/test_spellcheck_report.py‎

Lines changed: 62 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ def test_original_checksum_survives_temporary_po_update(self):
5757
self.catalog.write_text('# temporary changes\n', encoding='utf-8')
5858
result = self.prepare()
5959
catalog = result['catalogs']['tutorial/guide.po']
60-
self.assertEqual(catalog['source_sha256'], original)
61-
self.assertEqual(catalog['scanned_sha256'], 'temporary-po-digest')
60+
self.assertEqual(catalog['checkout_sha256'], original)
61+
self.assertEqual(catalog['source_sha256'], 'temporary-po-digest')
6262
self.assertEqual(catalog['findings'], [self.finding])
6363
self.assertEqual(result['language'], 'pl')
6464
self.assertEqual(result['dictionaries'], ['pl_PL', 'pl_SJP'])
@@ -144,3 +144,63 @@ def test_missing_pospell_report_cannot_become_a_clean_report(self):
144144
):
145145
main()
146146
self.assertFalse(output.exists())
147+
148+
def test_snapshot_keeps_current_catalogs_and_sphinx_but_drops_orphans(self):
149+
pots = self.root / 'pots'
150+
(pots / 'tutorial').mkdir(parents=True)
151+
(pots / 'tutorial' / 'guide.pot').write_text('msgid "Source"\nmsgstr ""\n')
152+
orphan = self.root / 'old.po'
153+
orphan.write_text('msgid "Literal code"\nmsgstr "Literal code"\n')
154+
sphinx = self.root / 'sphinx.po'
155+
sphinx.write_text('msgid "Template"\nmsgstr "Szablon"\n')
156+
output = self.root / 'snapshot.json'
157+
with (
158+
patch(
159+
'spellcheck_report.revision', side_effect=['translations', 'cpython']
160+
),
161+
patch(
162+
'sys.argv',
163+
[
164+
'spellcheck_report.py',
165+
'snapshot',
166+
'--translations',
167+
str(self.root),
168+
'--cpython',
169+
str(self.root),
170+
'--pot-dir',
171+
str(pots),
172+
'--output',
173+
str(output),
174+
],
175+
),
176+
):
177+
main()
178+
self.assertFalse(orphan.exists())
179+
self.assertTrue(self.catalog.exists())
180+
self.assertTrue(sphinx.exists())
181+
self.assertEqual(
182+
set(json.loads(output.read_text())['catalogs']),
183+
{'tutorial/guide.po', 'sphinx.po'},
184+
)
185+
186+
def test_missing_pot_directory_does_not_remove_catalogs(self):
187+
with (
188+
patch(
189+
'sys.argv',
190+
[
191+
'spellcheck_report.py',
192+
'snapshot',
193+
'--translations',
194+
str(self.root),
195+
'--cpython',
196+
str(self.root),
197+
'--pot-dir',
198+
str(self.root / 'missing'),
199+
'--output',
200+
str(self.root / 'snapshot.json'),
201+
],
202+
),
203+
self.assertRaises(SystemExit),
204+
):
205+
main()
206+
self.assertTrue(self.catalog.exists())

0 commit comments

Comments
 (0)