Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support to generated CLIs for function arguments of arbitrary type #113

Merged
merged 3 commits into from
Aug 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ jobs:
run: pip install -U pip
- name: Install dev dependencies
run: pip install -e .[dev]
- name: Mypy type check
run: mypy moonworm/
- name: Isort imports check
run: isort --check moonworm/
- name: Black syntax check
Expand Down
6 changes: 3 additions & 3 deletions moonworm/generators/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,11 @@ def normalize_abi_name(name: str) -> str:


def python_type(evm_type: str) -> List[str]:
if evm_type.endswith("]"):
if evm_type.endswith("]") and not evm_type.endswith("][]"):
return ["List"]
if evm_type.startswith(("uint", "int")):
if evm_type.startswith(("uint", "int")) and "[" not in evm_type:
return ["int"]
if evm_type.startswith(("int", "int")):
if evm_type.startswith(("int", "int")) and "[" not in evm_type:
return ["int"]
elif evm_type.startswith("bytes"):
return ["bytes"]
Expand Down
9 changes: 9 additions & 0 deletions moonworm/generators/brownie.py
Original file line number Diff line number Diff line change
Expand Up @@ -831,6 +831,15 @@ def generate_cli_generator(
value=cst.parse_expression("eval"),
),
)
elif param["type"] == "Any":
# In general case, we just use a Python `eval` to parse the input from the command line.
# This is similar to the way we handle `tuple` arguments.
call_args.append(
cst.Arg(
keyword=cst.Name(value="type"),
value=cst.parse_expression("eval"),
),
)

add_argument_call = cst.Call(
func=cst.Attribute(
Expand Down
2 changes: 1 addition & 1 deletion moonworm/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
MOONWORM_VERSION = "0.6.2"
MOONWORM_VERSION = "0.7.0"
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"black",
"inflection",
"libcst",
"pysha3<2.0.0,>=1.0.0",
"pysha3<2.0.0,>=1.0.0; python_version < '3.6'",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to specify python_version version? Is it falling on your side? When I installed it without python_version specified in setup.py it also not exists in pip freeze

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was failing on my side with Python 3.11, which changed the LibPython.h to not include something required by pysha3.

pysha3 is also deprecated and not used after Python 3.6 - https://github.com/tiran/pysha3

When it is used, it's a monkey patch on hashlib anyway.

So I think it's ok to keep this python_version < 3.6 constraint. Should not affect anyone's user experience.

"tqdm",
"typing-extensions",
"web3>=5.27.0",
Expand Down
Loading