|
58 | 58 |
|
59 | 59 | def discover_external_plugins(): |
60 | 60 | """Discover ext_nodescraper_plugins from all installed packages. |
61 | | - |
| 61 | +
|
62 | 62 | Returns: |
63 | 63 | list: List of discovered plugin packages |
64 | 64 | """ |
65 | 65 | extra_pkgs = [] |
66 | 66 | seen_paths = set() # Track paths to avoid duplicates |
67 | | - |
| 67 | + |
68 | 68 | try: |
69 | 69 | import ext_nodescraper_plugins as ext_pkg |
| 70 | + |
70 | 71 | extra_pkgs.append(ext_pkg) |
71 | | - if hasattr(ext_pkg, '__file__') and ext_pkg.__file__: |
| 72 | + if hasattr(ext_pkg, "__file__") and ext_pkg.__file__: |
72 | 73 | seen_paths.add(ext_pkg.__file__) |
73 | 74 | except ImportError: |
74 | 75 | pass |
75 | | - |
| 76 | + |
76 | 77 | # Discover ext_nodescraper_plugins from installed packages |
77 | 78 | try: |
78 | 79 | from importlib.metadata import distributions |
79 | | - |
| 80 | + |
80 | 81 | for dist in distributions(): |
81 | | - pkg_name = dist.metadata.get('Name', '') |
| 82 | + pkg_name = dist.metadata.get("Name", "") |
82 | 83 | if not pkg_name: |
83 | 84 | continue |
84 | | - |
| 85 | + |
85 | 86 | name_variants = [ |
86 | | - pkg_name.replace('-', '_'), |
87 | | - pkg_name.replace('_', '-'), |
| 87 | + pkg_name.replace("-", "_"), |
| 88 | + pkg_name.replace("_", "-"), |
88 | 89 | ] |
89 | | - |
| 90 | + |
90 | 91 | try: |
91 | | - top_level = dist.read_text('top_level.txt') |
| 92 | + top_level = dist.read_text("top_level.txt") |
92 | 93 | if top_level: |
93 | | - name_variants.extend(top_level.strip().split('\n')) |
| 94 | + name_variants.extend(top_level.strip().split("\n")) |
94 | 95 | except Exception: |
95 | 96 | pass |
96 | | - |
| 97 | + |
97 | 98 | for variant in name_variants: |
98 | 99 | if not variant: |
99 | 100 | continue |
100 | | - |
| 101 | + |
101 | 102 | try: |
102 | 103 | module_path = f"{variant}.ext_nodescraper_plugins" |
103 | 104 | ext_pkg = import_module(module_path) |
104 | | - |
| 105 | + |
105 | 106 | # Check if we already have this package (by file path) |
106 | | - pkg_path = getattr(ext_pkg, '__file__', None) |
| 107 | + pkg_path = getattr(ext_pkg, "__file__", None) |
107 | 108 | if pkg_path and pkg_path in seen_paths: |
108 | 109 | continue |
109 | | - |
| 110 | + |
110 | 111 | # Add the package |
111 | 112 | extra_pkgs.append(ext_pkg) |
112 | 113 | if pkg_path: |
113 | 114 | seen_paths.add(pkg_path) |
114 | | - |
| 115 | + |
115 | 116 | break |
116 | | - |
| 117 | + |
117 | 118 | except (ImportError, AttributeError, ModuleNotFoundError): |
118 | 119 | continue |
119 | | - |
| 120 | + |
120 | 121 | except Exception: |
121 | 122 | pass |
122 | | - |
| 123 | + |
123 | 124 | return extra_pkgs |
124 | 125 |
|
125 | 126 |
|
|
0 commit comments