Skip to content

🧹 [Code Health] Remove duplicated sys.path boilerplate from Scripts#149

Closed
Ven0m0 wants to merge 1 commit into
mainfrom
code-health-remove-sys-path-boilerplate-4625015370076301560
Closed

🧹 [Code Health] Remove duplicated sys.path boilerplate from Scripts#149
Ven0m0 wants to merge 1 commit into
mainfrom
code-health-remove-sys-path-boilerplate-4625015370076301560

Conversation

@Ven0m0
Copy link
Copy Markdown
Owner

@Ven0m0 Ven0m0 commented Mar 8, 2026

🎯 What: Removed duplicated sys.path modification boilerplate from Python scripts and test files inside Scripts/. Refactored tests to rely on unittest discover paths instead of dynamically injecting directory parents.

💡 Why: Modifying sys.path via boilerplate across many files adds tech debt, confusing module paths, and is unpythonic. By relying on native working directory resolution when executing tests (cd Scripts && python3 -m unittest discover -p 'test_*.py'), we eliminate the duplication and retain local imports seamlessly.

Verification: Verified changes by executing bash run_pre_commit.sh, validating linting and formats via uv run ruff check / uv run ruff format, and ensuring the exact test suite output identically matched execution before the sys.path changes.

Result: A cleaner codebase absent of repetitive file path inspection and sys path injections.


PR created automatically by Jules for task 4625015370076301560 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:35
@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 is currently in state closed (PR closed manually).


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 codebase's health by eliminating duplicated sys.path manipulation across multiple Python scripts and their corresponding test files. The change streamlines module imports by relying on standard Python mechanisms and unittest discover's inherent capabilities, leading to a more maintainable and Pythonic structure. The refactoring ensures that local imports function seamlessly without manual path adjustments.

Highlights

  • Code Health Improvement: Removed redundant sys.path modification boilerplate from Python scripts and test files within the Scripts/ directory.
  • Test Refactoring: Refactored test files to leverage unittest discover's native path resolution, eliminating the need for dynamic sys.path injections.
  • Codebase Cleanliness: Achieved a cleaner codebase by removing repetitive file path inspection and system path injections, reducing technical debt.
Changelog
  • Scripts/deduplicate.py
    • Removed the boilerplate code that dynamically added the current directory to sys.path.
  • Scripts/move-pure-domains.py
    • Removed the boilerplate code that dynamically added the current directory to sys.path.
  • Scripts/test_common.py
    • Removed the import sys statement.
    • Removed the boilerplate code that dynamically added the current directory to sys.path.
  • Scripts/test_deduplicate.py
    • Removed import sys and from pathlib import Path statements.
    • Removed the boilerplate code that dynamically added the current directory to sys.path.
  • Scripts/test_is_pure_domain_logic.py
    • Removed import sys and from pathlib import Path statements.
    • Removed the boilerplate code that dynamically added the Scripts directory to sys.path.
  • Scripts/test_update_lists.py
    • Updated the importlib.util.spec_from_file_location call to construct the module path using Path(__file__).parent / "update-lists.py" for better clarity and robustness.
  • Scripts/update-lists.py
    • Removed the boilerplate code that dynamically added the current directory to sys.path.
Activity
  • PR created automatically by Jules for task 4625015370076301560, initiated by @Ven0m0.
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 8 minutes and 7 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: 92c8aa9d-490f-4efd-989c-7615edd43c62

📥 Commits

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

📒 Files selected for processing (7)
  • Scripts/deduplicate.py
  • Scripts/move-pure-domains.py
  • Scripts/test_common.py
  • Scripts/test_deduplicate.py
  • Scripts/test_is_pure_domain_logic.py
  • Scripts/test_update_lists.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-remove-sys-path-boilerplate-4625015370076301560

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.

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

Removes repetitive sys.path manipulation in Scripts/ Python scripts and tests, relying instead on the existing unittest discover Scripts/ ... invocation and normal script execution semantics for local imports.

Changes:

  • Removed sys.path boilerplate from multiple Python scripts/tests under Scripts/.
  • Updated test_update_lists.py to load update-lists.py via a path relative to the test file.
  • Simplified several test modules by dropping now-unneeded imports (sys, Path) tied to the removed sys.path logic.

Reviewed changes

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

Show a summary per file
File Description
Scripts/update-lists.py Removes local sys.path injection before importing common.
Scripts/test_update_lists.py Loads update-lists.py using Path(__file__).parent for robust path resolution.
Scripts/test_is_pure_domain_logic.py Removes sys.path setup and related imports at the top of the test.
Scripts/test_deduplicate.py Removes sys.path setup and related imports.
Scripts/test_common.py Removes sys.path setup and related imports.
Scripts/move-pure-domains.py Removes local sys.path injection before importing common.
Scripts/deduplicate.py Removes local sys.path injection before importing common.

