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

Improve pypechain import #94

Merged
merged 4 commits into from
Jan 18, 2024
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
6 changes: 4 additions & 2 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
from web3.middleware import geth_poa
from web3.types import RPCEndpoint

from pypechain import pypechain

# pylint: disable=redefined-outer-name

# IMPORTANT NOTE!!!!!
Expand Down Expand Up @@ -181,5 +183,5 @@ def process_contracts(request):
with open(output_file, "w", encoding="utf-8") as file:
json.dump(data, file, ensure_ascii=False, indent=2)

# Run the pypechain module after processing all contracts
subprocess.run(f"pypechain {test_dir}/abis --output_dir={test_dir}/types", shell=True, check=True)
# # Run the pypechain module after processing all contracts
pypechain(f"{test_dir}/abis", f"{test_dir}/types")
1 change: 1 addition & 0 deletions pypechain/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
# This tool is meant to be used as a command line tool. It is exported here for testing. Do not
# rely on this being available in the future.
from .main import main as pypechain_cli
from .main import pypechain
22 changes: 16 additions & 6 deletions pypechain/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,30 @@


def main(argv: Sequence[str] | None = None) -> None:
"""Main entrypoint for pypechain cli.

Arguments
---------
argv : Sequence[str] | None, optional
_description_, by default None
"""
abi_file_path, output_dir, line_length = parse_arguments(argv)
pypechain(abi_file_path, output_dir, line_length)


def pypechain(abi_file_path: str, output_dir: str = "pypechain_types", line_length: int = 120):
"""Generates class files for a given abi.

Arguments
---------
abi_file_path : str
Path to the abi JSON file.
output_dir: str
Path to the directory where files will be generated.
line_length : int
Optional argument for the output file's maximum line length. Defaults to 80.
output_dir: str, optional
sentilesdal marked this conversation as resolved.
Show resolved Hide resolved
Path to the directory where files will be generated. Defaults to 'pypechain_types'.
line_length : int, optional
Optional argument for the output file's maximum line length. Defaults to 120.
"""

abi_file_path, output_dir, line_length = parse_arguments(argv)

# TODO: move to end of main() so that files aren't cleared if something breaks during script
# execution. Create/clear the output directory
setup_directory(output_dir)
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[project]

name = "pypechain"
version = "0.0.23"
version = "0.0.24"
authors = [
{ name = "Matthew Brown", email = "matt@delv.tech" },
{ name = "Dylan Paiton", email = "dylan@delv.tech" },
Expand Down
Loading