diff --git a/Scripts/__init__.py b/Scripts/__init__.py new file mode 100644 index 0000000..3cd96c8 --- /dev/null +++ b/Scripts/__init__.py @@ -0,0 +1,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)) diff --git a/Scripts/deduplicate.py b/Scripts/deduplicate.py index 4f1a5a1..3ed6806 100755 --- a/Scripts/deduplicate.py +++ b/Scripts/deduplicate.py @@ -13,9 +13,6 @@ 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 diff --git a/Scripts/move-pure-domains.py b/Scripts/move-pure-domains.py index bc6dd89..a7bc951 100644 --- a/Scripts/move-pure-domains.py +++ b/Scripts/move-pure-domains.py @@ -9,8 +9,6 @@ from collections import defaultdict # Import common utilities -if str(Path(__file__).parent) not in sys.path: - sys.path.append(str(Path(__file__).parent)) from common import is_valid_domain, read_lines, write_lines diff --git a/Scripts/test_common.py b/Scripts/test_common.py index 86e8ef1..1cae1ba 100644 --- a/Scripts/test_common.py +++ b/Scripts/test_common.py @@ -3,9 +3,6 @@ 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 @@ -68,9 +65,9 @@ def test_sanitize_filename_without_name_special_urls(self): # URL with port url = "http://example.com:8080/list.txt" filename = sanitize_filename(url) - self.assertTrue(filename.startswith("example-com:8080-")) + self.assertTrue(filename.startswith("example-com-8080-")) expected_hash = hashlib.sha256(url.encode("utf-8")).hexdigest()[:12] - self.assertEqual(filename, f"example-com:8080-{expected_hash}.txt") + self.assertEqual(filename, f"example-com-8080-{expected_hash}.txt") def test_is_valid_domain(self): self.assertTrue(is_valid_domain("example.com")) diff --git a/Scripts/test_deduplicate.py b/Scripts/test_deduplicate.py index 5e8c577..2ade88d 100644 --- a/Scripts/test_deduplicate.py +++ b/Scripts/test_deduplicate.py @@ -2,9 +2,6 @@ import sys from pathlib import Path -# 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 diff --git a/Scripts/test_is_pure_domain_logic.py b/Scripts/test_is_pure_domain_logic.py index 7dc4ad8..c88da48 100644 --- a/Scripts/test_is_pure_domain_logic.py +++ b/Scripts/test_is_pure_domain_logic.py @@ -3,10 +3,6 @@ from pathlib import Path import importlib -# Add Scripts to path -scripts_dir = Path(__file__).parent -if str(scripts_dir) not in sys.path: - sys.path.append(str(scripts_dir)) # Import ADGUARD_INDICATORS from common from common import ADGUARD_INDICATORS diff --git a/Scripts/update-lists.py b/Scripts/update-lists.py index 6bc4d15..fda7dba 100644 --- a/Scripts/update-lists.py +++ b/Scripts/update-lists.py @@ -21,8 +21,6 @@ import aiofiles # Import common utilities -if str(Path(__file__).parent) not in sys.path: - sys.path.append(str(Path(__file__).parent)) from common import sanitize_filename