Skip to content

Commit

Permalink
perf: hardcoded trusted plugin during --help check (#2347)
Browse files Browse the repository at this point in the history
  • Loading branch information
antazoey authored Oct 27, 2024
1 parent 6b584a2 commit 4199cac
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/ape/_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def format_commands(self, ctx, formatter) -> None:

if plugin.in_core:
sections["Core"].append((cli_name, help))
elif plugin.is_installed and not plugin.is_third_party:
elif plugin.check_trusted(use_web=False):
sections["Plugin"].append((cli_name, help))
else:
sections["3rd-Party Plugin"].append((cli_name, help))
Expand Down
63 changes: 61 additions & 2 deletions src/ape/plugins/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,47 @@
"ape_run",
"ape_test",
]
# Hardcoded for performance reasons. Functionality in plugins commands
# and functions won't use this; they use GitHub to check directly.
# This hardcoded list is useful for `ape --help`. If ApeWorX adds a new
# trusted plugin, it should be added to this list; else it will show
# as 3rd-party in `ape --help`.
TRUSTED_PLUGINS = [
"addressbook",
"alchemy",
"arbitrum",
"avalanche",
"aws",
"base",
"blast",
"blockscout",
"bsc",
"cairo",
"chainstack",
"ens",
"etherscan",
"fantom",
"farcaster",
"flashbots",
"foundry",
"frame",
"ganache",
"hardhat",
"infura",
"ledger",
"notebook",
"optimism",
"polygon",
"polygon_zkevm",
"safe",
"solidity",
"template",
"tenderly",
"titanoboa",
"tokens",
"trezor",
"vyper",
]


def clean_plugin_name(name: str) -> str:
Expand Down Expand Up @@ -378,14 +419,23 @@ def is_installed(self) -> bool:

@property
def is_third_party(self) -> bool:
return self.is_installed and not self.is_available
"""
``True`` when is an installed plugin that is not from ApeWorX.
"""
return self.is_installed and not self.is_trusted

@cached_property
def is_trusted(self) -> bool:
"""
``True`` when is a plugin from ApeWorX.
"""
return self.check_trusted()

@property
def is_available(self) -> bool:
"""
Whether the plugin is maintained by the ApeWorX organization.
"""

return self.module_name in _get_available_plugins()

def __str__(self) -> str:
Expand All @@ -404,6 +454,15 @@ def check_installed(self, use_cache: bool = True) -> bool:

return any(n == self.package_name for n in get_plugin_dists())

def check_trusted(self, use_web: bool = True) -> bool:
if use_web:
return self.is_available

else:
# Sometimes (such as for --help commands), it is better
# to not check GitHub to see if the plugin is trusted.
return self.name in TRUSTED_PLUGINS

def _prepare_install(
self, upgrade: bool = False, skip_confirmation: bool = False
) -> Optional[dict[str, Any]]:
Expand Down

0 comments on commit 4199cac

Please sign in to comment.