Skip to content
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

Fixes #8228: Add constraints to ncf parameters #350

Conversation

VinceMacBuche
Copy link
Member

@@ -16,6 +16,8 @@
import sys
import os
import codecs
import ncf_constraints
from pprint import pprint
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can remove this now, I guess it was just used for debugging

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Up?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I never remove pprint, you always need it.
Having to add it each time you debug and removing it just after is very tiring. Moreover it costs almost nothing.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I clearly agree with peck, we always need it

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, fine. It's nice to answer comments though, even if you don't agree with them :)

@VinceMacBuche VinceMacBuche force-pushed the ust_8228/add_constraints_to_ncf_parameters branch from 956884c to 76b1c25 Compare May 11, 2016 16:19
@VinceMacBuche
Copy link
Member Author

PR updated

@VinceMacBuche
Copy link
Member Author

As a reminder:
Still need to add comments.
Check default cases are still treated (maybe define default constraint: allow_empty : false, allow_witthepace: false)

"list" : {
"check" : from_list
, "type" : list
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-reading the email discussion we had about specs makes me notice the name you've used here: "list". I don't think this is a good name, because it is not clear what "constraint" "list" is imposing.

I prefer "enum" (which, to me at least, makes it clear that this constraint in an enumeration of possible values), but I'm open to other terms. Maybe "values"?

Thoughts?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if it's an enumeration, in the web world we use "select", which is fairly easily understood.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the 'select' ! second choice would be 'values'. I don't like 'enum', and agree that list is not a good choice

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'select' works for me. It matches nicely with Rudder's Techniques metadata.xml terminology, too.

@VinceMacBuche
Copy link
Member Author

PR updated

@VinceMacBuche VinceMacBuche force-pushed the ust_8228/add_constraints_to_ncf_parameters branch from bb99c43 to f4d062d Compare May 23, 2016 09:43
@peckpeck
Copy link
Member

There should be an issue for documenting the constraint syntax

@peckpeck
Copy link
Member

This PR needs a rebase


def match_regex(parameter, regex):
match = re.search(regex, parameter)
return match is not None
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

re.S and re.M should be considered
It means that a parameter should be considered as a whole and we are matching it as is, not with separate lines. A new line can still be matched with \n, which is expected. And we can match things that couldn't be matched without those flags.

Example:

  • the regex r"^A.\nB.$" matches a line starting with A followed by a line starting with B. This is not possible without re.M
  • with re.S r"A.B." could match 2 lines with A in the first one and B in the second one. This may be counter intuitive.

So I'd say, use re.MULTILINE only.

Anyway, whatever the final behavior, the multiline case must be carefully documented.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should use re.UNICODE too, because all our strings are unicode and i would expect '\w' to match 'é' in the general case.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should use re.M

I think we want to check the whole value with our regex, so with you first case you would match
A
A
B

If you use re.M and would not match with other cases, and i think we don't want to match

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, I mixed up the definition of re.M, it is the opposite.

@peckpeck
Copy link
Member

Everything else is ok for me

@VinceMacBuche
Copy link
Member Author

VinceMacBuche commented Jun 8, 2016

@peckpeck I made a separate commit so you can look on the changes
edit: typo, s/comment/commit...

@VinceMacBuche VinceMacBuche force-pushed the ust_8228/add_constraints_to_ncf_parameters branch 2 times, most recently from c006e07 to 2491551 Compare June 10, 2016 09:59

def not_match_regex(parameter_value, regex):
return not match_regex(parameter_value, regex)
result = match_regex(parameter_value, regex) is not None
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be a re.U here

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is changed in next commit :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and match_regexp is not re.match !

@VinceMacBuche
Copy link
Member Author

PR updated

@VinceMacBuche VinceMacBuche force-pushed the ust_8228/add_constraints_to_ncf_parameters branch from 681c612 to 7efc3e6 Compare June 13, 2016 14:00
@VinceMacBuche
Copy link
Member Author

PR updated

@VinceMacBuche VinceMacBuche force-pushed the ust_8228/add_constraints_to_ncf_parameters branch from 7efc3e6 to 5abd7cb Compare June 13, 2016 14:14
@@ -114,11 +114,8 @@ def check_parameter(parameter_value, parameter_constraints):
constraint_set = constraints

# Check that our value contains a variable or not
value_without_variables = re.sub(r'[\$@][\{\(][a-zA-Z0-9\[\]_.-]+[\}\)]', "", parameter_value)
if parameter_value != value_without_variables:
if re.search(r'[$@][{(][$@{(a-zA-Z0-9[\]_.-]+[})]', parameter_value) is not None :
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just for information, ][ instead of [] works too

@VinceMacBuche
Copy link
Member Author

PR updated

@VinceMacBuche VinceMacBuche force-pushed the ust_8228/add_constraints_to_ncf_parameters branch from 5abd7cb to a808aa9 Compare June 13, 2016 14:33
@Normation-Quality-Assistant
Copy link
Contributor

This PR is not mergeable to upper versions.
Since it is "Ready for merge" you must merge it by yourself using the following command:
rudder-dev merge #350
-- Your faithful QA

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants