Skip to content

Commit 67c204b

Browse files
Add pre-commit (#90)
1 parent c9016e3 commit 67c204b

File tree

6 files changed

+78
-13
lines changed

6 files changed

+78
-13
lines changed

.github/workflows/pre-commit.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: pre-commit
2+
on:
3+
schedule:
4+
- cron: '0 0 * * 1,5'
5+
env:
6+
FORCE_COLOR: 1
7+
8+
jobs:
9+
lint:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v4
13+
with:
14+
persist-credentials: false
15+
- uses: actions/setup-python@v5
16+
with:
17+
python-version: "3.x"
18+
- uses: tox-dev/action-pre-commit-uv@v1

.github/workflows/update-lint-and-build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ jobs:
5454
- run: git config --local user.name "GitHub Action's update-translation job"
5555
- name: Check changes significance
5656
run: >
57-
! git diff -I'^"POT-Creation-Date: ' -I'^"Language-Team: ' -I'^# ' -I'^"Last-Translator: ' -I'^"Project-Id-Version: ' --exit-code && echo "SIGNIFICANT_CHANGES=1" >> $GITHUB_ENV || exit 0
57+
! git diff -I'^"POT-Creation-Date: ' -I'^"Language-Team: ' -I'^# ' -I'^"Last-Translator: ' -I'^"Project-Id-Version: ' --exit-code && echo "SIGNIFICANT_CHANGES=1" >> "$GITHUB_ENV" || exit 0
5858
- run: git add .
5959
- run: git commit -m 'Update translation from Transifex'
6060
if: env.SIGNIFICANT_CHANGES

.pre-commit-config.yaml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
repos:
2+
- repo: https://github.com/astral-sh/ruff-pre-commit
3+
rev: v0.11.4
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-yaml
16+
- id: debug-statements
17+
- id: end-of-file-fixer
18+
exclude: ^\.tx/
19+
- id: forbid-submodules
20+
- id: trailing-whitespace
21+
22+
- repo: https://github.com/python-jsonschema/check-jsonschema
23+
rev: 0.32.1
24+
hooks:
25+
- id: check-github-workflows
26+
27+
- repo: https://github.com/rhysd/actionlint
28+
rev: v1.7.7
29+
hooks:
30+
- id: actionlint
31+
32+
- repo: meta
33+
hooks:
34+
- id: check-hooks-apply
35+
- id: check-useless-excludes

license.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
**License**
22

3-
By inviting you to work on a project on the Transifex platform, we offer a contract for donating your translations to the Python Software Foundation under the CC0 license.
3+
By inviting you to work on a project on the Transifex platform, we offer a contract for donating your translations to the Python Software Foundation under the CC0 license.
44
In return, it will be visible that you are the translator of the part you translated. You signify your acceptance of this agreement by submitting your work for inclusion in the documentation.

manage_translation.py

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ def fetch():
3535
"""
3636
Fetch translations from Transifex, remove source lines.
3737
"""
38-
if (code := call("tx --version", shell=True)) != 0:
39-
sys.stderr.write("The Transifex client app is required.\n")
38+
if (code := call('tx --version', shell=True)) != 0:
39+
sys.stderr.write('The Transifex client app is required.\n')
4040
exit(code)
4141
lang = LANGUAGE
4242
_call(f'tx pull -l {lang} --minimum-perc=1 --force --skip')
@@ -71,12 +71,14 @@ def recreate_tx_config():
7171
file.write(contents)
7272
warn_about_files_to_delete()
7373

74+
7475
def warn_about_files_to_delete():
7576
files = list(_get_files_to_delete())
7677
if not files:
7778
return
7879
warn(f'Found {len(files)} file(s) to delete: {", ".join(files)}.')
7980

81+
8082
def _get_files_to_delete():
8183
with open('.tx/config') as config_file:
8284
config = config_file.read()
@@ -86,11 +88,13 @@ def _get_files_to_delete():
8688

8789

8890
def _clone_cpython_repo(version: str):
89-
_call(f'git clone -b {version} --single-branch https://github.com/python/cpython.git --depth 1')
91+
_call(
92+
f'git clone -b {version} --single-branch https://github.com/python/cpython.git --depth 1'
93+
)
9094

9195

9296
def _build_gettext():
93-
_call("make -C cpython/Doc/ gettext")
97+
_call('make -C cpython/Doc/ gettext')
9498

9599

96100
def _create_txconfig():
@@ -115,7 +119,9 @@ class ResourceLanguageStatistics:
115119
@classmethod
116120
def from_api_entry(cls, data: transifex_api.ResourceLanguageStats) -> Self:
117121
return cls(
118-
name=data.id.removeprefix(f'o:python-doc:p:{PROJECT_SLUG}:r:').removesuffix(f':l:{LANGUAGE}'),
122+
name=data.id.removeprefix(f'o:python-doc:p:{PROJECT_SLUG}:r:').removesuffix(
123+
f':l:{LANGUAGE}'
124+
),
119125
total_words=data.attributes['total_words'],
120126
translated_words=data.attributes['translated_words'],
121127
total_strings=data.attributes['total_strings'],
@@ -161,21 +167,23 @@ def get_number_of_translators():
161167
def _fetch_translators() -> Generator[str, None, None]:
162168
for file in Path().rglob('*.po'):
163169
header = pofile(file).header.splitlines()
164-
for translator_record in header[header.index('Translators:') + 1:]:
170+
for translator_record in header[header.index('Translators:') + 1 :]:
165171
translator, _year = translator_record.split(', ')
166172
yield translator
167173

168174

169175
def _remove_bot(translators: set[str]) -> None:
170-
translators.remove("Transifex Bot <>")
176+
translators.remove('Transifex Bot <>')
171177

172178

173179
def _eliminate_aliases(translators: set[str]) -> set[str]:
174180
unique = set()
175181
for name in translators:
176182
for match in unique:
177-
if (ratio := SequenceMatcher(lambda x: x in '<>@', name, match).ratio()) > 0.64:
178-
info(f"{name} and {match} are similar ({ratio:.3f}). Deduplicating.")
183+
if (
184+
ratio := SequenceMatcher(lambda x: x in '<>@', name, match).ratio()
185+
) > 0.64:
186+
info(f'{name} and {match} are similar ({ratio:.3f}). Deduplicating.')
179187
break
180188
else:
181189
unique.add(name)
@@ -184,10 +192,12 @@ def _eliminate_aliases(translators: set[str]) -> set[str]:
184192

185193
def language_switcher(entry: ResourceLanguageStatistics) -> bool:
186194
language_switcher_resources_prefixes = ('bugs', 'tutorial', 'library--functions')
187-
return any(entry.name.startswith(prefix) for prefix in language_switcher_resources_prefixes)
195+
return any(
196+
entry.name.startswith(prefix) for prefix in language_switcher_resources_prefixes
197+
)
188198

189199

190-
if __name__ == "__main__":
200+
if __name__ == '__main__':
191201
RUNNABLE_SCRIPTS = ('fetch', 'recreate_tx_config', 'warn_about_files_to_delete')
192202

193203
parser = ArgumentParser()

ruff.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[format]
2+
quote-style = "single"

0 commit comments

Comments
 (0)