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

refactor!: 0.8 changes #112

Merged
merged 11 commits into from
Jun 1, 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
2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ jobs:
# TODO: Replace with macos-latest when works again.
# https://github.com/actions/setup-python/issues/808
os: [ubuntu-latest, macos-12] # eventually add `windows-latest`
python-version: [3.8, 3.9, "3.10", "3.11", "3.12"]
python-version: [3.9, "3.10", "3.11", "3.12"]

env:
GETH_VERSION: 1.12.0
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ repos:
rev: 0.7.17
hooks:
- id: mdformat
additional_dependencies: [mdformat-gfm, mdformat-frontmatter]
additional_dependencies: [mdformat-gfm, mdformat-frontmatter, mdformat-pyproject]

default_language_version:
python: python3
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Ape compiler plugin around [VVM](https://github.com/vyperlang/vvm)

## Dependencies

- [python3](https://www.python.org/downloads) version 3.8 up to 3.12.
- [python3](https://www.python.org/downloads) version 3.9 up to 3.12.

## Installation

Expand Down
9 changes: 6 additions & 3 deletions ape_vyper/_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import ape
import click
from ape.cli import ape_cli_context
from ape.cli import ape_cli_context, project_option


@click.group
Expand All @@ -12,14 +12,17 @@ def cli():

@cli.command(short_help="Flatten select contract source files")
@ape_cli_context()
@project_option()
@click.argument("CONTRACT", type=click.Path(exists=True, resolve_path=True))
@click.argument("OUTFILE", type=click.Path(exists=False, resolve_path=True, writable=True))
def flatten(cli_ctx, contract: Path, outfile: Path):
def flatten(cli_ctx, project, contract: Path, outfile: Path):
"""
Flatten a contract into a single file
"""
with Path(outfile).open("w") as fout:
content = ape.compilers.vyper.flatten_contract(
Path(contract), base_path=ape.project.contracts_folder
Path(contract),
base_path=ape.project.contracts_folder,
project=project,
)
fout.write(str(content))
18 changes: 8 additions & 10 deletions ape_vyper/ast.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
"""Utilities for dealing with Vyper AST"""

from typing import List

from ethpm_types import ABI, MethodABI
from ethpm_types.abi import ABIType
from vyper.ast import parse_to_ast # type: ignore
Expand All @@ -16,11 +14,11 @@
}


def funcdef_decorators(funcdef: FunctionDef) -> List[str]:
def funcdef_decorators(funcdef: FunctionDef) -> list[str]:
return [d.id for d in funcdef.get("decorator_list") or []]


def funcdef_inputs(funcdef: FunctionDef) -> List[ABIType]:
def funcdef_inputs(funcdef: FunctionDef) -> list[ABIType]:
"""Get a FunctionDef's defined input args"""
args = funcdef.get("args")
# TODO: Does Vyper allow complex input types, like structs and arrays?
Expand All @@ -31,7 +29,7 @@ def funcdef_inputs(funcdef: FunctionDef) -> List[ABIType]:
)


def funcdef_outputs(funcdef: FunctionDef) -> List[ABIType]:
def funcdef_outputs(funcdef: FunctionDef) -> list[ABIType]:
"""Get a FunctionDef's outputs, or return values"""
returns = funcdef.get("returns")

Expand All @@ -46,9 +44,9 @@ def funcdef_outputs(funcdef: FunctionDef) -> List[ABIType]:
elif isinstance(returns, Subscript):
# An array type
length = returns.slice.value.value
array_type = returns.value.id
# TOOD: Is this an acurrate way to define a fixed length array for ABI?
return [ABIType.model_validate({"type": f"{array_type}[{length}]"})]
if array_type := getattr(returns.value, "id", None):
# TOOD: Is this an accurate way to define a fixed length array for ABI?
return [ABIType.model_validate({"type": f"{array_type}[{length}]"})]

raise NotImplementedError(f"Unhandled return type {type(returns)}")

Expand Down Expand Up @@ -81,7 +79,7 @@ def funcdef_to_abi(func: FunctionDef) -> ABI:
)


def module_to_abi(module: Module) -> List[ABI]:
def module_to_abi(module: Module) -> list[ABI]:
"""
Create a list of MethodABIs from a Vyper AST Module instance.
"""
Expand All @@ -92,7 +90,7 @@ def module_to_abi(module: Module) -> List[ABI]:
return abi


def source_to_abi(source: str) -> List[ABI]:
def source_to_abi(source: str) -> list[ABI]:
"""
Given Vyper source code, return a list of Ape ABI elements needed for an external interface.
This currently does not include complex types or events.
Expand Down
Loading
Loading