-
Notifications
You must be signed in to change notification settings - Fork 81
✨🎄 Add parse_variants to needs_fields / needs_extra_link, deprecate needs_variant_options
#1614
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
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1614 +/- ##
==========================================
+ Coverage 86.87% 88.33% +1.45%
==========================================
Files 56 70 +14
Lines 6532 9947 +3415
==========================================
+ Hits 5675 8787 +3112
- Misses 857 1160 +303
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
c18ba33 to
60c41c1
Compare
…ate `needs_variant_options`
716e3fd to
72c4494
Compare
ubmarco
left a comment
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.
Looks good! We should document how to use variants for array items. Can be done in another PR. I added test cases for typed variants. If you look at those you see that multi value input for a non-array field is not detected as error:
| :field_bool: <<['tag_a' in build_tags]:1, 0>>, <<['tag_b' in build_tags]:0, 1>> |
It's picking up the first value and does not care about the rest. It should complain, as it does for non-variant literals:
:field_bool: 1, 0
then I correctly get
Need could not be created: Extra option 'field_bool' is invalid: Cannot convert '1, 0' to boolean
I don't think this is behaving as you think @ubmarco see: sphinx-needs/sphinx_needs/needs_schema.py Lines 269 to 292 in f0b9fbd
The entire thing is parsed as a single variant, e.g. Of course, we could consider changing that behaviour, like finding the "first" closing |
parse_variants to needs_fields / needs_extra_link, deprecate needs_variant_optionsparse_variants to needs_fields / needs_extra_link, deprecate needs_variant_options
|
I'm confused about the behavior. When looking at
which is an array of int, it delivers [1, 3]:sphinx-needs/tests/__snapshots__/test_variants.ambr Lines 123 to 124 in 055c5e9
If the outer type is an array, doesn't it split first?sphinx-needs/sphinx_needs/needs_schema.py Line 890 in 055c5e9
So works as expected from my point of view. After the split the type is checked and correctly evaluated. |
Yes, the parsing logic for arrays is different to non-arrays, that's the point. Anyway, the parsing logic had not changed in this PR |
This pull request introduces a new, more flexible way to enable variant support for need fields and links by adding a
parse_variantsoption to the configuration. It deprecates the oldneeds_variant_optionssetting in favor of specifyingparse_variantsdirectly inneeds_fieldsandneeds_extra_links. The documentation and codebase are updated to reflect this change, improving clarity and flexibility for users configuring variant handling.Configuration and API changes:
Added a
parse_variantsboolean option toneeds_fieldsandneeds_extra_links, allowing users to enable variant parsing on a per-field or per-link basis. This replaces the previous globalneeds_variant_optionslist.Updated the API (
add_extra_option) and configuration loading logic to accept and propagate the newparse_variantsparameter.Deprecation and backward compatibility:
Deprecated the
needs_variant_optionsconfiguration option. If used, a warning is issued, and backward compatibility is maintained by enablingparse_variantsfor the specified fields.Documentation updates:
Updated documentation in
docs/configuration.rstanddocs/dynamic_functions.rstto describe the newparse_variantsoption and markneeds_variant_optionsas deprecated. Examples and usage instructions are revised accordingly.Schema and internal logic changes:
parse_variantsinstead ofallow_variant_functions, and updated related variable names and validation.Example and test configuration updates:
docs/ubproject.toml) to use the newparse_variantsoption instead of the deprecatedvariant_optionslist.