Comment thread Scripts/deduplicate.py
Comment on lines 16 to 18
# Add current directory to path to allow importing common if run from elsewhere
if str(Path(__file__).parent) not in sys.path:
sys.path.append(str(Path(__file__).parent))

from common import is_valid_domain, write_lines
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.

The comment about adding the script directory to sys.path is now stale since the sys.path modification was removed. Please remove or update this comment to avoid misleading future readers.

Copilot uses AI. Check for mistakes.
Comment on lines 3 to 5
# Add current directory to path to allow importing deduplicate
if str(Path(__file__).parent) not in sys.path:
sys.path.append(str(Path(__file__).parent))

from deduplicate import process_content
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.

This comment indicates the test adjusts sys.path, but that code was removed. Please delete or reword the comment so it matches the current import strategy (relying on unittest discover adding Scripts/ to sys.path).

Copilot uses AI. Check for mistakes.
Comment thread Scripts/test_common.py
Comment on lines 5 to 7
# Add current directory to path
if str(Path(__file__).parent) not in sys.path:
sys.path.append(str(Path(__file__).parent))

from common import sanitize_filename, is_valid_domain, is_adguard_rule
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.

The "Add current directory to path" comment is now inaccurate after removing the sys.path modification. Please remove/update it to prevent confusion about how common is imported in tests.

Copilot uses AI. Check for mistakes.
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 pull request correctly removes boilerplate sys.path modifications from several Python scripts, which is a good code health improvement. My review includes a few suggestions to also remove the now-misleading or orphaned comments associated with the removed code to complete the cleanup.

I am having trouble creating individual review comments. Click here to see my feedback.

Scripts/deduplicate.py (17-18)

medium

While removing this sys.path modification is correct, the comment on line 16 (# Add current directory to path to allow importing common if run from elsewhere) is now misleading and should also be removed as part of this code health improvement.

Scripts/test_common.py (7-8)

medium

This sys.path modification is correctly removed. However, the comment on line 6 (# Add current directory to path) is now orphaned and should also be removed.

Scripts/test_deduplicate.py (6-7)

medium

This sys.path modification is correctly removed. However, the comment on line 5 (# Add current directory to path to allow importing deduplicate) is now orphaned and should also be removed.

Comment thread Scripts/test_common.py
from pathlib import Path
import hashlib

# Add current directory to path
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.

WARNING: Orphaned comment - the sys.path manipulation code this comment referred to has been removed. This comment is now misleading and should be removed.

import sys
from pathlib import Path

# Add current directory to path to allow importing deduplicate
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.

WARNING: Orphaned comment - the sys.path manipulation code this comment referred to has been removed. This comment is now misleading and should be removed.

@kilo-code-bot
Copy link
Copy Markdown
Contributor

kilo-code-bot Bot commented Mar 8, 2026

Code Review Summary

Status: 1 Critical Issue Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 1
WARNING 0
SUGGESTION 0
Issue Details (click to expand)

CRITICAL

File Line Issue
Scripts/deduplicate.py 17-18 (removed) Scripts will fail when run as documented - The README documents running scripts as python3 Scripts/deduplicate.py, but after removing the sys.path manipulation, these scripts will fail with ModuleNotFoundError: No module named 'common'. When Python runs Scripts/deduplicate.py, it adds the current directory (project root) to sys.path, but common.py is in the Scripts/ subdirectory. The removed code added Scripts/ to sys.path to resolve this. This affects: deduplicate.py, move-pure-domains.py, and update-lists.py.
Inline Comments Posted
  • Scripts/test_common.py:5 - Orphaned comment warning
  • Scripts/test_deduplicate.py:3 - Orphaned comment warning
Files Reviewed (7 files)
  • Scripts/deduplicate.py - 1 critical issue
  • Scripts/move-pure-domains.py - inherits critical issue
  • Scripts/update-lists.py - inherits critical issue
  • Scripts/test_common.py - 1 warning (orphaned comment)
  • Scripts/test_deduplicate.py - 1 warning (orphaned comment)
  • Scripts/test_is_pure_domain_logic.py - no issues
  • Scripts/test_update_lists.py - improvement (better path handling)

Recommendation: The sys.path manipulation should either be:

  1. Kept in the main scripts (deduplicate.py, move-pure-domains.py, update-lists.py), OR
  2. The README and any CI that runs these scripts should be updated to use python3 -m deduplicate from the project root with proper PYTHONPATH setup

The tests don't need the sys.path manipulation since they run via python3 -m unittest discover which handles paths automatically.

@Ven0m0 Ven0m0 closed this Mar 9, 2026
@Ven0m0 Ven0m0 deleted the code-health-remove-sys-path-boilerplate-4625015370076301560 branch March 9, 2026 05:18
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