Skip to content

Commit

Permalink
Make it easier to call hunter from scripts (#17)
Browse files Browse the repository at this point in the history
* Pass in Config object to main function

This allows scripts to call hunter.script_main() directly by building a
Config object in-memory instead of needing to create files on disk.

* Allow scripts to pass arguments to script_main()

The default behaviour is to use sys.argv.
  • Loading branch information
mfleming authored Mar 14, 2024
1 parent f5b1f6f commit 6425c00
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions hunter/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,16 @@ def analysis_options_from_args(args: argparse.Namespace) -> AnalysisOptions:


def main():
try:
conf = config.load_config()
except ConfigError as err:
logging.error(err.message)
exit(1)

script_main(conf)


def script_main(conf: Config, args: List[str] = None):
logging.basicConfig(format="%(levelname)s: %(message)s", level=logging.INFO)

parser = argparse.ArgumentParser(description="Hunts performance regressions in Fallout results")
Expand Down Expand Up @@ -530,8 +540,7 @@ def main():
)

try:
args = parser.parse_args()
conf = config.load_config()
args = parser.parse_args(args=args)
hunter = Hunter(conf)

if args.command == "list-groups":
Expand Down Expand Up @@ -619,9 +628,6 @@ def main():
if args.command is None:
parser.print_usage()

except ConfigError as err:
logging.error(err.message)
exit(1)
except TestConfigError as err:
logging.error(err.message)
exit(1)
Expand Down

0 comments on commit 6425c00

Please sign in to comment.