diff --git a/README.md b/README.md index 597c09d..148a4fa 100644 --- a/README.md +++ b/README.md @@ -144,6 +144,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 ` *(v3.1.1)* will install the specified extra(s) for this run. Can be specified multiple times. +- `--all-extras` *(v3.1.1)* will install all extras for this run. +- `--no-extras` *(v3.1.1)* 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. @@ -231,7 +234,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.1.1)* Can be specified at execution time with `stew ci --extra --extra `. - **all-extras**: If true, all extras will be installed during `stew build` and `stew ci`. Overrides the `extras` list. + - *(v3.1.1)* 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. diff --git a/coveo_stew/commands.py b/coveo_stew/commands.py index bb29cee..2d2bf3e 100644 --- a/coveo_stew/commands.py +++ b/coveo_stew/commands.py @@ -323,6 +323,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, @@ -333,6 +336,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: @@ -345,6 +351,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, diff --git a/coveo_stew/stew.py b/coveo_stew/stew.py index af6059c..f8a27c4 100644 --- a/coveo_stew/stew.py +++ b/coveo_stew/stew.py @@ -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 @@ -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)