diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml new file mode 100644 index 000000000..eccafe60e --- /dev/null +++ b/.github/workflows/pre-commit.yml @@ -0,0 +1,18 @@ +name: pre-commit +on: + schedule: + - cron: '0 0 * * 1,5' +env: + FORCE_COLOR: 1 + +jobs: + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + persist-credentials: false + - uses: actions/setup-python@v5 + with: + python-version: "3.x" + - uses: tox-dev/action-pre-commit-uv@v1 diff --git a/.github/workflows/update-lint-and-build.yml b/.github/workflows/update-lint-and-build.yml index 91e12dfa8..47739abe0 100644 --- a/.github/workflows/update-lint-and-build.yml +++ b/.github/workflows/update-lint-and-build.yml @@ -54,7 +54,7 @@ jobs: - run: git config --local user.name "GitHub Action's update-translation job" - name: Check changes significance run: > - ! 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 + ! 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 - run: git add . - run: git commit -m 'Update translation from Transifex' if: env.SIGNIFICANT_CHANGES diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 000000000..28b721f45 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,35 @@ +repos: + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.11.4 + hooks: + - id: ruff + args: [--fix, --exit-non-zero-on-fix] + - id: ruff-format + + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v5.0.0 + hooks: + - id: check-added-large-files + - id: check-case-conflict + - id: check-merge-conflict + - id: check-yaml + - id: debug-statements + - id: end-of-file-fixer + exclude: ^\.tx/ + - id: forbid-submodules + - id: trailing-whitespace + + - repo: https://github.com/python-jsonschema/check-jsonschema + rev: 0.32.1 + hooks: + - id: check-github-workflows + + - repo: https://github.com/rhysd/actionlint + rev: v1.7.7 + hooks: + - id: actionlint + + - repo: meta + hooks: + - id: check-hooks-apply + - id: check-useless-excludes diff --git a/license.md b/license.md index b583b1a4c..a11a3d20b 100644 --- a/license.md +++ b/license.md @@ -1,4 +1,4 @@ **License** -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. +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. 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. diff --git a/manage_translation.py b/manage_translation.py index 86f5fcacd..7d53b2f23 100755 --- a/manage_translation.py +++ b/manage_translation.py @@ -35,8 +35,8 @@ def fetch(): """ Fetch translations from Transifex, remove source lines. """ - if (code := call("tx --version", shell=True)) != 0: - sys.stderr.write("The Transifex client app is required.\n") + if (code := call('tx --version', shell=True)) != 0: + sys.stderr.write('The Transifex client app is required.\n') exit(code) lang = LANGUAGE _call(f'tx pull -l {lang} --minimum-perc=1 --force --skip') @@ -71,12 +71,14 @@ def recreate_tx_config(): file.write(contents) warn_about_files_to_delete() + def warn_about_files_to_delete(): files = list(_get_files_to_delete()) if not files: return warn(f'Found {len(files)} file(s) to delete: {", ".join(files)}.') + def _get_files_to_delete(): with open('.tx/config') as config_file: config = config_file.read() @@ -86,11 +88,13 @@ def _get_files_to_delete(): def _clone_cpython_repo(version: str): - _call(f'git clone -b {version} --single-branch https://github.com/python/cpython.git --depth 1') + _call( + f'git clone -b {version} --single-branch https://github.com/python/cpython.git --depth 1' + ) def _build_gettext(): - _call("make -C cpython/Doc/ gettext") + _call('make -C cpython/Doc/ gettext') def _create_txconfig(): @@ -115,7 +119,9 @@ class ResourceLanguageStatistics: @classmethod def from_api_entry(cls, data: transifex_api.ResourceLanguageStats) -> Self: return cls( - name=data.id.removeprefix(f'o:python-doc:p:{PROJECT_SLUG}:r:').removesuffix(f':l:{LANGUAGE}'), + name=data.id.removeprefix(f'o:python-doc:p:{PROJECT_SLUG}:r:').removesuffix( + f':l:{LANGUAGE}' + ), total_words=data.attributes['total_words'], translated_words=data.attributes['translated_words'], total_strings=data.attributes['total_strings'], @@ -161,21 +167,23 @@ def get_number_of_translators(): def _fetch_translators() -> Generator[str, None, None]: for file in Path().rglob('*.po'): header = pofile(file).header.splitlines() - for translator_record in header[header.index('Translators:') + 1:]: + for translator_record in header[header.index('Translators:') + 1 :]: translator, _year = translator_record.split(', ') yield translator def _remove_bot(translators: set[str]) -> None: - translators.remove("Transifex Bot <>") + translators.remove('Transifex Bot <>') def _eliminate_aliases(translators: set[str]) -> set[str]: unique = set() for name in translators: for match in unique: - if (ratio := SequenceMatcher(lambda x: x in '<>@', name, match).ratio()) > 0.64: - info(f"{name} and {match} are similar ({ratio:.3f}). Deduplicating.") + if ( + ratio := SequenceMatcher(lambda x: x in '<>@', name, match).ratio() + ) > 0.64: + info(f'{name} and {match} are similar ({ratio:.3f}). Deduplicating.') break else: unique.add(name) @@ -184,10 +192,12 @@ def _eliminate_aliases(translators: set[str]) -> set[str]: def language_switcher(entry: ResourceLanguageStatistics) -> bool: language_switcher_resources_prefixes = ('bugs', 'tutorial', 'library--functions') - return any(entry.name.startswith(prefix) for prefix in language_switcher_resources_prefixes) + return any( + entry.name.startswith(prefix) for prefix in language_switcher_resources_prefixes + ) -if __name__ == "__main__": +if __name__ == '__main__': RUNNABLE_SCRIPTS = ('fetch', 'recreate_tx_config', 'warn_about_files_to_delete') parser = ArgumentParser() diff --git a/ruff.toml b/ruff.toml new file mode 100644 index 000000000..749ef043d --- /dev/null +++ b/ruff.toml @@ -0,0 +1,2 @@ +[format] +quote-style = "single" diff --git a/update_switcher_chart.py b/update_switcher_chart.py deleted file mode 100644 index 7ddca16b3..000000000 --- a/update_switcher_chart.py +++ /dev/null @@ -1,35 +0,0 @@ -# EOL code, saving as this can be repurposed for a chart with the total translation progress - -from datetime import datetime -from re import search - -from git import Repo, GitCommandError -from matplotlib import pyplot -from matplotlib.ticker import PercentFormatter - -repo = Repo('.') -progress, dates = [], [] -for commit in repo.iter_commits(): - try: - readme_content = repo.git.show('{}:{}'.format(commit.hexsha, 'README.md')) - except GitCommandError: - continue - found = search(r'!\[(\d\d.\d\d)% przełącznika języków]', readme_content) - if not found: - found = search(r'!\[(\d+.\d\d)% language switchera]', readme_content) - if not found: - found = search(r'!\[(\d+.\d\d)% do language switchera]', readme_content) - if not found: - print(readme_content) - continue - number = float(found.group(1)) - progress.append(number) - dates.append(datetime.fromtimestamp(commit.authored_date)) - -pyplot.plot_date(dates, progress, linestyle='-', marker='') -pyplot.ylim(ymin=0) -pyplot.grid() -pyplot.gcf().autofmt_xdate() -pyplot.gca().yaxis.set_major_formatter(PercentFormatter()) -pyplot.title("Postęp tłumaczenia do dodania do przełącznika języków") -pyplot.savefig("language-switcher-progress.svg")