|
30 | 30 | import os |
31 | 31 | import platform |
32 | 32 | import sys |
33 | | -from importlib import import_module |
34 | 33 | from typing import Optional |
35 | 34 |
|
36 | 35 | import nodescraper |
|
56 | 55 | from nodescraper.pluginregistry import PluginRegistry |
57 | 56 |
|
58 | 57 |
|
59 | | -def discover_external_plugins(): |
60 | | - """Discover ext_nodescraper_plugins from all installed packages. |
61 | | -
|
62 | | - Returns: |
63 | | - list: List of discovered plugin packages |
64 | | - """ |
65 | | - extra_pkgs = [] |
66 | | - seen_paths = set() # Track paths to avoid duplicates |
67 | | - |
68 | | - try: |
69 | | - import ext_nodescraper_plugins as ext_pkg |
70 | | - |
71 | | - extra_pkgs.append(ext_pkg) |
72 | | - if hasattr(ext_pkg, "__file__") and ext_pkg.__file__: |
73 | | - seen_paths.add(ext_pkg.__file__) |
74 | | - except ImportError: |
75 | | - pass |
76 | | - |
77 | | - # Discover ext_nodescraper_plugins from installed packages |
78 | | - try: |
79 | | - from importlib.metadata import distributions |
80 | | - |
81 | | - for dist in distributions(): |
82 | | - pkg_name = dist.metadata.get("Name", "") |
83 | | - if not pkg_name: |
84 | | - continue |
85 | | - |
86 | | - name_variants = [ |
87 | | - pkg_name.replace("-", "_"), |
88 | | - pkg_name.replace("_", "-"), |
89 | | - ] |
90 | | - |
91 | | - try: |
92 | | - top_level = dist.read_text("top_level.txt") |
93 | | - if top_level: |
94 | | - name_variants.extend(top_level.strip().split("\n")) |
95 | | - except Exception: |
96 | | - pass |
97 | | - |
98 | | - for variant in name_variants: |
99 | | - if not variant: |
100 | | - continue |
101 | | - |
102 | | - try: |
103 | | - module_path = f"{variant}.ext_nodescraper_plugins" |
104 | | - ext_pkg = import_module(module_path) |
105 | | - |
106 | | - # Check if we already have this package (by file path) |
107 | | - pkg_path = getattr(ext_pkg, "__file__", None) |
108 | | - if pkg_path and pkg_path in seen_paths: |
109 | | - continue |
110 | | - |
111 | | - # Add the package |
112 | | - extra_pkgs.append(ext_pkg) |
113 | | - if pkg_path: |
114 | | - seen_paths.add(pkg_path) |
115 | | - |
116 | | - break |
117 | | - |
118 | | - except (ImportError, AttributeError, ModuleNotFoundError): |
119 | | - continue |
120 | | - |
121 | | - except Exception: |
122 | | - pass |
123 | | - |
124 | | - return extra_pkgs |
125 | | - |
126 | | - |
127 | | -# Fix sys.path[0] if it's the venv/bin directory to avoid breaking editable install discovery |
128 | | -_original_syspath0 = sys.path[0] |
129 | | -if _original_syspath0.endswith("/bin") or _original_syspath0.endswith("\\Scripts"): |
130 | | - sys.path[0] = "" |
131 | | - |
132 | | -extra_pkgs = discover_external_plugins() |
133 | | - |
134 | | -# Restore original sys.path[0] |
135 | | -sys.path[0] = _original_syspath0 |
136 | | - |
137 | | - |
138 | 58 | def build_parser( |
139 | 59 | plugin_reg: PluginRegistry, |
140 | 60 | config_reg: ConfigRegistry, |
@@ -449,7 +369,7 @@ def main(arg_input: Optional[list[str]] = None): |
449 | 369 | if arg_input is None: |
450 | 370 | arg_input = sys.argv[1:] |
451 | 371 |
|
452 | | - plugin_reg = PluginRegistry(plugin_pkg=extra_pkgs) |
| 372 | + plugin_reg = PluginRegistry() |
453 | 373 |
|
454 | 374 | config_reg = ConfigRegistry() |
455 | 375 | parser, plugin_subparser_map = build_parser(plugin_reg, config_reg) |
|
0 commit comments