Introduce ContextDimension#293
Conversation
|
blocked by #294 |
|
This does not look good: |
| return self.value.version_cmp( | ||
| self._make_value(other), | ||
| ordered=False, | ||
| case_sensitive=self.case_sensitive, |
There was a problem hiding this comment.
Case sensitivity is broken now
python - <<'PY'
from fmf.context import Context
context = Context(component="python3-3.8.5-5.fc32")
context.case_sensitive = False
print(context.matches("component == python3")) # True
print(context.matches("component == PYTHON3")) # Expected True, PR returns False
PY
True
False
There was a problem hiding this comment.
Yes, the tests show that. Please look at the current design and provide a suggestion. There are various courses of action here:
- Delete the
case_sensitiveoption and tests - Fail on unsupported
case_sensitiveoption - Deprecate
case_sensitiveand do some ugly workaround - Maintain the current support
There is a broader discussion necessary on the support, e.g. in tmt we are mixing both case_sensitive = False in various adjust and the default in enabled_by_when for example.
There was a problem hiding this comment.
I have no idea why the feature was added, I think we will need to find out first. But I would prefer first to provide a drop in replacement and work on dropping any functionality separately.
There was a problem hiding this comment.
Here are the facts I could gather:
tmtis the only consumer of context other thanfmfitself, andfmfcli does not expose context either. Let me know of instances that I did not look for, I consideredartemis-pools,rh-kernel-stqe/python-stqe, andfmf-jinjacase_sensitivewas added in Allow case-insensitive matching of context dimension values #195, Handle all context dimension values case insensitive tmt#2357- The case-sensitive handling in tmt is not consistent as seen in https://github.com/teemtee/tmt/blob/ee7b865b111c6f6d41114905431286ffd07ab807/tmt/steps/__init__.py#L2111-L2127
I personally don't see a reason to be conservative about this one since this change would need tmt change as well to be useful. There already is customizability and guidance if new users pop up. In the meantime, please review the design and the suggested way to opt-in the case-sensitivity! Right now the commits are very minimal and focused on the main functionality before it starts growing with the test adjustments and such.
@therazix @psss were involved in the introduction of the case-sensitive feature, so I will wait for their feedback and context in the meantime.
There was a problem hiding this comment.
Thanks much for preparing the draft of this. The overall design sounds good to me. There was a tangible use case behind introducing the case-insensitive comparison so we definitely want to keep the insensitive handling at least. By default, I'd vote for keeping the option to choose the behavior. Defining the sensitivity at the ContextDimension class level looks like a good approach to me. But, if this would complicate the implementation too much, I wouldn't be strongly against dropping case-sensitive altogether, especially if there are no clear consumers for it.
Before diving into all related detailed changes, could we outline how the is defined and is not defined operators could be handled? Would it be some special separate value-less class? That way sounds a bit complicated to me. If possible, I'd rather suggest to keep a single ContextDimension and somehow allow value-less handling inside it. @LecrisUT, do you see a way how we could implement the second path?
There was a problem hiding this comment.
By default, I'd vote for keeping the option to choose the behavior. Defining the sensitivity at the
ContextDimensionclass level looks like a good approach to me.
That should still be available. The part that I would prefer to be dropped is the interface at the Context level and make ContextDimension the source of truth for that instead. I could make the current case_sensitive api still work, but it would be ugly and have potential race condition-like bugs.
Before diving into all related detailed changes, could we outline how the
is definedandis not definedoperators could be handled?
Good question, I do not have a good vision for those, here are some possibilities:
- Keep them at the
Contextlevel as special hard-coded values (current state) - Extend the other 2 regex patterns with decorator and generalize them in
Context Same as ☝️ but try to add it to(quite difficult as I think about it, rather not)ContextDimension(somehow) instead
Would it be some special separate value-less class?
Don't think we would need that. If needed I think we can just split the operators decorator and add them to a separate registrar (options 2 and 3 in above). The main thing here would be to generalize the Operators so that it can hook to other class.
There was a problem hiding this comment.
That should still be available. The part that I would prefer to be dropped is the interface at the
Contextlevel and makeContextDimensionthe source of truth for that instead. I could make the currentcase_sensitiveapi still work, but it would be ugly and have potential race condition-like bugs.
Sounds good to me to keep this at the ContextDimension level. Just to clarify on a tangible example: So if tmt would like to disable case sensitivity, it could inherit from DefaultContextDimension and change the class variable to False and handle all provided context dimensions with this custom class. No other change(s) needed?
If needed I think we can just split the operators decorator and add them to a separate registrar (options 2 and 3 in above).
Separate register for unary and binary operators sounds ok to me.
There was a problem hiding this comment.
So if
tmtwould like to disable case sensitivity, it could inherit fromDefaultContextDimensionand change the class variable toFalseand handle all provided context dimensions with this custom class. No other change(s) needed?
Exactly. I can update the tests to show this.
If needed I think we can just split the operators decorator and add them to a separate registrar (options 2 and 3 in above).
Separate register for unary and binary operators sounds ok to me.
👍
There was a problem hiding this comment.
So if
tmtwould like to disable case sensitivity, it could inherit fromDefaultContextDimensionand change the class variable toFalseand handle all provided context dimensions with this custom class. No other change(s) needed?Exactly. I can update the tests to show this.
Good! 👍
| _registrar = {} | ||
|
|
||
| class TmtContext(fmf.context.Context): | ||
| _dimensions = TmtContextDimension |
There was a problem hiding this comment.
This should now be _context_dimensions ?
There was a problem hiding this comment.
Sure, but I will wait until there is a review on the design instead of ping-ponging between implementations. Please provide feedback on the design as well
|
LGTM, in general the operator-based approach fits my view how these things should be implemented. I guess I will have a comment or two, mostly minor ones, when I get back in the evening. |
4dba56d to
3204c6c
Compare
Signed-off-by: Cristian Le <git@lecris.dev>
This is quite a big one, but I will keep the commits relatively logically contained for easier review commit by commit. The idea here is:
ContextDimensionContextDimensionby sub-classing it and defining the_dimension_nameit is linked tocreate_defaultis used, which by default wraps aroundContextValuefor backwards-compatibilityContextDimensioninstead.Operatorsand decorators were added to manage these more dynamicallystaticmethod->classmethodto allow expanding theContextclassre_expression_triplewas made a function for the reason aboveCloses #289
Depends-on #297
Checklist