Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork40
Drop template generation for updating .tx/config#283
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
Show all changes
9 commits Select commitHold shift + click to select a range
bb7a184 Add generate_txconfig.py
rffontenelleb0b9311 Move TEXT_TO_REPLACE outside function, move parse_args first
rffontenelle4e910c7 Drop cpython checkout and change language dir
rffontenelled2e46f3 Make environment variable available
rffontenelle028dee7 Handle new path in potodo.sh
rffontenelle2762541 Fix script dir in commit.sh
rffontenelle7e19c40 Handle lang_dir in stats.py
rffontenelle52fefb8 Use Path to str
rffontenelle78db6b8 black
rffontenelleFile filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
49 changes: 18 additions & 31 deletions.github/workflows/sync.yml
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
10 changes: 7 additions & 3 deletionsscripts/commit.sh
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
125 changes: 125 additions & 0 deletionsscripts/generate_txconfig.py
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,125 @@ | ||
| #!/usr/bin/env python3 | ||
| """ | ||
| Generate the .tx/config file based on the existing projects | ||
| in Python docs Transifex project. Takes an project slug as | ||
| positional argument, e.g. python-newest or python-313 | ||
| """ | ||
| import argparse | ||
| import re | ||
| import subprocess | ||
| import sys | ||
| from pathlib import Path | ||
| # Replaces required to fix the default values set by 'tx add remote' command. | ||
| # Add or remove | ||
| TEXT_TO_REPLACE = { | ||
| "2_": "2.", | ||
| "3_": "3.", | ||
| "glossary_": "glossary", | ||
| "collections_": "collections.", | ||
| "compression_": "compression.", | ||
| "concurrent_": "concurrent.", | ||
| "curses_": "curses.", | ||
| "email_": "email.", | ||
| "html_": "html.", | ||
| "http_": "http.", | ||
| "importlib_resources_": "importlib.resources.", | ||
| "importlib_": "importlib.", | ||
| "logging_": "logging.", | ||
| "multiprocessing_": "multiprocessing.", | ||
| "os_": "os.", | ||
| "string_": "string.", | ||
| "sys_monitoring": "sys.monitoring", | ||
| "tkinter_": "tkinter.", | ||
| "unittest_": "unittest.", | ||
| "urllib_": "urllib.", | ||
| "xml_dom_": "xml.dom.", | ||
| "xml_etree_": "xml.etree.", | ||
| "xmlrpc_": "xmlrpc.", | ||
| "xml_sax_": "xml.sax.", | ||
| "xml_": "xml.", | ||
| } | ||
| def parse_args(): | ||
| parser = argparse.ArgumentParser(description=__doc__) | ||
| parser.add_argument( | ||
| "--root-path", | ||
| "-p", | ||
| default=Path("."), | ||
| help="Path to the translation files, and also the .tx/config (defaults to current directory)", | ||
| ) | ||
| parser.add_argument( | ||
| "tx_project", help="Slug of the Transifex project to query resources from" | ||
| ) | ||
| return parser.parse_args() | ||
| def reset_tx_config(txconfig: Path): | ||
| """Create or reset the .tx/config file with basic header.""" | ||
| txconfig.parent.mkdir(exist_ok=True) | ||
| txconfig.write_text("[main]\nhost = https://www.transifex.com\n", encoding="utf-8") | ||
| print("Initialized .tx/config.") | ||
| def populate_resources_from_remote(config_file: Path, tx_project: str): | ||
| """Add the remote resources from the Transifex project to .tx/config.""" | ||
| result = subprocess.run( | ||
| [ | ||
| "tx", | ||
| "--config", | ||
| str(config_file), | ||
| "add", | ||
| "remote", | ||
| "--file-filter", | ||
| "<lang>/<resource_slug>.<ext>", | ||
| f"https://app.transifex.com/python-doc/{tx_project}/", | ||
| ], | ||
| check=True, | ||
| ) | ||
| if result.returncode != 0: | ||
| print("Failed to add the resources from remote:") | ||
| print(result.stderr.strip()) | ||
| sys.exit(result.returncode) | ||
| print("Added remote resources to Transifex.") | ||
| def patch_config(txconfig: Path): | ||
| """Patch .tx/config to fixing PO filenames to match the expected.""" | ||
| content = txconfig.read_text(encoding="utf-8").splitlines() | ||
| new_lines = [] | ||
| for line in content: | ||
| if line.startswith(("source_file", "source_lang")): | ||
| continue | ||
| if line.startswith("file_filter"): | ||
| line = line.replace("<lang>/", "") | ||
| line = line.replace("--", "/") | ||
| for pattern, replacement in TEXT_TO_REPLACE.items(): | ||
| if pattern in line: | ||
| line = line.replace(pattern, replacement) | ||
| break | ||
| new_lines.append(line) | ||
| text = "\n".join(new_lines) | ||
| txconfig.write_text(text + "\n", encoding="utf-8") | ||
| print("Updated .tx/config with character substitutions") | ||
| def main(): | ||
| args = parse_args() | ||
| config_path = Path(".tx/config") | ||
| if args.root_path: | ||
| config_path = args.root_path / config_path | ||
| reset_tx_config(config_path) | ||
| populate_resources_from_remote(config_path, args.tx_project) | ||
| patch_config(config_path) | ||
| if __name__ == "__main__": | ||
| main() |
3 changes: 2 additions & 1 deletionscripts/potodo.sh
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
6 changes: 5 additions & 1 deletionscripts/pull_translations.sh
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
13 changes: 9 additions & 4 deletionsscripts/stats.py
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
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
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.