🧹 Refactor main function complexity in cia_3ds_decryptor.py#226
🧹 Refactor main function complexity in cia_3ds_decryptor.py#226
Conversation
Extracted logic from the main function into several smaller, modular helper functions: - initialize_tools - sanitize_filenames - get_file_counts - ask_for_conversion - run_decryption - run_conversion - display_summary This improves readability and maintainability while preserving the original functionality and sequence of operations. Verified with existing tests and ruff. Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
Current Aviator status
This pull request is currently open (not queued). How to mergeTo merge this PR, comment
See the real-time status of this PR on the
Aviator webapp.
Use the Aviator Chrome Extension
to see the status of your PR within GitHub.
|
Summary of ChangesHello, 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! This pull request significantly improves the code quality of the Highlights
Changelog
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
|
|
❌ Lint/Format Check Failed Please run |
Code Review SummaryStatus: No Issues Found | Recommendation: Merge Files Reviewed (1 file)
This PR is a clean refactoring that extracts the monolithic
The boolean return from Reviewed by minimax-m2.5 · 126,920 tokens |
There was a problem hiding this comment.
Code Review
This pull request effectively refactors the main function in cia_3ds_decryptor.py, significantly improving its readability and maintainability by breaking down a large monolithic function into smaller, focused helper functions. The new structure makes the script's execution flow much clearer. I have one suggestion to further improve the error logging in one of the new helper functions.
| banner() | ||
| print(" Decrypting...\n") | ||
| futures = {} | ||
| with concurrent.futures.ThreadPoolExecutor() as executor: | ||
| if cnt.count_3ds: | ||
| logging.info( | ||
| "[i] Found %d 3DS file(s). Start decrypting...", cnt.count_3ds | ||
| ) | ||
| logging.info("[i] Found %d 3DS file(s). Start decrypting...", cnt.count_3ds) | ||
| for f in sorted(root.glob("*.3ds")): | ||
| future = executor.submit( | ||
| process_file_task, decrypt_3ds, root, f, tools_list, seeddb | ||
| ) | ||
| futures[future] = "3ds" | ||
|
|
||
| if cnt.count_cia: | ||
| logging.info( | ||
| "[i] Found %d CIA file(s). Start decrypting...", cnt.count_cia | ||
| ) | ||
| logging.info("[i] Found %d CIA file(s). Start decrypting...", cnt.count_cia) | ||
| for f in sorted(root.glob("*.cia")): | ||
| future = executor.submit( | ||
| process_file_task, decrypt_cia, root, f, tools_list, seeddb | ||
| ) | ||
| futures[future] = "cia" | ||
|
|
||
| # Wait for completion and accumulate results | ||
| for future in concurrent.futures.as_completed(futures): | ||
| task_type = futures.get(future) | ||
| try: | ||
| result_cnt = future.result() | ||
| cnt += result_cnt | ||
| except Exception as e: | ||
| logging.error("Task failed with exception: %s", e) | ||
| # Update error counts so failed tasks are reflected in statistics | ||
| if task_type == "3ds": | ||
| cnt.ds_err += 1 | ||
| elif task_type == "cia": | ||
| cnt.cia_err += 1 | ||
| # If task_type is None or unrecognized, we intentionally do not guess | ||
| if cnt.convert_to_cci: | ||
| logging.info("[i] Starting parallel CCI conversion...") | ||
| conv_futures = {} | ||
| with concurrent.futures.ThreadPoolExecutor() as executor: | ||
| for f in sorted(root.glob("*-decrypted.cia")): | ||
| future = executor.submit( | ||
| process_conversion_task, root, f, tools_list, seeddb | ||
| return cnt |
There was a problem hiding this comment.
The error handling in run_decryption could be improved for better diagnostics. When a task fails with an exception, the current implementation logs the exception but doesn't specify which file failed. This is because the futures dictionary only stores the task type ('3ds' or 'cia').
To provide more context, you can store both the task type and the filename in the futures dictionary, similar to how run_conversion stores the filename. This will allow you to log the specific file that caused the error, making debugging much easier.
banner()
print(" Decrypting...\n")
futures = {}
with concurrent.futures.ThreadPoolExecutor() as executor:
if cnt.count_3ds:
logging.info("[i] Found %d 3DS file(s). Start decrypting...", cnt.count_3ds)
for f in sorted(root.glob("*.3ds")):
future = executor.submit(
process_file_task, decrypt_3ds, root, f, tools_list, seeddb
)
futures[future] = ("3ds", f.name)
if cnt.count_cia:
logging.info("[i] Found %d CIA file(s). Start decrypting...", cnt.count_cia)
for f in sorted(root.glob("*.cia")):
future = executor.submit(
process_file_task, decrypt_cia, root, f, tools_list, seeddb
)
futures[future] = ("cia", f.name)
for future in concurrent.futures.as_completed(futures):
task_type, filename = futures.get(future, (None, "unknown file"))
try:
result_cnt = future.result()
cnt += result_cnt
except Exception as e:
logging.error("Task for file '%s' failed with exception: %s", filename, e)
if task_type == "3ds":
cnt.ds_err += 1
elif task_type == "cia":
cnt.cia_err += 1
return cntThere was a problem hiding this comment.
Pull request overview
This PR refactors the monolithic main() function in cia_3ds_decryptor.py into 7 focused helper functions: initialize_tools, sanitize_filenames, get_file_counts, ask_for_conversion, run_decryption, run_conversion, and display_summary. The resulting main() is a clear, linear orchestrator.
Changes:
- Extracted 7 helper functions from the original
main(), each with a single responsibility and proper type annotations/docstrings. - Moved the "no files found" early-return logic into the new
main()orchestrator (previously inline). - Minor formatting cleanup: collapsed multi-line
logging.infocalls into single lines and removed inline comments.
You can also share your feedback on Copilot code review. Take the survey.
This PR addresses the high complexity of the
mainfunction inCachyos/Scripts/WIP/emu/cia_3ds_decryptor.py.🎯 What: The
mainfunction was a long, monolithic block of code handling multiple responsibilities. I refactored it into 7 focused helper functions.💡 Why: Smaller functions are easier to understand, test, and maintain. It also makes the high-level logic of the script clear at a glance in the
mainorchestrator.✅ Verification:
python3 -m py_compile.python3 Cachyos/Scripts/WIP/emu/test_decryptor_counters.py.ruff check.✨ Result: Improved code health and reduced cognitive load for future maintainers.
PR created automatically by Jules for task 1313614530380434342 started by @Ven0m0