From b19f10863b20d5428e9d7ff6d0c7d12e49152381 Mon Sep 17 00:00:00 2001 From: antazoey Date: Thu, 30 Jan 2025 09:16:42 -0600 Subject: [PATCH 1/3] feat: show output --- src/ape_compile/_cli.py | 9 ++++++++- tests/integration/cli/test_compile.py | 20 +++++++++++++++++--- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/src/ape_compile/_cli.py b/src/ape_compile/_cli.py index 0251d77d3a..c35ecdf026 100644 --- a/src/ape_compile/_cli.py +++ b/src/ape_compile/_cli.py @@ -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, @@ -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 @@ -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: @@ -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 diff --git a/tests/integration/cli/test_compile.py b/tests/integration/cli/test_compile.py index 39a25fc980..a898eb13a7 100644 --- a/tests/integration/cli/test_compile.py +++ b/tests/integration/cli/test_compile.py @@ -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 From 44da257c9eb25b6a20077f823a7fb96c48d410f4 Mon Sep 17 00:00:00 2001 From: antazoey Date: Thu, 30 Jan 2025 09:18:02 -0600 Subject: [PATCH 2/3] docs: doc --- docs/userguides/compile.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/docs/userguides/compile.md b/docs/userguides/compile.md index 67bfdf7460..d233e29249 100644 --- a/docs/userguides/compile.md +++ b/docs/userguides/compile.md @@ -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 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. From ed7c56f1fdd551e42f8db1527c1858bfe725dc57 Mon Sep 17 00:00:00 2001 From: antazoey Date: Thu, 30 Jan 2025 09:19:43 -0600 Subject: [PATCH 3/3] docs: s --- docs/userguides/compile.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/userguides/compile.md b/docs/userguides/compile.md index d233e29249..2083a963ee 100644 --- a/docs/userguides/compile.md +++ b/docs/userguides/compile.md @@ -165,7 +165,7 @@ To see the full list of supported output-extra, see [the OutputExtras enum docum ## Show Output -To also display the contract type in the CLI terminal, use the `--show-output` flag when compiling: +To also display the contract type(s) in the CLI terminal, use the `--show-output` flag when compiling: ```shell ape compile --show-output