-
Notifications
You must be signed in to change notification settings - Fork 810
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
Artifact string name validation #817
Conversation
Codecov Report
@@ Coverage Diff @@
## master #817 +/- ##
==========================================
+ Coverage 56.38% 56.39% +0.01%
==========================================
Files 116 116
Lines 8603 8605 +2
==========================================
+ Hits 4851 4853 +2
Misses 3752 3752
Continue to review full report at Codecov.
|
BentoServiceArtifact(name) | ||
assert "'name' must start with a letter" in str(e.value) | ||
|
||
name = "_" |
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 like this case does fit the requirement description: 'name' must start with a letter (a-z|A-Z) or underscore character and can only contain alpha-numeric characters and underscores
Could you take a look and see if the benotoml.utils.isidentifier
method work for this check?
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.
Actually, since we dropped support for PY2, we can probably just use the name.isidentifier()
here. The error message could be improved as well, e.g.:
"Artifact name must be a valid python identifier, a string is considered a valid identifier if it only contains alphanumeric letters (a-z) and (0-9), or underscores (_). A valid identifier cannot start with a number, or contain any spaces."
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.
I changed the regex to name.isidentifier()
and the error message with the one you suggested.
Btw, benotoml.utils.isidentifier
function was failing for the check and the check with accents (same for name.isidentifier()
).
Those, 2 tests were not fitting the requirements of a python identifier. I was a bit to restrictive when I read the definition and actually you can define variables names with accents or using the Underscore(_) character even if it is not recommended.
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.
Thanks for updating the PR @AlexDut, surprised that characters with accents work for isidentifier
, but I think technology as long as it is a valid python identifier we can use it as a property name for accessing the artifact.
c6b49b2
to
0bd0620
Compare
* Add artifact name validation * Format code for linter * Use isidentifier + Better error message Co-authored-by: Alexis Dutot <alexis.dutot@linkfluence.com>
Description
Add simple validation for artifact's 'name' attribute. As this name is used as a property to access the artifact, the string should respect Python's variable naming conventions. Those are the following:
The check is done in
BentoServiceArtifact
init method.Some tests were added for the validation.
Motivation and Context
Issue #747
How Has This Been Tested?
Following the
DEVELOPMENT.md
file:Types of changes
Components (if applicable)
Checklist:
./dev/format.sh
and./dev/lint.sh
script have passed(instructions).