fix(ci): evitar erro de config no workflow de geração - #3
Conversation
Summary of ChangesHello @pedromendes-dev, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! Este pull request aprimora a resiliência do script de geração ao carregar arquivos de configuração, especialmente no modo de demonstração. Anteriormente, o modo demo falharia se o arquivo Highlights
Changelog
Ignored Files
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
Este pull request melhora a robustez do modo de demonstração (--demo) ao permitir um fallback para config.yml se config.example.yml não for encontrado. A lógica de carregamento de configuração foi refatorada para ser mais clara e as mensagens de ajuda foram atualizadas para refletir essa mudança. Adicionalmente, a especificação explícita de encoding='utf-8' ao abrir o arquivo de configuração é uma boa prática que evita possíveis problemas de codificação em diferentes sistemas.
Minha única sugestão é modernizar o tratamento de caminhos de arquivo usando o módulo pathlib, que pode tornar o código um pouco mais legível e conciso.
| root_dir = os.path.join(os.path.dirname(__file__), "..") | ||
| if demo: | ||
| config_path = os.path.join(os.path.dirname(__file__), "..", "config.example.yml") | ||
| config_candidates = [ | ||
| os.path.join(root_dir, "config.example.yml"), | ||
| os.path.join(root_dir, "config.yml"), | ||
| ] | ||
| else: | ||
| config_path = os.path.join(os.path.dirname(__file__), "..", "config.yml") | ||
| config_candidates = [os.path.join(root_dir, "config.yml")] | ||
|
|
||
| try: | ||
| with open(config_path, "r") as f: | ||
| config = yaml.safe_load(f) | ||
| except FileNotFoundError: | ||
| config_path = next((path for path in config_candidates if os.path.exists(path)), None) | ||
| if config_path is None: | ||
| if demo: | ||
| logger.error("config.example.yml not found.") | ||
| logger.error("Neither config.example.yml nor config.yml was found.") | ||
| else: | ||
| logger.error("config.yml not found. Copy config.example.yml to config.yml and edit it.") | ||
| sys.exit(1) | ||
|
|
||
| if demo and config_path.endswith("config.yml"): | ||
| logger.info("Demo mode: config.example.yml not found, falling back to config.yml.") | ||
|
|
||
| with open(config_path, "r", encoding="utf-8") as f: | ||
| config = yaml.safe_load(f) |
There was a problem hiding this comment.
Para melhorar a legibilidade e modernizar o código, você poderia considerar o uso do módulo pathlib para manipulação de caminhos de arquivo. Ele oferece uma API orientada a objetos que é geralmente mais intuitiva do que os.path.
Isso tornaria a definição de root_dir, a construção de caminhos candidatos e as verificações de existência um pouco mais limpas.
Não se esqueça de adicionar from pathlib import Path no início do arquivo.
root_dir = Path(__file__).parent.parent
if demo:
config_candidates = [
root_dir / "config.example.yml",
root_dir / "config.yml",
]
else:
config_candidates = [root_dir / "config.yml"]
config_path = next((path for path in config_candidates if path.exists()), None)
if config_path is None:
if demo:
logger.error("Neither config.example.yml nor config.yml was found.")
else:
logger.error("config.yml not found. Copy config.example.yml to config.yml and edit it.")
sys.exit(1)
if demo and config_path.name == "config.yml":
logger.info("Demo mode: config.example.yml not found, falling back to config.yml.")
with config_path.open("r", encoding="utf-8") as f:
config = yaml.safe_load(f)|
Patch validado localmente e também no fork (workflow Generate Profile SVGs com conclusion=success). O PR está CLEAN e pronto para merge. Assim que fizerem merge, a main já fica com a correção de fallback de config no modo demo + comando explícito no workflow. |
Resumo
Validação