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

feat: ability to show contract-types in stdout when compiling #2483

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
10 changes: 10 additions & 0 deletions docs/userguides/compile.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,3 +162,13 @@ Then, after compiling, you should notice minified ABI json files in your `.build
This is useful if hosting these files on a web-server.

To see the full list of supported output-extra, see [the OutputExtras enum documentation](../methoddocs/ape_compile.html#ape_compile.config.OutputExtras).

## Show Output

To also display the contract type(s) in the CLI terminal, use the `--show-output` flag when compiling:

```shell
ape compile --show-output
```

Now, your ABIs and bytecode (and all other artifacts) will appear stdout as well as Ape's disk cache.
9 changes: 8 additions & 1 deletion src/ape_compile/_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ def _include_dependencies_callback(ctx, param, value):
help="Also compile dependencies",
callback=_include_dependencies_callback,
)
@click.option("--show-output", is_flag=True, help="Show contract-types in stdout")
@config_override_option()
def cli(
cli_ctx,
Expand All @@ -51,6 +52,7 @@ def cli(
display_size: bool,
include_dependencies,
config_override,
show_output,
):
"""
Compiles the manifest for this project and saves the results
Expand All @@ -70,6 +72,11 @@ def cli(
k: v.contract_type
for k, v in project.load_contracts(*file_paths, use_cache=use_cache).items()
}

if show_output:
for contract in contracts.values():
click.echo(contract.model_dump_json())

cli_ctx.logger.success("'local project' compiled.")
compiled = True
if display_size:
Expand All @@ -79,7 +86,7 @@ def cli(
project.dependencies
) > 0:
for dependency in project.dependencies:
# Even if compiling we failed, we at least tried
# Even if compiling we failed, we at least tried,
# and so we don't need to warn "Nothing to compile".
compiled = True

Expand Down
20 changes: 17 additions & 3 deletions tests/integration/cli/test_compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,20 +377,34 @@ def test_raw_compiler_output_bytecode(integ_project):


@skip_projects_except("with-contracts")
def test_compile_exclude(ape_cli, runner):
result = runner.invoke(ape_cli, ("compile", "--force"), catch_exceptions=False)
def test_compile_exclude(ape_cli, runner, integ_project):
result = runner.invoke(
ape_cli,
("compile", "--force", "--project", f"{integ_project.path}"),
catch_exceptions=False,
)
assert "Compiling 'contracts/Exclude.json'" not in result.output
assert "Compiling 'contracts/IgnoreUsingRegex.json'" not in result.output
assert "Compiling 'contracts/exclude_dir/UnwantedContract.json'" not in result.output


@skip_projects_except("with-contracts")
def test_compile_config_override(ape_cli, runner):
def test_compile_config_override(ape_cli, runner, integ_project):
arguments = (
"compile",
"--force",
"--config-override",
'{"compile": {"exclude": ["*ContractA*"]}}',
"--project",
f"{integ_project.path}",
)
result = runner.invoke(ape_cli, arguments, catch_exceptions=False)
assert "Compiling 'contracts/ContractA.json'" not in result.output


@skip_projects_except("with-contracts")
def test_compile_show_output(ape_cli, runner, integ_project):
arguments = ("compile", "--force", "--show-output", "--project", f"{integ_project.path}")
result = runner.invoke(ape_cli, arguments, catch_exceptions=False)
assert "Compiling 'contracts/ContractA.json'" not in result.output
assert '{"bytecode":"0x34611' in result.output
Loading