Skip to content

🧹 [code health] Centralize sys.path modifications#147

Merged
Ven0m0 merged 1 commit into
mainfrom
code-health-sys-path-fix-10027454394505962663
Mar 8, 2026
Merged

🧹 [code health] Centralize sys.path modifications#147
Ven0m0 merged 1 commit into
mainfrom
code-health-sys-path-fix-10027454394505962663

Conversation

@Ven0m0
Copy link
Copy Markdown
Owner

@Ven0m0 Ven0m0 commented Mar 8, 2026

🎯 What: The duplicated sys.path.append boilerplate across 6 python scripts in the Scripts/ directory was removed. A single Scripts/__init__.py file was created to handle injecting the package directory into sys.path. A failing test in Scripts/test_common.py regarding filename colons replacement was also fixed to properly expect hyphens.

💡 Why: Modifying sys.path dynamically in every file creates unnecessary duplication and reduces readability. By creating an __init__.py and converting the folder into a python package, the Python import system automatically handles module resolution during unittest discover. When executing scripts directly (e.g. python Scripts/update-lists.py), the sys.path already includes the execution directory, making the boilerplate redundant.

Verification: I ran python3 -m unittest discover Scripts/ 'test_*.py' and verified all 28 tests pass successfully. I also ran direct script execution such as python3 Scripts/test_common.py to ensure standalone execution works natively without the boilerplate.

Result: Improved maintainability, cleaner code, and 1 failing test fixed.


PR created automatically by Jules for task 10027454394505962663 started by @Ven0m0

Co-authored-by: Ven0m0 <82972344+Ven0m0@users.noreply.github.com>
@google-labs-jules
Copy link
Copy Markdown
Contributor

👋 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 @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

Copilot AI review requested due to automatic review settings March 8, 2026 09:32
@aviator-app
Copy link
Copy Markdown

aviator-app Bot commented Mar 8, 2026

Current Aviator status

Aviator will automatically update this comment as the status of the PR changes.
Comment /aviator refresh to force Aviator to re-examine your PR (or learn about other /aviator commands).

This PR was merged manually (without Aviator). Merging manually can negatively impact the performance of the queue. Consider using Aviator next time.


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.

@chatgpt-codex-connector
Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, 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 health of the Scripts/ directory by centralizing Python's module path management. By converting the Scripts/ directory into a Python package and moving sys.path modifications to __init__.py, it removes repetitive code and streamlines module imports for both testing and direct script execution. Additionally, a minor bug in a test case for filename sanitization has been resolved.

Highlights

  • Centralized sys.path management: Consolidated sys.path modifications into a new Scripts/__init__.py file, eliminating redundant boilerplate across multiple scripts.
  • Boilerplate removal: Removed duplicated sys.path.append logic from six Python scripts, enhancing code readability and maintainability.
  • Test fix: Corrected a failing test in Scripts/test_common.py related to filename sanitization, specifically for URLs containing colons.
Changelog
  • Scripts/init.py
    • Added a new file to manage sys.path by inserting the Scripts directory at the beginning of the path.
  • Scripts/deduplicate.py
    • Removed the local sys.path.append boilerplate.
  • Scripts/move-pure-domains.py
    • Removed the local sys.path.append boilerplate.
  • Scripts/test_common.py
    • Removed the local sys.path.append boilerplate.
    • Updated test assertions for sanitize_filename to expect hyphens instead of colons in sanitized URLs with ports.
  • Scripts/test_deduplicate.py
    • Removed the local sys.path.append boilerplate.
  • Scripts/test_is_pure_domain_logic.py
    • Removed the local sys.path.append boilerplate.
  • Scripts/update-lists.py
    • Removed the local sys.path.append boilerplate.
Activity
  • The author verified that all 28 tests pass successfully by running python3 -m unittest discover Scripts/ 'test_*.py'.
  • The author confirmed standalone script execution works natively without boilerplate by running python3 Scripts/test_common.py.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Mar 8, 2026

Warning

Rate limit exceeded

@Ven0m0 has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 11 minutes and 16 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 2bccaf66-ec5b-46b9-aac5-625b4191af46

📥 Commits

Reviewing files that changed from the base of the PR and between 7ae0716 and 32e6beb.

📒 Files selected for processing (7)
  • Scripts/__init__.py
  • Scripts/deduplicate.py
  • Scripts/move-pure-domains.py
  • Scripts/test_common.py
  • Scripts/test_deduplicate.py
  • Scripts/test_is_pure_domain_logic.py
  • Scripts/update-lists.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch code-health-sys-path-fix-10027454394505962663

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@kilo-code-bot
Copy link
Copy Markdown
Contributor

kilo-code-bot Bot commented Mar 8, 2026

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Files Reviewed (7 files)
  • Scripts/__init__.py - New file: centralizes sys.path management
  • Scripts/deduplicate.py - Removed redundant sys.path boilerplate
  • Scripts/move-pure-domains.py - Removed redundant sys.path boilerplate
  • Scripts/test_common.py - Removed redundant sys.path boilerplate, fixed test to match actual sanitize_filename behavior
  • Scripts/test_deduplicate.py - Removed redundant sys.path boilerplate
  • Scripts/test_is_pure_domain_logic.py - Removed redundant sys.path boilerplate
  • Scripts/update-lists.py - Removed redundant sys.path boilerplate

