From a4c25d2bad7e3167a67d442a56736abfbded8b87 Mon Sep 17 00:00:00 2001 From: Aryaz Eghbali Date: Thu, 26 Oct 2023 13:53:46 +0200 Subject: [PATCH] Fixed command line crash #41 --- src/dynapyt/__init__.py | 2 +- src/dynapyt/instrument/instrument.py | 23 ++++++++++++---------- src/dynapyt/run_all.py | 28 ++++++++++++++++----------- src/dynapyt/run_analysis.py | 13 +++++++------ src/dynapyt/run_instrumentation.py | 29 +++++++++++++++------------- 5 files changed, 54 insertions(+), 41 deletions(-) diff --git a/src/dynapyt/__init__.py b/src/dynapyt/__init__.py index 0d05b2f..89db17b 100644 --- a/src/dynapyt/__init__.py +++ b/src/dynapyt/__init__.py @@ -1,2 +1,2 @@ """DynaPyt""" -__version__ = "1.2.0" +__version__ = "1.2.1" diff --git a/src/dynapyt/instrument/instrument.py b/src/dynapyt/instrument/instrument.py index 5d9e46a..a472a0f 100644 --- a/src/dynapyt/instrument/instrument.py +++ b/src/dynapyt/instrument/instrument.py @@ -8,16 +8,6 @@ from shutil import copyfile from dynapyt.utils.hooks import get_hooks_from_analysis -parser = argparse.ArgumentParser() -parser.add_argument( - "--files", - help="Python files to instrument or .txt file with all file paths", - nargs="+", -) -parser.add_argument( - "--analysis", help="Analysis class(es) (full dotted path)", nargs="+" -) - def gather_files(files_arg): if len(files_arg) == 1 and files_arg[0].endswith(".txt"): @@ -70,6 +60,19 @@ def instrument_file(file_path, selected_hooks): if __name__ == "__main__": + parser = argparse.ArgumentParser() + parser.add_argument( + "--files", + help="Python files to instrument or .txt file with all file paths", + nargs="+", + required=True, + ) + parser.add_argument( + "--analysis", + help="Analysis class(es) (full dotted path)", + nargs="+", + required=True, + ) args = parser.parse_args() files = gather_files(args.files) analysis = args.analysis diff --git a/src/dynapyt/run_all.py b/src/dynapyt/run_all.py index 4d1d42d..6e5f247 100644 --- a/src/dynapyt/run_all.py +++ b/src/dynapyt/run_all.py @@ -5,17 +5,6 @@ import time from multiprocessing import Pool -parser = argparse.ArgumentParser() -parser.add_argument("--directory", help="Directory of the project to analyze") -parser.add_argument("--entry", help="Entry module of the execution") -parser.add_argument( - "--analysis", help="Analysis class(es) (full dotted path)", nargs="+" -) -parser.add_argument( - "--skip-instrumentation", help="Skip instrumentation", action="store_true" -) -parser.add_argument("--time-limit", help="Time limit for instrumentation in minutes") - def process_files(cmd_list, file_path): comp_proc = run(cmd_list) @@ -25,6 +14,23 @@ def process_files(cmd_list, file_path): if __name__ == "__main__": + parser = argparse.ArgumentParser() + parser.add_argument( + "--directory", help="Directory of the project to analyze", required=True + ) + parser.add_argument("--entry", help="Entry module of the execution", required=True) + parser.add_argument( + "--analysis", + help="Analysis class(es) (full dotted path)", + nargs="+", + required=True, + ) + parser.add_argument( + "--skip-instrumentation", help="Skip instrumentation", action="store_true" + ) + parser.add_argument( + "--time-limit", help="Time limit for instrumentation in minutes" + ) args = parser.parse_args() start = args.directory analysis = args.analysis diff --git a/src/dynapyt/run_analysis.py b/src/dynapyt/run_analysis.py index a002e0f..0d900df 100644 --- a/src/dynapyt/run_analysis.py +++ b/src/dynapyt/run_analysis.py @@ -39,13 +39,14 @@ def run_analysis( _rt.end_execution() -parser = argparse.ArgumentParser() -parser.add_argument("--entry", help="Entry file for execution") -parser.add_argument("--analysis", help="Analysis class name(s)", nargs="+") -parser.add_argument("--name", help="Associates a given name with current run") -parser.add_argument("--coverage", help="Enables coverage", action="store_true") - if __name__ == "__main__": + parser = argparse.ArgumentParser() + parser.add_argument("--entry", help="Entry file for execution", required=True) + parser.add_argument( + "--analysis", help="Analysis class name(s)", nargs="+", required=True + ) + parser.add_argument("--name", help="Associates a given name with current run") + parser.add_argument("--coverage", help="Enables coverage", action="store_true") args = parser.parse_args() name = args.name analyses = args.analysis diff --git a/src/dynapyt/run_instrumentation.py b/src/dynapyt/run_instrumentation.py index 2132280..8bb9643 100644 --- a/src/dynapyt/run_instrumentation.py +++ b/src/dynapyt/run_instrumentation.py @@ -47,19 +47,6 @@ def instrument_dir( print("#################### Instrumentation took " + str(time.time() - start_time)) -parser = argparse.ArgumentParser() -parser.add_argument("--directory", help="Directory of the project to analyze") -parser.add_argument( - "--analysis", help="Analysis class(es) (full dotted path)", nargs="+" -) -parser.add_argument( - "--external_dir", - help="Place instrumented files in another directory", - dest="external_dir", - action="store_true", -) - - def process_files(cmd_list, file_path): comp_proc = run(cmd_list) if comp_proc.returncode != 0: @@ -67,6 +54,22 @@ def process_files(cmd_list, file_path): if __name__ == "__main__": + parser = argparse.ArgumentParser() + parser.add_argument( + "--directory", help="Directory of the project to analyze", required=True + ) + parser.add_argument( + "--analysis", + help="Analysis class(es) (full dotted path)", + nargs="+", + required=True, + ) + parser.add_argument( + "--external_dir", + help="Place instrumented files in another directory", + dest="external_dir", + action="store_true", + ) args = parser.parse_args() start = args.directory analysis = args.analysis