Skip to content

Commit b95ac2f

Browse files
authored
fix: making it easier to install dependencies (#2665)
1 parent 46f0d8e commit b95ac2f

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

src/ape/managers/project.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1435,12 +1435,25 @@ def _get_dependency_api_by_package_id(
14351435
self, package_id: str, version: Optional[str] = None, attr: str = "package_id"
14361436
) -> Optional[DependencyAPI]:
14371437
matching = []
1438-
for dependency in self.config_apis:
1439-
if getattr(dependency, attr) != package_id:
1438+
1439+
# First, only look at local configured packages (to give priority).
1440+
for api in self.config_apis:
1441+
if getattr(api, attr) != package_id:
14401442
continue
14411443

1442-
if (version and dependency.version_id == version) or not version:
1443-
matching.append(dependency)
1444+
if (version and api.version_id == version) or not version:
1445+
matching.append(api)
1446+
1447+
if not matching:
1448+
# Nothing found: search in 'all'.
1449+
for dependency in self.all:
1450+
if getattr(dependency, attr) != package_id:
1451+
continue
1452+
1453+
if (version and dependency.api.version_id == version) or not version:
1454+
matching.append(dependency.api)
1455+
1456+
# else: prioritize the local dependencies, as that is most-likely what the user wants.
14441457

14451458
return sorted(matching, key=lambda d: d.version_id)[-1] if matching else None
14461459

src/ape_pm/_cli.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,9 @@ def _package_callback(ctx, param, value):
173173
else:
174174
return dependency
175175

176-
raise click.BadArgumentUsage(f"Unknown package '{value}'.")
176+
raise click.BadArgumentUsage(
177+
f"Unknown package '{value}'. Did you mean to prefix with `gh:`, `npm:` etc.?"
178+
)
177179

178180

179181
@cli.command()

0 commit comments

Comments
 (0)