-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
scripts/set-alias-page.py: Improve sync translations #15389
base: main
Are you sure you want to change the base?
Conversation
This comment was marked as off-topic.
This comment was marked as off-topic.
Could you remove the Korean changes? I think you have committed them by accident when testing |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After removing the Korean changes (or moving them to a separate PR), this LGTM!
Let's separate the Korean alias page into a different PR |
Co-authored-by: Sebastiaan Speck <[email protected]>
Co-authored-by: Sebastiaan Speck <[email protected]>
Co-authored-by: Sebastiaan Speck <[email protected]>
Looks a lot better now, minor thing that remains; the title for a page; I understand these issues were initially out-of-scope of this PR, but I guess it is better to fix it properly now than iterate multiple times with still a "broken" script. |
I also think it's better to fix it properly before moving on. Currently, the title is parsed from the file path, but it might be better to extract it directly from the original alias content instead. |
I agree, we just need to copy the title just like it exists in pages/. If we are creating a new page, we could add a third optional argument, just like you did with DOCUMENTATION_COMMAND. |
scripts/_common.py
Outdated
@@ -309,7 +309,7 @@ def create_argument_parser(description: str) -> argparse.ArgumentParser: | |||
|
|||
parser = argparse.ArgumentParser(description=description) | |||
parser.add_argument( | |||
"-p", | |||
"-P", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe we still can use -p
. Explain why not
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's typically because of the documentation command exception of the "osx/g*.md" document in "osx/gsum.md ". If "-p linux sum" is used as an argument, it recognizes "-p" and causes an error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
However, instead of taking title and commands as arguments, we can use "-p" again if you make it into a wizard form
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Feel free to modify it, but that feels like a new PR. Let's fix the current issues and then accept this PR for now.
- Change -P/--page option to -p/--page - Remove positional arguments (ORIGINAL_CMD, DOCUMENTATION_CMD) - Add interactive wizard for creating alias pages - Refactor sync functionality with dataclasses (SyncConfig, AliasPage) - Extract title from alias pages for better sync - Update documentation and examples - Improve code formatting and readability - Add detailed prompts with examples for each input field - Show preview of the page before creation
- Update Config dataclass for global script configuration - Move dataclass definitions to top of file - Remove redundant dry_run and language parameters from functions - Update function signatures to use global config
- Refactor AliasPage to use AliasPageContent - Update function signatures to use new dataclass * get_alias_command_in_page returns AliasPageContent * set_alias_page takes AliasPageContent parameter * generate_alias_page_content takes AliasPageContent - Simplify get_english_alias_pages to return list[AliasPage]
IMO this PR is going too broad for the initial scope. Please keep it simple for now and introduce new features in a new PR. |
- Move templates into Config class as a field * Remove global templates variable * Update all template references to use config.templates - Add pages_dirs to Config class * Remove redundant pages_dirs variable passing * Use config.pages_dirs throughout the code - Move sync_translations logic into main * Remove sync_translations function * Integrate sync logic directly into args.sync block * Simplify code flow for sync operation
- Rename functions and variables * sync -> sync_alias_page_to_locale * existing_page_content -> existing_locale_page_content * locale_page_content -> new_locale_page_content - Remove redundant comments
There is no new feature here, just add an argument to the title and get it as input. |
The three scripts looked almost identical and now they do not anymore. IMO the benefit is minimal ATM. I would prefer fixing the |
The separation of title and commands from options in For example:
|
Fine by me, but change it for all scripts then to keep them sort-of in sync with each other. |
scripts/set-alias-page.py
Outdated
|
||
target_paths = [] | ||
|
||
# Use '--page' option | ||
if args.page != "": | ||
target_paths += get_target_paths(args.page, pages_dirs) | ||
page_info = prompt_alias_page_info(args.page) | ||
target_paths += get_target_paths(args.page, config.pages_dirs) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not working for creating new alias pages. It can only update current alias pages.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
scripts/_common.py
def get_target_paths(page: Path, pages_dirs: Path) -> list[Path]:
"""
Get all paths in all languages that match the page.
Parameters:
page (Path): the page to search for.
Returns:
list (list of Path's): A list of Path's.
"""
target_paths = []
if not page.lower().endswith(".md"):
page = f"{page}.md"
arg_platform, arg_page = page.split("/")
for pages_dir in pages_dirs:
page_path = pages_dir / arg_platform / arg_page
if not page_path.exists():
continue # Skip if page is missing
target_paths.append(page_path)
target_paths.sort()
return target_paths
Looking at these files, I noticed that 8 months ago there was a change to prevent creating new pages. The change was in get_target_paths()
where it skips paths that don't exist.
Is there a specific reason for this change?
From my understanding, the other scripts are designed to modify existing pages
Co-authored-by: Sebastiaan Speck <[email protected]>
The build for this PR failed with the following error(s):
Please fix the error(s) and push again. |
Fixes: #14929
This PR improves the user experience of the
set-alias-page.py
script by adding an interactive wizard and refactoring the sync functionality.Changes
Interactive Wizard
Sync Functionality Refactoring
SyncConfig
andAliasPage
dataclasses for better code organizationBefore
After