Skip to content

Commit

Permalink
chore: code refactored & working on fixing the cli
Browse files Browse the repository at this point in the history
  • Loading branch information
avik committed Jul 9, 2024
1 parent aaa72ad commit 1bb2c5b
Show file tree
Hide file tree
Showing 8 changed files with 135 additions and 152 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@ TODO: Description
You can install the latest release via [`pip`](https://pypi.org/project/pip/):

```bash
pip install <PYPI_NAME>
pip install ape_utils
```

### via `setuptools`

You can clone the repository and use [`setuptools`](https://github.com/pypa/setuptools) for the most up-to-date version:

```bash
git clone https://github.com/ApeWorX/<PYPI_NAME>.git
cd <PYPI_NAME>
python3 setup.py install
git clone https://github.com/Aviksaikat/ape_utils.git
cd ape_utils
pip install -e .
```

## Quick Usage
Expand Down
149 changes: 108 additions & 41 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,114 @@ classifiers = [
]
dependencies = []

# Cli tool name & options
[project.scripts]
ape_call = "ape_utils._cli:main"

[project.urls]
Documentation = "https://github.com/Aviksaikat/ape-utils#readme"
Issues = "https://github.com/Aviksaikat/ape-utils/issues"
Source = "https://github.com/Aviksaikat/ape-utils"

[tool.hatch.version]
source = "regex_commit"
commit_extra_args = ["-e"]
path = "src/ape_utils/__about__.py"


##################
# External Tools #
##################

[tool.mypy]
files = ["ape_utils"]
exclude = ["build/", "dist/", "docs/", "tests/"]
disallow_untyped_defs = true
disallow_any_unimported = true
no_implicit_optional = true
check_untyped_defs = true
warn_return_any = true
warn_unused_ignores = true
show_error_codes = true
ignore_missing_imports = true
# plugins = ["pydantic.mypy"]


[tool.ruff]
target-version = "py39"
line-length = 120
indent-width = 4
include = [
"src/**/*.py",
"src/**/*.pyi",
"tests/**/*.py",
"tests/**/*.pyi"
]
exclude = ["tests", "src/ape_utils/_version.py"]

[tool.ruff.lint]
preview = true # preview features & checks, use with caution
extend-select = [ # features in preview
"W292", # missing-newline-at-end-of-file
]
select = [
"A",
"ARG",
"B",
"C",
"DTZ",
"E",
"EM",
"F",
"FBT", # Boolean trap
"ICN",
"ISC",
"I",
"N",
"PLC",
"PLE",
"PLR",
"PLW",
"Q",
"RUF",
"S",
"T",
"TID",
"UP",
"W",
"YTT",
"RUF100", # Automatically remove unused # noqa directives
]
ignore = [
# Allow non-abstract empty methods in abstract base classes
"B027",
# Allow boolean positional values in function calls, like `dict.get(... True)`
"FBT003",
# Ignore checks for possible passwords
"S105", "S106", "S107",
# Ignore complexity
"C901", "PLR0911", "PLR0912", "PLR0913", "PLR0915",
"PLC1901", # empty string comparisons
"PLW2901", # `for` loop variable overwritten
"SIM114", # Combine `if` branches using logical `or` operator
"E203", # Whitespace before :, needed for black compatability and also `ruff format`
"ISC001", # causes unexpected behaviour with formatter
]

[tool.ruff.lint.isort]
known-first-party = ["ape_utils"]


[tool.ruff.lint.flake8-tidy-imports]
ban-relative-imports = "all"


[tool.ruff.lint.per-file-ignores]
# Allow print/pprint
"examples/*" = ["T201"]
# Tests can use magic values, assertions, and relative imports
"tests/**/*" = ["PLR2004", "S101", "TID252"]


[tool.coverage.run]
source_pkgs = ["src/ape_utils", "tests"]
Expand All @@ -43,8 +142,8 @@ omit = [
]

[tool.coverage.paths]
ape_utils = ["src/ape_utils", "*/ape-utils/ape_utils"]
tests = ["tests", "*/ape-utils/tests"]
ape_utils = ["src/ape_utils", "*/ape_utils/src/ape_utils"]
tests = ["tests", "*/ape_utils/tests"]

[tool.coverage.report]
exclude_lines = [
Expand All @@ -62,57 +161,25 @@ dependencies = [
# "eth-ape",
"multicall",
"click",
"rich"
]

[tool.hatch.envs.dev]
dependencies = [
"rich",
"multicall",
"click",
"commitizen",
"pre-commit",
"pytest-watch",
"IPython",
"ipdb",
"pytest>=6.0",
"pytest-xdist",
"pytest-cov",
"hypothesis>=6.2.0,<7.0",
"black>=24.4.2,<25",
"mypy>=1.10.0,<2",
"types-setuptools",
"types-requests",
"flake8>=7.0.0,<8",
"flake8-breakpoint>=1.1.0,<2",
"flake8-print>=5.0.0,<6",
"isort>=5.13.2,<6",
"mdformat>=0.7.17",
"mdformat-gfm>=0.3.5",
"mdformat-frontmatter>=0.4.1",
"mdformat-pyproject>=0.0.1",
]

[tool.hatch.envs.test]
dependencies = ["pytest", "pytest-xdist", "pytest-cov", "hypothesis", "multicall", "click",]

dependencies = ["pytest", "pytest-xdist", "pytest-cov", "hypothesis"]

[tool.hatch.envs.lint]
dependencies = [
"multicall",
"click",
"black",
# If you define environments with dependencies that only slightly differ from their
# inherited environments, you can use the extra-dependencies option to avoid redeclaring the
# dependencies option: https://hatch.pypa.io/latest/config/environment/overview/#dependencies
extra-dependencies = [
"mypy",
"flake8",
"isort",
"types-setuptools",
"types-requests",
"flake8-breakpoint>=1.1.0",
"flake8-print>=5.0.0",
"mdformat>=0.7.17",
"mdformat-gfm>=0.3.5",
"mdformat-frontmatter>=0.4.1",
"mdformat-pyproject>=0.0.1",

]
[tool.hatch.envs.lint.scripts]
# check = "mypy --install-types --non-interactive {args:ape_utils tests}"
Expand All @@ -134,5 +201,5 @@ lint-check = [
]

[build-system]
requires = ["hatchling"]
requires = ["hatchling", "hatch-regex-commit"]
build-backend = "hatchling.build"
7 changes: 0 additions & 7 deletions setup.cfg

This file was deleted.

84 changes: 0 additions & 84 deletions setup.py

This file was deleted.

2 changes: 1 addition & 1 deletion src/ape_utils/__about__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version = "0.0.1"
version = "0.0.1"
3 changes: 3 additions & 0 deletions src/ape_utils/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
# Add module top-level imports here
from ape_utils.utils import call_view_function

__all__ = ["call_view_function"]
17 changes: 11 additions & 6 deletions src/ape_utils/_cli.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
import click

from ape_utils.utils import call_view_function


@click.command()
@click.option('--function-sig', prompt='Function signature', help='The function signature (e.g., gsr_query(uint256)(string)).')
@click.option('--address', prompt='Contract address', help='The address of the smart contract.')
@click.option('--args', prompt='Arguments', help='The arguments for the function call.', type=int)
def main(function_sig, address, args):
@click.option(
"--function-sig", prompt="Function signature", help="The function signature (e.g., function_name(uint256)(string))."
)
@click.option("--address", prompt="Contract address", help="The address of the smart contract.")
@click.option("--args", prompt="Arguments", help="The arguments for the function call.", type=int)
def main(function_sig: str, address: str, args: int) -> None:
try:
output = call_view_function(function_sig, address, args)
click.echo(f"Output: {output}")
except Exception as e:
click.echo(f"Error: {str(e)}")
click.echo(f"Error: {e!s}")


if __name__ == '__main__':
if __name__ == "__main__":
main()
17 changes: 8 additions & 9 deletions src/ape_utils/utils.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,30 @@
from multicall import Call # type: ignore
from web3 import Web3
import os
from typing import Any

from multicall import Call
from rich.console import Console
from rich.traceback import install


from web3 import Web3

# install rich traceback
install()
console = Console()



def call_view_function(function_sig: str, address: str, args: int) -> None:

def call_view_function(function_sig: str, address: str, args: int) -> Any:
w3 = Web3(Web3.HTTPProvider(os.environ["sepoliafork"]))

# get_sitnature(address, function_sig)

output = Call(address, [function_sig, args])(_w3=w3)

console.print(f"[blue]Output: [green bold]{output}")
# console.print(f"[blue]Output: [green bold]{output}")
return output


if __name__ == "__main__":
function_sig: str = "gsr_query(uint256)(string)"
address: str = "0x9b7FD6FF5e427F8470E1da652f21A79Bed318f38"
args = 6147190

call_view_function(function_sig, address, args)

0 comments on commit 1bb2c5b

Please sign in to comment.