Skip to content

Commit

Permalink
Attempting to fix formatting.
Browse files Browse the repository at this point in the history
  • Loading branch information
afourney committed Jan 30, 2024
1 parent 37f633f commit faaf883
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 46 deletions.
8 changes: 2 additions & 6 deletions samples/tools/autogenbench/autogenbench/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,11 @@ def main(args=None):
sys.stderr.write(help_text + "\n")
sys.exit(0)
else:
command["function"](
[invocation_cmd + " " + command["command"]] + args[2:]
)
command["function"]([invocation_cmd + " " + command["command"]] + args[2:])
sys.exit(0)

# Command not found
sys.stderr.write(
f"Invalid command '{args[1]}'. Available commands include: {commands_list}\n"
)
sys.stderr.write(f"Invalid command '{args[1]}'. Available commands include: {commands_list}\n")
sys.exit(2)


Expand Down
52 changes: 12 additions & 40 deletions samples/tools/autogenbench/autogenbench/run_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,7 @@ def run_scenarios(
print(f"Running scenario {results_repetition}")

# Expand the scenario
expand_scenario(
scenario_dir, instance, results_repetition, requirements
)
expand_scenario(scenario_dir, instance, results_repetition, requirements)

# Prepare the environment (keys/values that need to be added)
env = get_scenario_env(config_list)
Expand Down Expand Up @@ -171,14 +169,10 @@ def expand_scenario(scenario_dir, scenario, output_dir, requirements):
template = scenario["template"]

# Either key works for finding the substiturions list. "values" may be deprecated in the future
substitutions = (
scenario["substitutions"] if "substitutions" in scenario else scenario["values"]
)
substitutions = scenario["substitutions"] if "substitutions" in scenario else scenario["values"]

# Older versions are only one-level deep. Convert them,
if len(substitutions) > 0 and isinstance(
substitutions[next(iter(substitutions))], str
):
if len(substitutions) > 0 and isinstance(substitutions[next(iter(substitutions))], str):
substitutions = {"scenario.py": substitutions}

copy_operations = []
Expand Down Expand Up @@ -217,18 +211,14 @@ def expand_scenario(scenario_dir, scenario, output_dir, requirements):
else:
if os.path.isdir(dest_path):
# If the destination is a directory, use the same filename
shutil.copyfile(
src_path, os.path.join(dest_path, os.path.basename(src_path))
)
shutil.copyfile(src_path, os.path.join(dest_path, os.path.basename(src_path)))
else:
# Otherwuse use the filename provided
shutil.copyfile(src_path, dest_path)

# Copy the requirements file if specified
if requirements is not None:
shutil.copyfile(
requirements, pathlib.Path(os.path.join(output_dir, "requirements.txt"))
)
shutil.copyfile(requirements, pathlib.Path(os.path.join(output_dir, "requirements.txt")))

# Expand templated files
for templated_file in substitutions.keys(): # Keys are relative file paths
Expand Down Expand Up @@ -289,11 +279,7 @@ def run_scenario_natively(work_dir, env, timeout=TASK_TIMEOUT):

# Navigate to the scenario
os.chdir(work_dir)
print(
"\n\n"
+ os.getcwd()
+ "\n==================================================================="
)
print("\n\n" + os.getcwd() + "\n===================================================================")

# Prepare the run script
with open(os.path.join("run.sh"), "wt") as f:
Expand Down Expand Up @@ -378,9 +364,7 @@ def run_scenario_in_docker(work_dir, env, timeout=TASK_TIMEOUT, docker_image=Non
try:
image = client.images.get(DEFAULT_DOCKER_IMAGE_TAG)
except docker.errors.ImageNotFound:
print(
f"Building default Docker image '{DEFAULT_DOCKER_IMAGE_TAG}'. This may take a few minutes..."
)
print(f"Building default Docker image '{DEFAULT_DOCKER_IMAGE_TAG}'. This may take a few minutes...")
try:
build_default_docker_image(client, DEFAULT_DOCKER_IMAGE_TAG)
image = client.images.get(DEFAULT_DOCKER_IMAGE_TAG)
Expand Down Expand Up @@ -449,11 +433,7 @@ def run_scenario_in_docker(work_dir, env, timeout=TASK_TIMEOUT, docker_image=Non
"""
)

print(
"\n\n"
+ work_dir
+ "\n==================================================================="
)
print("\n\n" + work_dir + "\n===================================================================")

# Create and run the container
abs_path = str(pathlib.Path(work_dir).absolute())
Expand All @@ -468,9 +448,7 @@ def run_scenario_in_docker(work_dir, env, timeout=TASK_TIMEOUT, docker_image=Non
)

# Read the logs in a streaming fashion. Keep an eye on the time to make sure we don't need to stop.
docker_timeout = (
timeout + 60
) # One full minute after the bash timeout command should have already triggered
docker_timeout = timeout + 60 # One full minute after the bash timeout command should have already triggered
start_time = time.time()
logs = container.logs(stream=True)
log_file = open(os.path.join(work_dir, "console_log.txt"), "wt")
Expand All @@ -492,9 +470,7 @@ def run_scenario_in_docker(work_dir, env, timeout=TASK_TIMEOUT, docker_image=Non
# but remember how we got here.
stopping = True

if (
stopping
): # By this line we've exited the loop, and the container has actually stopped.
if stopping: # By this line we've exited the loop, and the container has actually stopped.
log_file.write("\nDocker timed out.\n")
log_file.flush()
sys.stdout.write("\nDocker timed out.\n")
Expand Down Expand Up @@ -599,16 +575,12 @@ def run_cli(args):

# Don't allow both --docker-image and --native on the same command
if parsed_args.docker_image is not None and parsed_args.native:
sys.exit(
"The options --native and --docker-image can not be used together. Exiting."
)
sys.exit("The options --native and --docker-image can not be used together. Exiting.")

# Warn if running natively
if parsed_args.native:
if IS_WIN32:
sys.exit(
"Running scenarios with --native is not supported in Windows. Exiting."
)
sys.exit("Running scenarios with --native is not supported in Windows. Exiting.")

if parsed_args.requirements is not None:
sys.exit("--requirements is not compatible with --native. Exiting.")
Expand Down

0 comments on commit faaf883

Please sign in to comment.