-
Notifications
You must be signed in to change notification settings - Fork 0
🧹 [code health improvement] remove sys.path boilerplate in Scripts by converting to python package #150
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -13,11 +13,7 @@ | |||||||||||
| from dataclasses import dataclass | ||||||||||||
| from collections.abc import Iterable | ||||||||||||
|
|
||||||||||||
| # 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 | ||||||||||||
| from Scripts.common import is_valid_domain, write_lines | ||||||||||||
|
||||||||||||
| from Scripts.common import is_valid_domain, write_lines | |
| try: | |
| from Scripts.common import is_valid_domain, write_lines | |
| except ModuleNotFoundError: | |
| from common import is_valid_domain, write_lines |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,11 +3,7 @@ | |
| from pathlib import Path | ||
| import hashlib | ||
|
|
||
| # 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 | ||
| from Scripts.common import sanitize_filename, is_valid_domain, is_adguard_rule | ||
|
|
||
|
|
||
| class TestCommon(unittest.TestCase): | ||
|
|
@@ -89,7 +85,7 @@ def test_is_adguard_rule(self): | |
|
|
||
| def test_write_lines_atomic(self): | ||
| import tempfile | ||
| from common import write_lines | ||
| from Scripts.common import write_lines | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
|
||
| with tempfile.TemporaryDirectory() as temp_dir: | ||
| temp_dir_path = Path(temp_dir) | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -2,11 +2,7 @@ | |||||
| import sys | ||||||
| from pathlib import Path | ||||||
|
Comment on lines
2
to
3
|
||||||
| import sys | |
| from pathlib import Path |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,7 +4,7 @@ | |
| from unittest.mock import Mock, mock_open | ||
|
|
||
| # Import the module dynamically | ||
| file_path = Path(__file__).parent / "move-pure-domains.py" | ||
| file_path = Path(__file__).parent / "move_pure_domains.py" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| spec = importlib.util.spec_from_file_location("move_pure_domains", file_path) | ||
| if spec is None or spec.loader is None: | ||
| raise ImportError("Could not load module") | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -20,7 +20,7 @@ class ClientError(Exception): | |||||||
| sys.modules["aiohttp"] = aiohttp_mock | ||||||||
| sys.modules["aiofiles"] = MagicMock() | ||||||||
|
|
||||||||
| spec = importlib.util.spec_from_file_location("update_lists", "Scripts/update-lists.py") | ||||||||
| spec = importlib.util.spec_from_file_location("update_lists", "Scripts/update_lists.py") | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This dynamic import and the
|
||||||||
| spec = importlib.util.spec_from_file_location("update_lists", "Scripts/update_lists.py") | |
| module_path = Path(__file__).parent / "update_lists.py" | |
| spec = importlib.util.spec_from_file_location("update_lists", module_path) |
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.
With
PYTHONSAFEPATH: 1set for the job,python -m Scripts.update_listsmay not be able to import the localScriptspackage unless the repo root is explicitly onsys.path(e.g. via installing the project into the venv or settingPYTHONPATH=$GITHUB_WORKSPACE). If this step fails withNo module named Scripts, consider unsettingPYTHONSAFEPATHfor this step, addingPYTHONPATH, or ensuringuv syncinstalls the project/package so the module is found in site-packages.