From a98ebd954d620e0d4192c95909e17349e57213b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan=20Pich=C3=A9?= Date: Fri, 12 Apr 2024 16:39:12 -0400 Subject: [PATCH] support extras --- README.md | 21 +++++++++++++++++++++ coveo_stew/metadata/stew_api.py | 21 ++++++++++++++++----- coveo_stew/stew.py | 7 ++++++- 3 files changed, 43 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index ddc7e8b..5db64c1 100644 --- a/README.md +++ b/README.md @@ -210,6 +210,27 @@ $ stew locate coveo-stew # Configuration +## stew + +Configuration is done through the `pyproject.toml` file; default values are shown: + +``` +[tool.stew] +build-without-hashes = false +pydev = false +build-dependencies = {} +extras = [] +all-extras = false +``` + +- **build-without-hashes**: Disables hashes when calling `pip` to download dependencies during `stew build`. +- **pydev**: See the [multiple-libraries](README_MULTIPLE_LIBRARIES.md) guide. +- **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`. +- **all-extras**: If true, all extras will be installed during `stew build`. Overrides the `extras` list. + +## stew ci Configuration is done through each `pyproject.toml` file; default values are shown: ``` diff --git a/coveo_stew/metadata/stew_api.py b/coveo_stew/metadata/stew_api.py index 4ebca69..3453c80 100644 --- a/coveo_stew/metadata/stew_api.py +++ b/coveo_stew/metadata/stew_api.py @@ -1,23 +1,34 @@ -from typing import Any, Mapping +from typing import Any, List, Mapping, Optional + +from coveo_styles.styles import echo from coveo_stew.metadata.poetry_api import dependencies_factory class StewPackage: - """Represents the coveo-specific sections of a pyproject.toml file.""" + """Represents the stew-specific sections of a pyproject.toml file.""" def __init__( self, *, - build: bool = False, + build: bool = False, # deprecated build_without_hashes: bool = False, pydev: bool = False, - build_dependencies: Mapping[str, Any] = None, + build_dependencies: Optional[Mapping[str, Any]] = None, + extras: Optional[List[str]] = None, + all_extras: bool = False, ) -> None: - self.build = build # we won't build a project unless this is specified. # poetry sometimes fail at getting hashes, in which case the export cannot work because pip will complain # that some files have a hash and some don't. This fixes it. self.build_without_hashes = build_without_hashes self.pydev = pydev # is this a one-ring-to-bind-them-all dev environment? # additional build-time dependencies self.build_dependencies = dependencies_factory(build_dependencies) + self.extras = extras + self.all_extras = all_extras + + if extras and all_extras: + echo.suggest( + "Both 'extras' and 'all_extras' are specified. 'extras' will be ignored; " + "consider removing it from your pyproject.toml." + ) diff --git a/coveo_stew/stew.py b/coveo_stew/stew.py index 95168ae..09df263 100644 --- a/coveo_stew/stew.py +++ b/coveo_stew/stew.py @@ -332,11 +332,16 @@ def install( # return unless we are cleaning a non-cleaned environment return - command = ["install"] + command: List[str] = ["install"] if sync: command.append(get_verb("--sync", target_environment)) if quiet and not self.verbose: command.append("--quiet") + if self.options.all_extras: + command.append("--all-extras") + elif self.options.extras: + for extra in self.options.extras: + command.extend(["--extras", extra]) self.poetry_run(*command, environment=target_environment) target_environment.installed = True