ApeWorX / ape

The smart contract development tool for Pythonistas, Data Scientists, and Security Professionals
https://apeworx.io
Apache License 2.0
889 stars 131 forks source link

plugins not recognized when pip isn't installed #1999

Closed wakamex closed 6 months ago

wakamex commented 7 months ago

Environment information

$ ape --version
0.7.13

$ ape plugins list
  alchemy      0.7.1.dev11+gad25ef2.d20240323
  etherscan    0.7.2
$ cat ape-config.yaml
cat: ape-config.yaml: No such file or directory

What went wrong?

couldn't use alchemy in my script. upon further inspection, it wasn't showing up in plugins or networks. i realized this is because of my non-standard installation with uv. since I don't have pip installed, it fails trying to query which plugins are installed.

here are some terminal printouts:

>> ape networks list              
ethereum  (default)
├── goerli
│   └── geth  (default)
├── local  (default)
│   ├── geth
│   └── test  (default)
├── mainnet
│   └── geth  (default)
└── sepolia
    └── geth  (default)
>> uv pip install pip          
Resolved 1 package in 25ms
Installed 1 package in 104ms
 + pip==24.0
>> ape networks list 
ethereum  (default)
├── goerli
│   ├── alchemy
│   └── geth  (default)
├── local  (default)
│   ├── geth
│   └── test  (default)
├── mainnet
│   ├── alchemy
│   └── geth  (default)
└── sepolia
    ├── alchemy
    └── geth  (default)

trying to use a script that uses alchemy without pip installed fails:

>> uv pip uninstall pip       
Uninstalled 1 package in 29ms
 - pip==24.0
>> python steth.py        
Traceback (most recent call last):
  File "/code/testape/steth.py", line 19, in <module>
    context = networks.parse_network_choice('ethereum:mainnet:alchemy')
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/code/testape/.venv/lib/python3.11/site-packages/ape/managers/networks.py", line 528, in parse_network_choice
    provider = self.get_provider_from_choice(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/code/testape/.venv/lib/python3.11/site-packages/ape/managers/networks.py", line 488, in get_provider_from_choice
    return network.get_provider(
           ^^^^^^^^^^^^^^^^^^^^^
  File "/code/testape/.venv/lib/python3.11/site-packages/ape/api/networks.py", line 1042, in get_provider
    raise ProviderNotFoundError(
ape.exceptions.ProviderNotFoundError: No provider named 'alchemy' in network 'mainnet' in ecosystem 'ethereum'. Options:
geth

How can it be fixed?

there's probably a more generic way to detect installed packages than going through pip. but it may be messy.

linear[bot] commented 7 months ago

APE-1723 plugins not recognized when pip isn't installed

fubuloubu commented 7 months ago

@antazoey was experimenting a bit with using importlib for plugin detection, but yeah I don't think the install portion of ape will work without pip (but maybe can just detect uv and use uv pip instead in that case)

antazoey commented 7 months ago

Yeah, can you try on main branch? I think you should be able to at least list the plugins now as of https://github.com/ApeWorX/ape/pull/1996

fubuloubu commented 7 months ago

yeah, I'm thinking if at least you can use ape and just ape plugins install is broken, that's probably not as huge a deal for @wakamex since he should know how to install plugins himself manually via uv

wakamex commented 7 months ago

so a re-install that just points to my local ape-alchemy repo (that i'm still working on!) and installs the latest requirements:

>> uv venv .venv -p 3.10
>> source .venv/bin/activate
>> uv pip install -e ../ape-alchemy
>> ape plugins list
Traceback (most recent call last):
  File "/code/testape2/.venv/bin/ape", line 5, in <module>
    from ape._cli import cli
  File "/code/testape2/.venv/lib/python3.10/site-packages/ape/__init__.py", line 10, in <module>
    from ape.managers.project import ProjectManager as Project
  File "/code/testape2/.venv/lib/python3.10/site-packages/ape/managers/__init__.py", line 23, in <module>
    ManagerAccessMixin.config_manager = ConfigManager(
  File "/code/testape2/.venv/lib/python3.10/site-packages/pydantic/main.py", line 164, in __init__
    __pydantic_self__.__pydantic_validator__.validate_python(data, self_instance=__pydantic_self__)
  File "/code/testape2/.venv/lib/python3.10/site-packages/ape/managers/config.py", line 134, in load_configs
    return cm.load()
  File "/code/testape2/.venv/lib/python3.10/site-packages/ape/managers/config.py", line 277, in load
    _ = self._plugin_configs
  File "/code/testape2/.venv/lib/python3.10/site-packages/ape/managers/config.py", line 205, in _plugin_configs
    valid_ecosystems = dict(self.plugin_manager.ecosystems)
  File "/code/testape2/.venv/lib/python3.10/site-packages/ape/plugins/__init__.py", line 138, in __getattr__
    self._register_plugins()
  File "/code/testape2/.venv/lib/python3.10/site-packages/ape/plugins/__init__.py", line 193, in _register_plugins
    module = importlib.import_module(module_name)
  File "/usr/lib64/python3.10/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "/code/testape2/.venv/lib/python3.10/site-packages/ape_test/__init__.py", line 10, in <module>
    from ape_test.provider import EthTesterProviderConfig, LocalProvider
  File "/code/testape2/.venv/lib/python3.10/site-packages/ape_test/provider.py", line 7, in <module>
    from eth.exceptions import HeaderNotFound
  File "/code/testape2/.venv/lib/python3.10/site-packages/eth/__init__.py", line 1, in <module>
    import pkg_resources
ModuleNotFoundError: No module named 'pkg_resources'

installing setuptools solves this error:

>> uv pip install setuptools      
Resolved 1 package in 1ms
Installed 1 package in 32ms
 + setuptools==69.2.0
>> ape plugins list
Installed Plugins
  alchemy    0.7.1.dev11+gad25ef2.d20240411

add setuptools as a dependency? if you add pip as a dependency then uv should install it...