Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposal | Move tasks load and list to run command #290

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 3 additions & 22 deletions leverage/leverage.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
import click

from leverage import __version__
from leverage.tasks import load_tasks
from leverage.tasks import list_tasks as _list_tasks
from leverage._internals import pass_state

from leverage.modules.aws import aws
Expand All @@ -14,34 +12,17 @@


@click.group(invoke_without_command=True)
@click.option(
"--filename",
"-f",
default="build.py",
show_default=True,
help="Name of the build file containing the tasks definitions.",
)
@click.option("--list-tasks", "-l", is_flag=True, help="List available tasks to run.")
@click.option("-v", "--verbose", is_flag=True, help="Increase output verbosity.")
@click.version_option(version=__version__)
@pass_state
@click.pass_context
def leverage(context, state, filename, list_tasks, verbose):
def leverage(context, state, verbose):
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codebase verification

Breaking changes need to be documented in the codebase

The functionality has been moved from the main leverage function to the run command, but this breaking change isn't properly documented. Please:

  1. Update the docstring in leverage/leverage.py to mention that task-related options have been moved to the run command
  2. Add a note in the README.md under the "Note for migration from previous versions" section about this breaking change
  3. Consider adding a deprecation notice in the documentation site mentioned at https://leverage.binbash.co/user-guide/leverage-cli/installation/

Example locations that need updates:

  • leverage/leverage.py: Update docstring to reflect the simplified interface
  • README.md: Add migration note about task-related options moving to run command
  • Documentation site: Update CLI usage guide
🔗 Analysis chain

Document breaking changes and provide migration guide.

The removal of filename and list_tasks parameters is a breaking change that could affect existing implementations. Consider:

  1. Updating the docstring to reflect the parameter changes
  2. Adding a note about migrating to the new run command for these features

Let's verify if there are any existing documentation files that need updates:


Let's check the content of README.md to see if it contains any documentation about the CLI usage and if it needs updates:


Let's check if there's any existing documentation about the CLI usage and parameters in the codebase, particularly focusing on the documentation site mentioned in the README:


Let's check the content of both files to understand how the functionality has been moved and if there's any existing documentation about the migration:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for documentation files that might need updates
fd -e md -e rst . | grep -i -E 'readme|guide|doc|changelog|breaking'

Length of output: 80


Script:

#!/bin/bash
# Check README.md content
cat README.md

Length of output: 7564


Script:

#!/bin/bash
# Search for any additional documentation files or usage examples
rg -l "leverage\(.*context.*state" --type py
rg -l "filename.*list.*tasks" --type py

Length of output: 133


Script:

#!/bin/bash
# Check the content of both files
echo "=== leverage.py ==="
cat leverage/leverage.py
echo -e "\n=== run.py ==="
cat leverage/modules/run.py

Length of output: 7152

"""Leverage Reference Architecture projects command-line tool."""
# --verbose | -v
state.verbosity = verbose

# Load build file as a module
state.module = load_tasks(build_script_filename=filename)

if context.invoked_subcommand is None:
# --list-tasks|-l
if list_tasks:
_list_tasks(state.module)

else:
# leverage called with no subcommand
click.echo(context.get_help())
# leverage called with no subcommand
click.echo(context.get_help())


# Add modules to leverage
Expand Down
21 changes: 19 additions & 2 deletions leverage/modules/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
from click.exceptions import Exit

from leverage import logger
from leverage.tasks import list_tasks
from leverage.tasks import load_tasks
from leverage.tasks import list_tasks as _list_tasks
from leverage.logger import get_tasks_logger
from leverage._parsing import parse_task_args
from leverage._parsing import InvalidArgumentOrderError
Expand All @@ -30,16 +31,32 @@ class TaskNotFoundError(RuntimeError):


@click.command()
@click.option(
"--filename",
"-f",
default="build.py",
show_default=True,
help="Name of the build file containing the tasks definitions.",
)
@click.option("--list-tasks", "-l", is_flag=True, help="List available tasks to run.")
@click.argument("tasks", nargs=-1)
@pass_state
def run(state, tasks):
def run(state, filename, list_tasks, tasks):
"""Perform specified task(s) and all of its dependencies.

When no task is given, the default (__DEFAULT__) task is run, if no default task has been defined, all available tasks are listed.
"""
global _logger
_logger = get_tasks_logger()

# Load build file as a module
state.module = load_tasks(build_script_filename=filename)

if list_tasks:
# --list-tasks|-l
_list_tasks(state.module)
return

if tasks:
# Run the given tasks
try:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ boto3 = "1.33.2"
configupdater = "3.2"
docutils = "0.17.1"
rich = "10.4.0"

requests = "2.31"

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Remove invalid line.

Line 43 contains an invalid standalone number that should be removed as it's not valid TOML syntax.

Committable suggestion skipped: line range outside the PR's diff.

[tool.poetry.group.dev.dependencies]
pylint = "2.8.3"
pytest = "6.2.4"
Expand Down
Loading