The user's selection of tox test environments via ``-e`` or ``env_list`` config. It is in one of three forms: - A list of specific environments, instantiated with a string that is a comma-separated list of the environment names. (These may have spaces on either side of the commas whi
| 39 | |
| 40 | |
| 41 | class CliEnv: # noqa: PLW1641 |
| 42 | """The user's selection of tox test environments via ``-e`` or ``env_list`` config. |
| 43 | |
| 44 | It is in one of three forms: |
| 45 | |
| 46 | - A list of specific environments, instantiated with a string that is a comma-separated list of the environment |
| 47 | names. (These may have spaces on either side of the commas which are removed.) As a sequence this will be a |
| 48 | sequence of those names. |
| 49 | - "ALL" which is all environments defined by the tox configuration. This is instantiated with ``ALL`` either alone |
| 50 | or as any element of a comma-separated list; any other environment names are ignored. `is_all()` will be true and |
| 51 | as a sequence it will be empty. This prints in string representation as ``ALL``. |
| 52 | - The default environments as chosen by tox configuration. This is instantiated with `None` as the parameter, |
| 53 | `is_default_list()` will be true, and as a sequence this will be empty. This prints in string representation as |
| 54 | ``<env_list>``. |
| 55 | |
| 56 | """ |
| 57 | |
| 58 | def __init__(self, value: list[str] | str | None = None) -> None: |
| 59 | if isinstance(value, str): |
| 60 | raw = value |
| 61 | try: |
| 62 | value = list(extend_factors(raw)) or None |
| 63 | except ValueError: |
| 64 | value = [v.strip() for v in raw.split(",") if v.strip()] or None |
| 65 | self._names: list[str] | None = value |
| 66 | |
| 67 | def __iter__(self) -> Iterator[str]: |
| 68 | if not self.is_all and self._names is not None: # pragma: no branch |
| 69 | yield from self._names |
| 70 | |
| 71 | def __bool__(self) -> bool: |
| 72 | """A `CliEnv` is `True` if it's not the default set of environments.""" |
| 73 | return bool(self._names) |
| 74 | |
| 75 | def __str__(self) -> str: |
| 76 | return "ALL" if self.is_all else ("<env_list>" if self.is_default_list else ",".join(self)) |
| 77 | |
| 78 | def __repr__(self) -> str: |
| 79 | return f"{self.__class__.__name__}({'' if self.is_default_list else repr(str(self))})" |
| 80 | |
| 81 | def __eq__(self, other: object) -> bool: |
| 82 | if not isinstance(other, CliEnv): |
| 83 | return False |
| 84 | return self._names == other._names |
| 85 | |
| 86 | def __ne__(self, other: object) -> bool: |
| 87 | return not (self == other) |
| 88 | |
| 89 | def __iadd__(self, other: CliEnv) -> Self: |
| 90 | if other._names is not None: |
| 91 | if self._names is None: |
| 92 | self._names = list(other._names) |
| 93 | else: |
| 94 | self._names.extend(other._names) |
| 95 | return self |
| 96 | |
| 97 | @property |
| 98 | def is_all(self) -> bool: |
no outgoing calls
searching dependent graphs…