|
5 | 5 | import logging
|
6 | 6 | import os
|
7 | 7 |
|
| 8 | +from macaron import MACARON_PATH |
8 | 9 | from macaron.config.defaults import defaults
|
9 |
| -from macaron.config.global_config import global_config |
10 | 10 | from macaron.errors import HeuristicAnalyzerValueError
|
11 | 11 | from macaron.json_tools import JsonType
|
12 | 12 | from macaron.malware_analyzer.pypi_heuristics.base_analyzer import BaseHeuristicAnalyzer
|
@@ -63,7 +63,7 @@ def __init__(self, popular_packages_path: str | None = None) -> None:
|
63 | 63 | super().__init__(
|
64 | 64 | name="typosquatting_presence_analyzer", heuristic=Heuristics.TYPOSQUATTING_PRESENCE, depends_on=None
|
65 | 65 | )
|
66 |
| - self.default_path = os.path.join(global_config.resources_path, "popular_packages.txt") |
| 66 | + self.default_path = os.path.join(MACARON_PATH, "resources/popular_packages.txt") |
67 | 67 | if popular_packages_path:
|
68 | 68 | self.default_path = popular_packages_path
|
69 | 69 | self.popular_packages, self.distance_ratio_threshold, self.keyboard, self.scaling, self.cost = (
|
@@ -98,18 +98,18 @@ def _load_defaults(self) -> tuple[list[str], float, float, float, float]:
|
98 | 98 | cost = section.getfloat("cost", 1.0)
|
99 | 99 |
|
100 | 100 | if not path or not os.path.exists(path):
|
101 |
| - err_msg = "Popular packages file not found or path not configured" |
102 |
| - logger.debug(err_msg) |
103 |
| - raise HeuristicAnalyzerValueError(err_msg) |
| 101 | + error_message = "Popular packages file not found or path not configured" |
| 102 | + logger.debug(error_message) |
| 103 | + raise HeuristicAnalyzerValueError(error_message) |
104 | 104 |
|
105 | 105 | popular_packages_list = []
|
106 | 106 | try:
|
107 | 107 | with open(path, encoding="utf-8") as file:
|
108 | 108 | popular_packages_list = file.read().splitlines()
|
109 | 109 | except OSError as error:
|
110 |
| - err_msg = "Could not read popular packages file" |
111 |
| - logger.debug(err_msg) |
112 |
| - raise HeuristicAnalyzerValueError(err_msg) from error |
| 110 | + error_message = "Could not read popular packages file" |
| 111 | + logger.debug(error_message) |
| 112 | + raise HeuristicAnalyzerValueError(error_message) from error |
113 | 113 |
|
114 | 114 | return (
|
115 | 115 | popular_packages_list,
|
@@ -269,9 +269,9 @@ def analyze(self, pypi_package_json: PyPIPackageJsonAsset) -> tuple[HeuristicRes
|
269 | 269 | The result and related information collected during the analysis.
|
270 | 270 | """
|
271 | 271 | if not self.popular_packages:
|
272 |
| - err_msg = "Popular packages file is empty" |
273 |
| - logger.warning(err_msg) |
274 |
| - return HeuristicResult.SKIP, {"error": err_msg} |
| 272 | + warning_message = "Popular packages file is empty" |
| 273 | + logger.warning(warning_message) |
| 274 | + return HeuristicResult.SKIP, {"error": warning_message} |
275 | 275 |
|
276 | 276 | package_name = pypi_package_json.component_name
|
277 | 277 | for popular_package in self.popular_packages:
|
|
0 commit comments