Analysis

This is a clean refactoring PR that:

  1. Adds Scripts/__init__.py - A proper Python package initialization file that adds the scripts directory to sys.path, enabling clean imports without manual path manipulation

  2. Removes redundant boilerplate - Six Python files had duplicate sys.path.append logic that is now handled centrally by __init__.py

  3. Fixes test assertion - The test for sanitize_filename was updated to expect hyphens instead of colons for URL ports, matching the actual implementation in common.py:71 which has .replace(":", "-")

No security concerns, no runtime errors, and no logic bugs detected. The changes improve code maintainability by centralizing module path management.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This is a great code health improvement. Centralizing the sys.path modification into Scripts/__init__.py effectively removes boilerplate from multiple scripts and improves maintainability by making the Scripts directory a proper Python package. The fix to the failing test in test_common.py is also correct. I have one minor suggestion to make the new path handling even more robust.

Comment thread Scripts/__init__.py
@@ -0,0 +1,5 @@
import sys
from pathlib import Path
scripts_dir = Path(__file__).parent
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

For greater robustness, it's a good practice to resolve the path to an absolute path before adding it to sys.path. This ensures that you're always working with a canonical path, which prevents potential issues related to the current working directory, relative paths, or symlinks.

Suggested change
scripts_dir = Path(__file__).parent
scripts_dir = Path(__file__).parent.resolve()

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR reduces duplicated Python import-path bootstrapping in Scripts/ by removing per-file sys.path manipulation and updates a filename-sanitization test to match current behavior.

Changes:

  • Removed repeated sys.path.append(...) setup from multiple Scripts/*.py scripts and tests.
  • Added Scripts/__init__.py intended to centralize sys.path handling.
  • Fixed Scripts/test_common.py to expect ports to be sanitized with - (not :) in generated filenames.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
Scripts/update-lists.py Removes local sys.path bootstrapping before importing common.
Scripts/move-pure-domains.py Removes local sys.path bootstrapping before importing common.
Scripts/deduplicate.py Removes local sys.path bootstrapping before importing common.
Scripts/test_common.py Removes local sys.path bootstrapping; fixes expected sanitized filename for URLs with ports.
Scripts/test_deduplicate.py Removes local sys.path bootstrapping for test imports.
Scripts/test_is_pure_domain_logic.py Removes local sys.path bootstrapping for test imports.
Scripts/init.py Adds package initializer that mutates sys.path to include Scripts/.

Comment on lines 1 to 5
import unittest
import sys
from pathlib import Path
import importlib

Copy link

Copilot AI Mar 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After removing the sys.path bootstrap, sys and Path are unused in this test module. Please remove the unused imports so ruff/linters don’t flag F401 and to reduce noise.

Copilot uses AI. Check for mistakes.
Comment thread Scripts/__init__.py
Comment on lines +1 to +5
import sys
from pathlib import Path
scripts_dir = Path(__file__).parent
if str(scripts_dir) not in sys.path:
sys.path.insert(0, str(scripts_dir))
Copy link

Copilot AI Mar 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Scripts/init.py introduces a side-effectful sys.path mutation (inserting the Scripts dir at index 0). This can unexpectedly shadow/import the wrong modules (e.g., a third-party common module) and can also lead to duplicate module loads (common vs Scripts.common) if anything ever imports the package. Also, for the stated invocation python -m unittest discover Scripts ..., this init.py is typically not imported at all (tests are imported as top-level modules), so it likely doesn’t achieve the intended centralization. Prefer removing this sys.path injection (and possibly the file), or switching scripts/tests to package/relative imports (e.g., from .common ... / from Scripts.common ...) and running them via python -m when needed.

Suggested change
import sys
from pathlib import Path
scripts_dir = Path(__file__).parent
if str(scripts_dir) not in sys.path:
sys.path.insert(0, str(scripts_dir))
"""Package initializer for the Scripts module.
This file is intentionally kept free of side effects such as mutating
sys.path. Importers should rely on standard Python packaging and
relative imports instead of path manipulation.
"""

Copilot uses AI. Check for mistakes.
Comment thread Scripts/test_common.py
Comment on lines 1 to 4
import unittest
import sys
from pathlib import Path
import hashlib
Copy link

Copilot AI Mar 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After removing the sys.path bootstrap code, sys and Path are no longer used in this test file. Please drop these unused imports to avoid ruff/linters failing on F401 and to keep the tests minimal.

Copilot uses AI. Check for mistakes.
Comment on lines 2 to 3
import sys
from pathlib import Path
Copy link

Copilot AI Mar 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After removing the sys.path bootstrap, sys and Path are no longer used here. Please remove the unused imports to avoid ruff/linters reporting F401 and to keep the test focused.

Suggested change
import sys
from pathlib import Path

Copilot uses AI. Check for mistakes.
@Ven0m0 Ven0m0 merged commit 257e085 into main Mar 8, 2026
16 of 19 checks passed
@Ven0m0 Ven0m0 deleted the code-health-sys-path-fix-10027454394505962663 branch March 8, 2026 09:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants