From d51e139570fddc5ddbd6b3f6b1fd4701e4f0f8db Mon Sep 17 00:00:00 2001 From: MB Date: Tue, 11 Oct 2022 20:03:12 -0500 Subject: [PATCH 1/7] Import PyYaml/create CLI arg for file based config and update TODO list. --- TODO.md | 10 ++++++++++ eth_vertigo/cli/main.py | 3 +++ 2 files changed, 13 insertions(+) create mode 100644 TODO.md diff --git a/TODO.md b/TODO.md new file mode 100644 index 0000000..f5dadbf --- /dev/null +++ b/TODO.md @@ -0,0 +1,10 @@ +# TODO ISSUE #11 Configuration: + +[x] Add command `-c` w/ help info and string arg (file path) +[ ] Check PyYaml import is fine +[ ] Create sample .yml config file. +[ ] Parse yaml data from config file. + [ ] output location + [ ] hardhat parallel value +[ ] Set appropriate values +[ ] Test diff --git a/eth_vertigo/cli/main.py b/eth_vertigo/cli/main.py index 43fdf45..dbff855 100644 --- a/eth_vertigo/cli/main.py +++ b/eth_vertigo/cli/main.py @@ -1,4 +1,5 @@ import click +import yaml from os import getcwd from pathlib import Path from eth_vertigo.core import MutationResult @@ -34,6 +35,8 @@ def cli(): @click.option('--exclude', help="Vertigo won't mutate files in these directories", multiple=True) @click.option('--incremental', help="File where incremental mutation state is stored", type=str) +@click.option('--config', help="Pulls CLI parameters from .yml file. (requires file name)", nargs=1, type=str) + def run( output, network, From 525898a10cc0724e56b36bc0d56855f200de49d8 Mon Sep 17 00:00:00 2001 From: MB Date: Wed, 12 Oct 2022 19:33:27 -0500 Subject: [PATCH 2/7] Grab cli params or default and log them out. --- TODO.md | 7 +++++-- eth_vertigo/cli/main.py | 13 ++++++++++++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/TODO.md b/TODO.md index f5dadbf..a546c93 100644 --- a/TODO.md +++ b/TODO.md @@ -1,10 +1,13 @@ # TODO ISSUE #11 Configuration: -[x] Add command `-c` w/ help info and string arg (file path) +[x] Add command `--config` w/ help info and string arg (file path) + - [x] Look for default 'vertigo_config.yml' file. [ ] Check PyYaml import is fine -[ ] Create sample .yml config file. +[x] Create sample .yml config file. [ ] Parse yaml data from config file. [ ] output location [ ] hardhat parallel value [ ] Set appropriate values [ ] Test + +Install w/ `pip3 install --editable ` diff --git a/eth_vertigo/cli/main.py b/eth_vertigo/cli/main.py index dbff855..6803ae9 100644 --- a/eth_vertigo/cli/main.py +++ b/eth_vertigo/cli/main.py @@ -48,7 +48,8 @@ def run( truffle_location, sample_ratio, exclude, - incremental + incremental, + config ): """ Run command """ click.echo("[*] Starting mutation testing") @@ -58,6 +59,7 @@ def run( working_directory = getcwd() project_type = _directory_type(working_directory) filters = [] + if exclude: filters.append(ExcludeFilter(exclude)) @@ -76,6 +78,15 @@ def run( else: store = IncrementalMutationStore.from_file(incremental_store_file) test_suggesters.append(IncrementalSuggester(store)) + + # Grab passed in value or look for dfault {pwd}/vertigo_config.yml + config_file_path = "" + if config: + config_file_path = config + else: + config_file_path = working_directory + "/vertigo_config.yml" + + click.echo(f" --- config_file_path: {config_file_path}") click.echo("[*] Starting analysis on project") project_path = Path(working_directory) From a664ae78be67b641d32a200de471e51397866340 Mon Sep 17 00:00:00 2001 From: MB Date: Thu, 3 Nov 2022 20:23:24 -0500 Subject: [PATCH 3/7] Simplify yaml parsing. --- TODO.md | 6 +++--- eth_vertigo/cli/main.py | 23 ++++++++++++----------- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/TODO.md b/TODO.md index a546c93..ba8c60a 100644 --- a/TODO.md +++ b/TODO.md @@ -2,12 +2,12 @@ [x] Add command `--config` w/ help info and string arg (file path) - [x] Look for default 'vertigo_config.yml' file. -[ ] Check PyYaml import is fine +[x] Check PyYaml import is fine [x] Create sample .yml config file. -[ ] Parse yaml data from config file. +[x] Parse yaml data from config file. [ ] output location [ ] hardhat parallel value [ ] Set appropriate values [ ] Test -Install w/ `pip3 install --editable ` +Install vertigo package in dev mode w/ `pip3 install --editable ` diff --git a/eth_vertigo/cli/main.py b/eth_vertigo/cli/main.py index 6803ae9..32a444b 100644 --- a/eth_vertigo/cli/main.py +++ b/eth_vertigo/cli/main.py @@ -33,8 +33,7 @@ def cli(): @click.option('--truffle-location', help="Location of truffle cli", nargs=1, type=str, default="truffle") @click.option('--sample-ratio', help="If this option is set. Vertigo will apply the sample filter with the given ratio", nargs=1, type=float) @click.option('--exclude', help="Vertigo won't mutate files in these directories", multiple=True) -@click.option('--incremental', help="File where incremental mutation state is stored", - type=str) +@click.option('--incremental', help="File where incremental mutation state is stored",type=str) @click.option('--config', help="Pulls CLI parameters from .yml file. (requires file name)", nargs=1, type=str) def run( @@ -59,6 +58,7 @@ def run( working_directory = getcwd() project_type = _directory_type(working_directory) filters = [] + config_hardhat_parallel = "" if exclude: filters.append(ExcludeFilter(exclude)) @@ -78,15 +78,14 @@ def run( else: store = IncrementalMutationStore.from_file(incremental_store_file) test_suggesters.append(IncrementalSuggester(store)) - - # Grab passed in value or look for dfault {pwd}/vertigo_config.yml - config_file_path = "" + if config: - config_file_path = config - else: - config_file_path = working_directory + "/vertigo_config.yml" + with open(config, 'r') as file: + config_params = yaml.safe_load(file) + + click.echo(f" --- hardhat_parallel: {config_params['hardhat_parallel']}") + config_hardhat_parallel = config_params['hardhat_parallel'] - click.echo(f" --- config_file_path: {config_file_path}") click.echo("[*] Starting analysis on project") project_path = Path(working_directory) @@ -109,11 +108,13 @@ def run( mutators.append(um) network_pool = None - if hardhat_parallel: + if hardhat_parallel or config_hardhat_parallel == 8: if project_type != "hardhat": click.echo("[+] Not running analysis on hardhat project, ignoring hardhat parallel option") - else: + elif config_hardhat_parallel == "": network_pool = StaticNetworkPool(["_not_used_anywhere_"] * hardhat_parallel) + else: + network_pool = StaticNetworkPool(["_not_used_anywhere_"] * config_hardhat_parallel) if network_pool and (network or ganache_network): click.echo("[*] Both a hardhat network pool is set up and custom networks. Only using hardhat networks") From e1aba0d867455b65b9d734778a577cf31aa96800 Mon Sep 17 00:00:00 2001 From: MB Date: Fri, 4 Nov 2022 08:36:33 -0500 Subject: [PATCH 4/7] Implement output feature from yml config file. --- eth_vertigo/cli/main.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/eth_vertigo/cli/main.py b/eth_vertigo/cli/main.py index 32a444b..add2fc5 100644 --- a/eth_vertigo/cli/main.py +++ b/eth_vertigo/cli/main.py @@ -59,6 +59,7 @@ def run( project_type = _directory_type(working_directory) filters = [] config_hardhat_parallel = "" + config_output = "" if exclude: filters.append(ExcludeFilter(exclude)) @@ -83,9 +84,9 @@ def run( with open(config, 'r') as file: config_params = yaml.safe_load(file) - click.echo(f" --- hardhat_parallel: {config_params['hardhat_parallel']}") + #click.echo(f" --- hardhat_parallel: {config_params['hardhat_parallel']}") config_hardhat_parallel = config_params['hardhat_parallel'] - + config_output = config_params['output'] click.echo("[*] Starting analysis on project") project_path = Path(working_directory) @@ -198,13 +199,20 @@ def run( for mutation in report.mutations: if mutation.result == MutationResult.LIVED: click.echo(str(mutation)) - +## if output: output_path = Path(output) if not output_path.exists() or click.confirm("[*] There already exists something at {}. Overwrite ".format(str(output_path))): click.echo("Result of core run can be found at: {}".format(output)) output_path.write_text(report.render(with_mutations=True), "utf-8") + if config_output: + output_path = Path(config_output) + if not output_path.exists() or click.confirm("[*] There already exists something at {}. Overwrite ".format(str(output_path))): + click.echo("Result of core run can be found at: {}".format(config_output)) + output_path.write_text(report.render(with_mutations=True), "utf-8") + + ## if incremental: incremental_store_file = Path(incremental) if not incremental_store_file.exists() or \ From 503250ea4d7f03298ebc85fc922533306d22d872 Mon Sep 17 00:00:00 2001 From: MB Date: Fri, 4 Nov 2022 13:43:05 -0500 Subject: [PATCH 5/7] Simplify implementation. --- eth_vertigo/cli/main.py | 23 ++++++----------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/eth_vertigo/cli/main.py b/eth_vertigo/cli/main.py index add2fc5..f13f27e 100644 --- a/eth_vertigo/cli/main.py +++ b/eth_vertigo/cli/main.py @@ -58,8 +58,7 @@ def run( working_directory = getcwd() project_type = _directory_type(working_directory) filters = [] - config_hardhat_parallel = "" - config_output = "" + #config_hardhat_parallel = "" if exclude: filters.append(ExcludeFilter(exclude)) @@ -84,9 +83,8 @@ def run( with open(config, 'r') as file: config_params = yaml.safe_load(file) - #click.echo(f" --- hardhat_parallel: {config_params['hardhat_parallel']}") - config_hardhat_parallel = config_params['hardhat_parallel'] - config_output = config_params['output'] + output = config_params['output'] + hardhat_parallel = config_params['hardhat_parallel'] click.echo("[*] Starting analysis on project") project_path = Path(working_directory) @@ -109,13 +107,11 @@ def run( mutators.append(um) network_pool = None - if hardhat_parallel or config_hardhat_parallel == 8: + if hardhat_parallel: if project_type != "hardhat": click.echo("[+] Not running analysis on hardhat project, ignoring hardhat parallel option") - elif config_hardhat_parallel == "": - network_pool = StaticNetworkPool(["_not_used_anywhere_"] * hardhat_parallel) else: - network_pool = StaticNetworkPool(["_not_used_anywhere_"] * config_hardhat_parallel) + network_pool = StaticNetworkPool(["_not_used_anywhere_"] * hardhat_parallel) if network_pool and (network or ganache_network): click.echo("[*] Both a hardhat network pool is set up and custom networks. Only using hardhat networks") @@ -199,20 +195,13 @@ def run( for mutation in report.mutations: if mutation.result == MutationResult.LIVED: click.echo(str(mutation)) -## + if output: output_path = Path(output) if not output_path.exists() or click.confirm("[*] There already exists something at {}. Overwrite ".format(str(output_path))): click.echo("Result of core run can be found at: {}".format(output)) output_path.write_text(report.render(with_mutations=True), "utf-8") - if config_output: - output_path = Path(config_output) - if not output_path.exists() or click.confirm("[*] There already exists something at {}. Overwrite ".format(str(output_path))): - click.echo("Result of core run can be found at: {}".format(config_output)) - output_path.write_text(report.render(with_mutations=True), "utf-8") - - ## if incremental: incremental_store_file = Path(incremental) if not incremental_store_file.exists() or \ From 60ee350df3d324e628208fa8e107f3e277903baf Mon Sep 17 00:00:00 2001 From: MB Date: Mon, 7 Nov 2022 10:10:12 -0600 Subject: [PATCH 6/7] Add notes on config use to README. --- README.md | 19 +++++++++++++++++++ TODO.md | 13 ------------- 2 files changed, 19 insertions(+), 13 deletions(-) delete mode 100644 TODO.md diff --git a/README.md b/README.md index 3ea1e20..081f42f 100644 --- a/README.md +++ b/README.md @@ -59,10 +59,29 @@ Options: --incremental TEXT File where incremental mutation state is stored + --config TEXT File to parse vertigo options from --help Show this message and exit. ``` +### Using Configuration File + +At this time a limited set of options have been implemented. + +A user can create a config file in the project root (see sample below) to limit the number of command line parameters used. +```bash +vertigo run --config vertigo_config.yml +``` + +Sample config file: +``` +//vertigo_config.yml +hardhat_parallel: 8 +output: output.txt +``` + +Note that unused fields in the config file should be `false`. + ### Known Issues **Ganache** is generally used only for a single run of the entire test suite. diff --git a/TODO.md b/TODO.md deleted file mode 100644 index ba8c60a..0000000 --- a/TODO.md +++ /dev/null @@ -1,13 +0,0 @@ -# TODO ISSUE #11 Configuration: - -[x] Add command `--config` w/ help info and string arg (file path) - - [x] Look for default 'vertigo_config.yml' file. -[x] Check PyYaml import is fine -[x] Create sample .yml config file. -[x] Parse yaml data from config file. - [ ] output location - [ ] hardhat parallel value -[ ] Set appropriate values -[ ] Test - -Install vertigo package in dev mode w/ `pip3 install --editable ` From f5ab28bdebd76c698d0c3082ac584c55278242c2 Mon Sep 17 00:00:00 2001 From: MB Date: Mon, 7 Nov 2022 10:21:28 -0600 Subject: [PATCH 7/7] Remove commented out code. --- eth_vertigo/cli/main.py | 1 - 1 file changed, 1 deletion(-) diff --git a/eth_vertigo/cli/main.py b/eth_vertigo/cli/main.py index f13f27e..5742b57 100644 --- a/eth_vertigo/cli/main.py +++ b/eth_vertigo/cli/main.py @@ -58,7 +58,6 @@ def run( working_directory = getcwd() project_type = _directory_type(working_directory) filters = [] - #config_hardhat_parallel = "" if exclude: filters.append(ExcludeFilter(exclude))