Skip to content

Commit

Permalink
fix remain initial issues
Browse files Browse the repository at this point in the history
  • Loading branch information
xmnlab committed Nov 29, 2024
1 parent c20e8cc commit 1923388
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 49 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ skips = ["B102", "B701", "B507", "B601"]
[tool.vulture]
exclude = ["tests"]
ignore_decorators = []
ignore_names = []
ignore_names = ["verbose", "dry_run"]
make_whitelist = true
min_confidence = 80
paths = ["src/makim/"]
Expand Down
25 changes: 0 additions & 25 deletions src/makim/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,31 +126,6 @@ def run_app() -> None:
for task_name, task_data in group_data.get('tasks', {}).items():
tasks[f'{group_name}.{task_name}'] = task_data

# add dummy test data:
"""
scheduler:
build:
schedule: "* * * * *" # hourly, daily, weekly, monthly, yearly
task: main.build
args:
clean: true
clean:
schedule: "* * * * *"
task: main.clean
"""

makim.global_data['scheduler'] = {
'build': {
'schedule': '* * * * *',
'task': 'main.build',
'args': {'clean': True},
},
'clean': {
'schedule': '* * * * *',
'task': 'main.clean',
},
}

# Add dynamically cron commands to Typer app
if 'scheduler' in makim.global_data:
typer_cron = typer.Typer(
Expand Down
25 changes: 2 additions & 23 deletions src/makim/cli/auto_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,15 +261,7 @@ def create_dynamic_command_cron(
args : dict
The command arguments and options.
"""
args_str = create_args_string(args)
args_param_list = [f'"task": "{name}"']

args_data = cast(Dict[str, Dict[str, str]], args.get('args', {}))

for arg, arg_details in args_data.items():
arg_clean = arg.replace('-', '_')
args_param_list.append(f'"--{arg}": {arg_clean}')

args_param_str = '{' + ','.join(args_param_list) + '}'
group_name = 'cron'

Expand All @@ -279,22 +271,9 @@ def create_dynamic_command_cron(
rich_help_panel=group_name,
)

function_code = f'def dynamic_command({args_str}):\n'

# handle interactive prompts
for arg, arg_details in args_data.items():
arg_clean = arg.replace('-', '_')
if arg_details.get('interactive', False):
function_code += f' if {arg_clean} is None:\n'
function_code += f" {arg_clean} = click.prompt('{arg}')\n"

function_code = 'def dynamic_command():\n'
function_code += f' makim.run({args_param_str})\n'

local_vars: dict[str, Any] = {}
exec(function_code, globals(), local_vars)
dynamic_command = decorator(local_vars['dynamic_command'])

# Apply Click options to the Typer command
if 'args' in args:
options_data = cast(Dict[str, Dict[str, Any]], args.get('args', {}))
dynamic_command = apply_click_options(dynamic_command, options_data)
decorator(local_vars['dynamic_command'])

0 comments on commit 1923388

Please sign in to comment.