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

Option to skip duty based on a condition #6

Closed
pawamoy opened this issue Feb 5, 2023 · 0 comments
Closed

Option to skip duty based on a condition #6

pawamoy opened this issue Feb 5, 2023 · 0 comments

Comments

@pawamoy
Copy link
Owner

pawamoy commented Feb 5, 2023

Is your feature request related to a problem? Please describe.
I've been using the following pytest-inspired decorator in some of my projects when a duty cannot run on a specific Python version:

def skip_if(condition: bool, reason: str):
    """Decorator allowing to skip a duty if a condition is met.

    Parameters:
        condition: The condition to meet.
        reason: The reason to skip.

    Returns:
        A decorator.
    """

    def decorator(func):
        @wraps(func)
        def wrapper(ctx, *args, **kwargs):
            if condition:
                ctx.run(["true"], title=reason)
            else:
                func(ctx, *args, **kwargs)

        return wrapper

    return decorator

...allowing to do this for example:

@duty
@skip_if(
    sys.version_info < (3, 8) or sys.version_info >= (3, 11),
    reason="Checking docs is not supported on Python 3.7 and 3.11, skipping",
)
def check_docs(ctx): ...

Describe the solution you'd like
Could be nice to provide that natively.

Describe alternatives you've considered
Custom code in projects.

Additional context
/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant