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
Improved factor selection to allow multiple uses of -f
for "OR" and to allow hyphenated factors
#2786
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Previously, when `-f` was passed, it overwrote the last value. The result was that `-f foo -f bar` was equivalent to only passing `-f bar`. Under the new behavior, `-f foo -f bar` combines `foo` and `bar` as selection criteria, using OR-semantics. Envs matching `foo OR bar` will be selected. The existing multi-value argument behavior for `-f` is retained, in which `-f foo bar` means `foo AND bar`. The behaviors can be combined to express a variety of environment selections which were not previously possible in a single invocation. e.g. `-f foo bar -f baz` meaning `(foo AND bar) OR baz`. No existing tests fail, and the new behavior is checked by a new test. The help message for `-f` is updated.
The existing parsing of factors allows multiple factors to be selected by passing them as multiple arguments to the `-f` flag. For example, `-f foo bar` to pass both `foo` and `bar` as factors. This can now be passed equivalently using `-f foo-bar`. The meaning of this usage is identical to `-f foo bar`. A new test checks the behavior, and very closely mirrors the existing `-f` selection test so that their outputs are exactly equivalent.
These three tests are nearly identical in structure, and rely upon the same project configuration. Convert from three distinct test cases to a single parametrized test. Also apply pre-commit, which does some mild reformatting.
gaborbernat
requested changes
Dec 29, 2022
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, fix the type checker issues.
1e75edd
to
2be500b
Compare
gaborbernat
reviewed
Dec 29, 2022
gaborbernat
reviewed
Dec 29, 2022
gaborbernat
reviewed
Dec 29, 2022
gaborbernat
reviewed
Dec 29, 2022
- use tuple instead of list for immutable data - use `continue` and `break` to skip unnecessary loop iterations
gaborbernat
requested changes
Dec 29, 2022
gaborbernat
reviewed
Dec 29, 2022
- convert args from list[str] to tuple[str, ...] - reformat str concat into a `.format()` usage
This check cannot be reached because it relies on an impossible combination of factors and labels.
I think I've addressed the outstanding changes needed. If this is going to squash merge, I think it's ready. Otherwise, I'd like to rebase it to tidy the history a little bit. |
gaborbernat
approved these changes
Dec 29, 2022
descope bot
added a commit
to descope/django-descope
that referenced
this pull request
Jan 12, 2023
This PR contains the following updates: | Package | Type | Update | Change | Pending | |---|---|---|---|---| | [tox](https://togithub.com/tox-dev/tox) ([changelog](https://tox.wiki/en/latest/changelog.html)) | dev | minor | `4.0.19` -> `4.1.0` | `4.2.8` (+11) | --- ### Release Notes <details> <summary>tox-dev/tox</summary> ### [`v4.1.0`](https://togithub.com/tox-dev/tox/releases/tag/4.1.0) [Compare Source](https://togithub.com/tox-dev/tox/compare/4.0.19...4.1.0) #### What's Changed - docs(config): Fix minor typo by [@​rpatterson](https://togithub.com/rpatterson) in [tox-dev/tox#2785 - Update user_guide.rst by [@​jamwil](https://togithub.com/jamwil) in [tox-dev/tox#2787 - Improved factor selection to allow multiple uses of `-f` for "OR" and to allow hyphenated factors by [@​sirosen](https://togithub.com/sirosen) in [tox-dev/tox#2786 #### New Contributors - [@​rpatterson](https://togithub.com/rpatterson) made their first contribution in [tox-dev/tox#2785 - [@​jamwil](https://togithub.com/jamwil) made their first contribution in [tox-dev/tox#2787 - [@​sirosen](https://togithub.com/sirosen) made their first contribution in [tox-dev/tox#2786 **Full Changelog**: tox-dev/tox@4.0.19...4.1.0 </details> --- ### Configuration📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).🚦 **Automerge**: Enabled.♻ **Rebasing**: Whenever PR is behind base branch, or you tick the rebase/retry checkbox.🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNC45OS4yIiwidXBkYXRlZEluVmVyIjoiMzQuOTkuMiJ9--> Co-authored-by: descope[bot] <descope[bot]@users.noreply.github.com>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Summary
To enable better factor selection, this PR applies two changes. (resolves #2766)
-f
can now be passed multiple times. Envs matching any-f
usage are selected (OR) on top of the existing behavior that envs must match all factors in a given usage (AND).-f
will now split factors with hyphens.(1) is the key functional change. (2) is not strictly necessary, but makes usage conform a little better to user expectations (or at least the expectations of one user!👋 😉 ).
Example Usage
Consider an env list as follows:
Prior to this change, the following usage was valid:
tox l -f py39 django20
and would selectpy39-django20 py39-django20-cov
.After this change, the same selection can be expressed with
tox l -f py39-django20
. Furthermore, the following selection which was previously not possible can be expressed:The groups of selections are combined with OR semantics, but the individual selections are combined with AND.
Implementation Notes
I separated these two features into two commits, anticipating that (2) might be contentious. I would like to keep it as I don't think it adds much complexity, but I'm ready and willing to pull it out if necessary.
The parsing/interpretation of factors is now separated out into a dedicated helper method, which I note most other CLI args do not have. It looks like the CLI code avoids breaking things apart into too many small functions, but I thought this case benefits enough in terms of readability to be worth it. Again, I'm happy to change this in response to feedback.
The help message is rather long for this now, and I'm still not sure it's fully descriptive. Perhaps a future FAQ on how to use factors and labels would help.
Checklist
tox -e fix
)docs/changelog
folder