Skip to content

Commit

Permalink
feat(run command): add a force option to overwrite the folder if exists
Browse files Browse the repository at this point in the history
  • Loading branch information
mostaphaRoudsari committed Feb 21, 2021
1 parent 3b57469 commit 8347a96
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion pollination_dsl/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import os
import sys
import tempfile
import shutil

import click
from click.exceptions import ClickException
Expand Down Expand Up @@ -212,6 +213,11 @@ def push_resource(ctx, package_name, endpoint, source, public, tag, dry_run):
'commands. Use = to separate key and value. RAYPATH=/usr/local/lib/ray'
)
@click.option('-n', '--name', help='Simulation name for this run.')
@click.option(
'-f', '--force', help='By default run command reuses the results from a previous '
'simulation if they exist. This option will ignore any previous results by trying '
'to delete the folder and running a new simulation.', is_flag=True
)
@click.option(
'-d', '--debug',
type=click.Path(exists=False, file_okay=False, resolve_path=True, dir_okay=True),
Expand All @@ -220,7 +226,7 @@ def push_resource(ctx, package_name, endpoint, source, public, tag, dry_run):
'furthur inspection.'
)
@click.pass_context
def run(ctx, recipe_name, project_folder, inputs, workers, env, name, debug):
def run(ctx, recipe_name, project_folder, inputs, workers, env, name, force, debug):
"""Execute a recipe against a project folder.
\b
Expand All @@ -247,6 +253,15 @@ def run(ctx, recipe_name, project_folder, inputs, workers, env, name, debug):

recipe_folder = target_folder / recipe_name

if name and force:
run_folder = pathlib.Path(project_folder, name)
if run_folder.exists():
print(
'A previous run with the same name already exist. '
'Removing the previous run...'
)
shutil.rmtree(run_folder.as_posix(), ignore_errors=True)

# run the recipe using queenbee-local
ctx.invoke(
run_recipe, recipe=recipe_folder, project_folder=project_folder, inputs=inputs,
Expand Down

0 comments on commit 8347a96

Please sign in to comment.