|
1 |
| -# Copyright 2021 MONAI Consortium |
| 1 | +# Copyright 2021-2022 MONAI Consortium |
2 | 2 | # Licensed under the Apache License, Version 2.0 (the "License");
|
3 | 3 | # you may not use this file except in compliance with the License.
|
4 | 4 | # You may obtain a copy of the License at
|
@@ -280,14 +280,45 @@ def is_dist_editable(project_name: str) -> bool:
|
280 | 280 | if not hasattr(dist, "egg_info"):
|
281 | 281 | return False
|
282 | 282 | egg_info = Path(dist.egg_info)
|
283 |
| - if egg_info.is_dir() and egg_info.suffix == ".egg-info": |
284 |
| - return True |
| 283 | + if egg_info.is_dir(): |
| 284 | + if egg_info.suffix == ".egg-info": |
| 285 | + return True |
| 286 | + elif egg_info.suffix == ".dist-info": |
| 287 | + if (egg_info / "direct_url.json").exists(): |
| 288 | + import json |
| 289 | + |
| 290 | + # Check direct_url.json for "editable": true |
| 291 | + # (https://packaging.python.org/en/latest/specifications/direct-url/) |
| 292 | + with open(egg_info / "direct_url.json", "r") as f: |
| 293 | + data = json.load(f) |
| 294 | + try: |
| 295 | + if data["dir_info"]["editable"]: |
| 296 | + return True |
| 297 | + except KeyError: |
| 298 | + pass |
285 | 299 | return False
|
286 | 300 |
|
287 | 301 |
|
288 | 302 | def dist_module_path(project_name: str) -> str:
|
289 | 303 | distributions: Dict = {v.key: v for v in pkg_resources.working_set}
|
290 | 304 | dist: Any = distributions.get(project_name)
|
| 305 | + if hasattr(dist, "egg_info"): |
| 306 | + egg_info = Path(dist.egg_info) |
| 307 | + if egg_info.is_dir() and egg_info.suffix == ".dist-info": |
| 308 | + if (egg_info / "direct_url.json").exists(): |
| 309 | + import json |
| 310 | + |
| 311 | + # Check direct_url.json for "url" |
| 312 | + # (https://packaging.python.org/en/latest/specifications/direct-url/) |
| 313 | + with open(egg_info / "direct_url.json", "r") as f: |
| 314 | + data = json.load(f) |
| 315 | + try: |
| 316 | + file_url = data["url"] |
| 317 | + if file_url.startswith("file://"): |
| 318 | + return str(file_url[7:]) |
| 319 | + except KeyError: |
| 320 | + pass |
| 321 | + |
291 | 322 | if hasattr(dist, "module_path"):
|
292 | 323 | return str(dist.module_path)
|
293 | 324 | return ""
|
|
0 commit comments