-
Notifications
You must be signed in to change notification settings - Fork 2
Upstream fragility and narrow dependency #140
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
whisper67265
wants to merge
3
commits into
cppalliance:develop
Choose a base branch
from
whisper67265:fix/upstream-fragility-and-narrow-dependency
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| #!/usr/bin/env bash | ||
| # SPDX-FileCopyrightText: 2026 Andrew Zhang <whisper67265@outlook.com> | ||
| # | ||
| # SPDX-License-Identifier: BSL-1.0 | ||
| # | ||
| # Verify plugin assumptions about undocumented Weblate internals | ||
| # (FormatsConf.FORMATS AST, WEBLATE_FORMATS, weblate.urls.real_patterns). | ||
|
|
||
| set -euo pipefail | ||
|
|
||
| ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" | ||
| cd "$ROOT" | ||
|
|
||
| LATEST=0 | ||
|
|
||
| usage() { | ||
| cat <<'EOF' | ||
| Usage: check-weblate-internal-contract.sh [--latest] | ||
|
|
||
| (default) Run contract tests against the already-installed Weblate version. | ||
| --latest Install the newest modern calver Weblate from PyPI, then run tests. | ||
| EOF | ||
| } | ||
|
|
||
| while [[ $# -gt 0 ]]; do | ||
| case "$1" in | ||
| --latest) | ||
| LATEST=1 | ||
| shift | ||
| ;; | ||
| -h | --help) | ||
| usage | ||
| exit 0 | ||
| ;; | ||
| *) | ||
| echo "Unknown argument: $1" >&2 | ||
| usage >&2 | ||
| exit 2 | ||
| ;; | ||
| esac | ||
| done | ||
|
|
||
| resolve_latest_weblate_pypi() { | ||
| uv run --with packaging python3 - <<'PY' | ||
| import json | ||
| import re | ||
| import sys | ||
| import urllib.request | ||
| from packaging.version import Version | ||
|
|
||
| calver = re.compile(r"^\d{4}\.\d+(?:\.\d+)?$") | ||
|
|
||
| def is_modern_calver(name: str) -> bool: | ||
| if not calver.match(name): | ||
| return False | ||
| year = int(name.split(".", 1)[0]) | ||
| return year >= 2020 | ||
|
|
||
| with urllib.request.urlopen( | ||
| "https://pypi.org/pypi/Weblate/json", timeout=30 | ||
| ) as resp: | ||
| data = json.load(resp) | ||
|
|
||
| releases = [v for v in data["releases"] if is_modern_calver(v)] | ||
| if not releases: | ||
| print("ERROR: no modern calver Weblate releases found on PyPI", file=sys.stderr) | ||
| raise SystemExit(1) | ||
|
|
||
| releases.sort(key=Version, reverse=True) | ||
| print(releases[0]) | ||
| PY | ||
| } | ||
|
|
||
| if [[ "$LATEST" -eq 1 ]]; then | ||
| latest_ver="$(resolve_latest_weblate_pypi)" | ||
| echo "Installing latest PyPI Weblate[postgres]==${latest_ver}" | ||
| uv pip install "Weblate[postgres]==${latest_ver}" | ||
| fi | ||
|
|
||
| weblate_version="$(uv run python3 -c 'import importlib.metadata; print(importlib.metadata.version("Weblate"))')" | ||
| echo "Weblate version under test: ${weblate_version}" | ||
| echo "Contracts checked:" | ||
| echo " - FormatsConf.FORMATS AST (weblate/formats/models.py)" | ||
| echo " - WEBLATE_FORMATS (weblate_formats_with_plugin_formats)" | ||
| echo " - weblate.urls.real_patterns (list accepts URLResolver append)" | ||
|
|
||
| set +e | ||
| uv run --group dev pytest tests/test_weblate_internal_contract.py -v --tb=short -m weblate_contract | ||
| pytest_status=$? | ||
| set -e | ||
|
|
||
| if [[ "$pytest_status" -ne 0 ]]; then | ||
| echo "Weblate internal API contract check failed." >&2 | ||
| echo "Review pytest output above for which contract broke:" >&2 | ||
| echo " [FormatsConf.FORMATS AST] | [WEBLATE_FORMATS] | [weblate.urls.real_patterns]" >&2 | ||
| exit "$pytest_status" | ||
| fi | ||
|
|
||
| echo "Weblate internal API contract check passed (Weblate ${weblate_version})." |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,121 @@ | ||
| # SPDX-FileCopyrightText: 2026 Andrew Zhang <whisper67265@outlook.com> | ||
| # | ||
| # SPDX-License-Identifier: BSL-1.0 | ||
|
|
||
| """Verify undocumented Weblate internal APIs the plugin depends on (pin-bump gate).""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import importlib.util | ||
| from pathlib import Path | ||
|
|
||
| import pytest | ||
| from django.urls import URLResolver | ||
|
|
||
| from boost_weblate.endpoint.weblate_urls_adapter import ( | ||
| _assert_weblate_url_layout, | ||
| _boost_endpoint_route, | ||
| ) | ||
| from boost_weblate.settings_override import ( | ||
| _parse_formatsconf_formats_ast, | ||
| weblate_formats_with_plugin_formats, | ||
| ) | ||
|
|
||
| _CONTRACT_PREFIX_FORMATSCONF = "Weblate contract broken [FormatsConf.FORMATS AST]:" | ||
| _CONTRACT_PREFIX_WEBLATE_FORMATS = "Weblate contract broken [WEBLATE_FORMATS]:" | ||
| _CONTRACT_PREFIX_REAL_PATTERNS = "Weblate contract broken [weblate.urls.real_patterns]:" | ||
|
|
||
|
|
||
| def _load_weblate_formats_models_source() -> str: | ||
| spec = importlib.util.find_spec("weblate") | ||
| if spec is None or not spec.submodule_search_locations: | ||
| msg = f"{_CONTRACT_PREFIX_FORMATSCONF} Weblate is not installed" | ||
| raise AssertionError(msg) | ||
| path = Path(spec.submodule_search_locations[0]) / "formats" / "models.py" | ||
| return path.read_text(encoding="utf-8") | ||
|
|
||
|
|
||
| @pytest.mark.weblate_contract | ||
| def test_weblate_contract_formatsconf_ast() -> None: | ||
| try: | ||
| parsed = _parse_formatsconf_formats_ast(_load_weblate_formats_models_source()) | ||
| except RuntimeError as exc: | ||
| msg = f"{_CONTRACT_PREFIX_FORMATSCONF} {exc}" | ||
| raise AssertionError(msg) from exc | ||
| if not parsed: | ||
| msg = ( | ||
| f"{_CONTRACT_PREFIX_FORMATSCONF} " | ||
| "FormatsConf.FORMATS parsed to an empty sequence" | ||
| ) | ||
| raise AssertionError(msg) | ||
|
|
||
|
|
||
| @pytest.mark.weblate_contract | ||
| def test_weblate_contract_weblate_formats_non_empty() -> None: | ||
| try: | ||
| formats = weblate_formats_with_plugin_formats() | ||
| except RuntimeError as exc: | ||
| msg = f"{_CONTRACT_PREFIX_WEBLATE_FORMATS} {exc}" | ||
| raise AssertionError(msg) from exc | ||
| if not isinstance(formats, tuple): | ||
| msg = ( | ||
| f"{_CONTRACT_PREFIX_WEBLATE_FORMATS} " | ||
| f"expected tuple, got {type(formats).__name__}" | ||
| ) | ||
| raise AssertionError(msg) | ||
| if not formats: | ||
| msg = ( | ||
| f"{_CONTRACT_PREFIX_WEBLATE_FORMATS} " | ||
| "weblate_formats_with_plugin_formats() returned an empty tuple" | ||
| ) | ||
| raise AssertionError(msg) | ||
|
|
||
|
|
||
| @pytest.mark.weblate_contract | ||
| def test_weblate_contract_real_patterns_accepts_resolver() -> None: | ||
| try: | ||
| import weblate.urls as wl_urls | ||
| except ModuleNotFoundError as exc: | ||
| msg = f"{_CONTRACT_PREFIX_REAL_PATTERNS} weblate.urls is not importable: {exc}" | ||
| raise AssertionError(msg) from exc | ||
|
|
||
| try: | ||
| _assert_weblate_url_layout(wl_urls) | ||
| except Exception as exc: | ||
| msg = f"{_CONTRACT_PREFIX_REAL_PATTERNS} {exc}" | ||
| raise AssertionError(msg) from exc | ||
|
|
||
| real_patterns = wl_urls.real_patterns | ||
| if not isinstance(real_patterns, list): | ||
| msg = ( | ||
| f"{_CONTRACT_PREFIX_REAL_PATTERNS} " | ||
| f"real_patterns is not a list (got {type(real_patterns).__name__})" | ||
| ) | ||
| raise AssertionError(msg) | ||
|
|
||
| route = _boost_endpoint_route() | ||
| if not isinstance(route, URLResolver): | ||
| msg = ( | ||
| f"{_CONTRACT_PREFIX_REAL_PATTERNS} " | ||
| f"expected URLResolver from _boost_endpoint_route(), " | ||
| f"got {type(route).__name__}" | ||
| ) | ||
| raise AssertionError(msg) | ||
|
|
||
| before_len = len(real_patterns) | ||
| real_patterns.append(route) | ||
| try: | ||
| if len(real_patterns) != before_len + 1: | ||
| msg = ( | ||
| f"{_CONTRACT_PREFIX_REAL_PATTERNS} " | ||
| "real_patterns did not accept appended URLResolver" | ||
| ) | ||
| raise AssertionError(msg) | ||
| if real_patterns[-1] is not route: | ||
| msg = ( | ||
| f"{_CONTRACT_PREFIX_REAL_PATTERNS} " | ||
| "appended URLResolver was not retained at list tail" | ||
| ) | ||
| raise AssertionError(msg) | ||
| finally: | ||
| real_patterns.pop() |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.