Skip to content

Commit

Permalink
allow extras from command line
Browse files Browse the repository at this point in the history
  • Loading branch information
jonapich committed Oct 17, 2024
1 parent 125a253 commit 21c902e
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,9 @@ Options:
- `--quick` skips running `poetry install --remove-untracked` before running the checks.
- **v3.0.30**: You can now customize which checks to run when `--quick` is specified. See the [quick](#configuration) configuration option.
- `--no-github-step-report` can be used to disable Step Report generation when running in a GitHub context.
- `--extra <extra>` *(v3.0.35)* will install the specified extra(s) for this run. Can be specified multiple times.
- `--all-extras` *(v3.0.35)* will install all extras for this run.
- `--no-extras` *(v3.0.35)* will not install any extra for this run.

The configuration for this feature is explained in more details in the [runners](#runners-stew-ci) section.

Expand Down Expand Up @@ -230,7 +233,9 @@ quick = {}
- **build-dependencies**: You can specify additional dependencies to be installed during `stew build`.
- The format is the same as poetry dependencies: `name = "version"` or `name = { version = "version", ... }`
- **extras**: A list of extras to install during `stew build` and `stew ci`.
- *(v3.0.35)* Can be specified at execution time with `stew ci --extra <this> --extra <that>`.
- **all-extras**: If true, all extras will be installed during `stew build` and `stew ci`. Overrides the `extras` list.
- *(v3.0.35)* Can be specified at execution time with `stew ci --all-extras` and `stew ci --no-extras`.
- **quick**: *(v3.0.30)* Controls which checks are skipped when calling `stew ci --quick`.
- The format is a dictionary with either the `check` or `skip` key, followed by a list of runners.
- The behavior is identical to the `--check` and `--skip` options.
Expand Down
9 changes: 9 additions & 0 deletions coveo_stew/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import re
from collections import defaultdict
from pathlib import Path
from sys import flags
from typing import Generator, Iterable, Set, Tuple, Union

import click
Expand Down Expand Up @@ -323,6 +324,9 @@ def refresh(project_name: str = None, exact_match: bool = False, verbose: bool =
)
@click.option("--parallel/--sequential", default=True)
@click.option("--github-step-report", is_flag=True, default=False, envvar="GITHUB_ACTIONS")
@click.option("--extra", multiple=True, default=())
@click.option("--no-extras", is_flag=True, default=False)
@click.option("--all-extras", is_flag=True, default=False)
def ci(
project_name: str = None,
exact_match: bool = False,
Expand All @@ -333,6 +337,9 @@ def ci(
quick: bool = False,
parallel: bool = True,
github_step_report: bool = False,
extra: Tuple[str, ...] = (),
no_extras: bool = False,
all_extras: bool = False,
) -> None:
failures = defaultdict(list)
try:
Expand All @@ -345,6 +352,8 @@ def ci(
check += tuple(project.options.quick.get("check", ()))
skip += tuple(project.options.quick.get("skip", ()))

project.overrides_from_cli(extras=extra, no_extras=no_extras, all_extras=all_extras)

if (
overall_result := project.launch_continuous_integration(
auto_fix=fix,
Expand Down
21 changes: 20 additions & 1 deletion coveo_stew/stew.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

from coveo_stew.ci.runner_status import RunnerStatus
from coveo_stew.environment import PythonEnvironment, PythonTool, find_python_tool
from coveo_stew.exceptions import NotAPoetryProject, StewException
from coveo_stew.exceptions import NotAPoetryProject, StewException, UsageError
from coveo_stew.metadata.poetry_api import PoetryAPI
from coveo_stew.metadata.python_api import PythonFile
from coveo_stew.metadata.stew_api import StewPackage
Expand Down Expand Up @@ -117,6 +117,25 @@ def _virtual_environments_cache(self) -> List[PythonEnvironment]:

return cache

def overrides_from_cli(
self, extras: Tuple[str, ...] = (), no_extras: bool = False, all_extras: bool = False
) -> None:
"""Overrides the project's options with the CLI arguments."""
if no_extras and (extras or all_extras):
raise UsageError("Cannot use --no-extras with --extras or --all-extras.")
if all_extras and (extras or no_extras):
raise UsageError("Cannot use --all-extras with --extras or --no-extras.")

if extras:
self.options.extras = list(extras)
self.options.all_extras = False
if no_extras:
self.options.extras = []
self.options.all_extras = False
if all_extras:
self.options.extras = []
self.options.all_extras = True

def relative_path(self, path: Path) -> Path:
"""returns the relative path of a path vs the project folder."""
return path.relative_to(self.project_path)
Expand Down

0 comments on commit 21c902e

Please sign in to comment.