Skip to content

Commit

Permalink
fix: plugins install fix (#1639)
Browse files Browse the repository at this point in the history
  • Loading branch information
antazoey authored Aug 31, 2023
1 parent 6f5399a commit 1550955
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 14 deletions.
32 changes: 18 additions & 14 deletions src/ape_plugins/_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,26 +41,30 @@ def plugins_argument():
or plugins loaded from the local config file.
"""

def load_from_file(ctx, file_path: Path) -> List[PluginInstallRequest]:
if file_path.is_file() and file_path.name != CONFIG_FILE_NAME:
file_path = file_path / CONFIG_FILE_NAME

if file_path.is_file():
config = load_config(file_path)
if plugins := config.get("plugins"):
return [PluginInstallRequest.parse_obj(d) for d in plugins]

ctx.obj.logger.warning(f"No plugins found at '{file_path}'.")
return []

def callback(ctx, param, value: Tuple[str]):
if not value:
ctx.obj.abort("You must give at least one requirement to install.")

elif len(value) == 1 and Path(value[0]).resolve().exists():
elif len(value) == 1:
# User passed in a path to a file.
file_path = Path(value[0]).expanduser().resolve()

# Config file
if file_path.name != CONFIG_FILE_NAME:
file_path = file_path / CONFIG_FILE_NAME

config = load_config(file_path)
plugins = config.get("plugins") or []

if not plugins:
ctx.obj.logger.warning(f"No plugins found at '{file_path}'.")
sys.exit(0)

return [PluginInstallRequest.parse_obj(d) for d in plugins]
return (
load_from_file(ctx, file_path)
if file_path.exists()
else [PluginInstallRequest(name=v) for v in value[0].split(" ")]
)

else:
return [PluginInstallRequest(name=v) for v in value]
Expand Down
7 changes: 7 additions & 0 deletions tests/integration/cli/test_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from tests.integration.cli.utils import github_xfail

TEST_PLUGIN_NAME = "tokens"
TEST_PLUGIN_NAME_2 = "optimism"


class PluginsList(list):
Expand Down Expand Up @@ -140,6 +141,12 @@ def test_upgrade_failure(ape_plugins_runner):
assert result.exit_code == 1


@github_xfail()
def test_install_multiple_in_one_str(ape_plugins_runner):
result = ape_plugins_runner.invoke(["install", f"{TEST_PLUGIN_NAME} {TEST_PLUGIN_NAME_2}"])
assert result.exit_code == 0


@github_xfail()
def test_install_from_config_file(ape_cli, runner, temp_config, caplog):
plugins_config = {"plugins": [{"name": TEST_PLUGIN_NAME}]}
Expand Down

0 comments on commit 1550955

Please sign in to comment.