Added checks for invalid keys.#243
Conversation
|
This is a precursor look, but TravisCI is failing on the style check with the following: |
|
I'm wondering if we should take this opportunity to look into using a JSON Schema to validate the spec. This would get us away from having to manage the validation and just manage the schema itself. |
|
@kcathey -- I was just trying to find that yesterday because I recalled it. But I lost it in my sea of tabs... do you have a link to it? My google-fu failed me and I found everythig else JSON but that... |
|
Python JSONSchema https://python-jsonschema.readthedocs.io/ |
|
@ben-bay Why don't you submit these as separate issues so that they can be tracked and not lost. We can then also start discussions around them and get some community input specifically about those things. Submit this one as a bug.
Ans this as an enhancement request.
|
|
Sure. |
FrankD412
left a comment
There was a problem hiding this comment.
Overall, looking good. I left some feedback. The general things that are causing the TravisCI check to fail are as follows:
flake8 ./maestrowf
./maestrowf/datastructures/yamlspecification.py:71:1: E302 expected 2 blank lines, found 1
./maestrowf/datastructures/yamlspecification.py:75:80: E501 line too long (91 > 79 characters)
./maestrowf/datastructures/yamlspecification.py:81:1: E302 expected 2 blank lines, found 1
./maestrowf/datastructures/yamlspecification.py:216:80: E501 line too long (88 > 79 characters)
./maestrowf/datastructures/yamlspecification.py:379:80: E501 line too long (82 > 79 characters)
./maestrowf/datastructures/yamlspecification.py:450:80: E501 line too long (103 > 79 characters)
|
@ben-bay -- I just checked out your fork and rebased it on #247 just to test. I'm not getting warnings show up. However, it looks like the existing verification methods that are in place catch the simple things I put into my specification. I think that your new checking would be the preferable way forward and would improve the utility and functionality of those checks. I noticed you put your What do you think? I'd have no issues replacing the previous verification with your improved setup. |
Sure I can replace the verification logic. Also, you didn't see it, but I've got a lot of new functionality that uses the |
|
@ben-bay Awesome, I look forward to it. The verification logic has been due for an update for a while. 😄 |
|
Check out the diff to see the direction of my latest changes. I've removed the need for some of your original verification, but not all of it yet. Still working on that. |
|
@ben-bay You'll need to add |
|
Oh yeah duh |
|
So currently our spec can find and report 4 kinds of errors:
...then there's the matter of making the schemas exactly fit what maestro expects. I'm not all the way there, but |
FrankD412
left a comment
There was a problem hiding this comment.
So far, these changes look reasonable. I do need to test them locally. Your style checks are still failing on TravisCI -- please correct those.
|
Just wanted to note here, this PR has pointed out that Maestro prints out exceptions twice. Once I think because of logging and the other because I think raise naturally prints them. I think that I'll leave a comment in #248 to include that in its scope, since it has to do with what the logger is outputting. |
|
Without a lot of scrutiny, it's possible that this feature will introduce bugs and cause headaches down the line. So scrutinize away! Observation: |
|
@ben-bay When I tested your code earlier, Maestro did terminate. It would definitely stop and point out the key. I'll look through your recent commits. |
|
@FrankD412 it's the exception handling logic. At some places it was double-nested, so I stopped raising |
|
@ben-bay -- Got it. I just tested it and logging errors do show on my end, and it does continue executing as you mentioned. I did see earlier that the JSON schema package provides a |
|
Awesome, @ben-bay -- Checks passed. I ran my simple test and it seemed to run just fine, even printed the exception only once. I'll run a few more extensive things, but I think this is safe to mark as robust enough that it's not a WIP. I'll get back with a formal review later! :D |
FrankD412
left a comment
There was a problem hiding this comment.
Overall, I think this is a great addition. I left some comments, overall not drastic changes, the biggest two are the Specification.verify_schema call as it doesn't look like it's implemented in the base class, but rather here in YAMLSpecification and the moving of the verification call in verify_parameters.
I'm curious your thoughts about the sys.exit in the _verify method -- I've always been taught that minimizing exit points is best. And moving the try/catch to maestro.py would make it so that we can use an enumeration to return a code for the error. What do you think?
FrankD412
left a comment
There was a problem hiding this comment.
Just some bug fixes I found that will fix the monitoring of the env section of the spec. The last thing that needs sorting is that when the env section is verified, it prints out a message that says the error is in the env section as a whole rather than git or paths sections. Haven't found where to set that yet.
|
Awesome -- I've been testing it the last 15 or so minutes and things appear to be working. This PR actually uncovered some bugs that I wasn't aware of, so yay! Thanks for fixing the things this exposed. I noticed something odd about the schema -- not how you defined it but with how This PR also seems to close #238 -- I wanted to assign you the issue since this seems to close it, but was surprised to find that I couldn't. Not sure why, I'll track that down. |
FrankD412
left a comment
There was a problem hiding this comment.
Alright! Things appear to be working -- once the TravisCI tests go through I'll merge. From what I can tell, the flake8 checks pass on my local machine, so I don't expect them to fail on Travis. Do you mind squashing the commits down so that you get credit for all the work you've put into this. Thanks Ben!
| "name": {"type": "string", "minLength": 1}, | ||
| "description": {"type": "string", "minLength": 1} | ||
| }, | ||
| "additionalProperties": false, |
There was a problem hiding this comment.
Just a quick comment -- I was testing this and found that this should probably be set to true. The description block is meant to have other types of information that isn't necessarily name and description. Just a comment, I didn't think this was worth un-approving the PR.
|
@ben-bay -- It looks like you need to run a small rebase just to squash the merge commit in your branch. I ran it locally on my end, and it was just fixing the requirements.txt and maestro.py conflicts. |
added checks for valid keys branch updates working on validation added schema file updates fixed spec fixed spec added jsonschema to deps updates ran black on yamlspecification.py specified newest jsonschema version added manifest added include_package_data to setup.py reformatted json experimental package_data fixed path fixed path fixed path again reverted newline added check for empty strings reworked exception logic implemented reviewer suggestions, shifted exception logic, renamed redundant variables renamed variable removed unused import added missing `self.verify_environment()` call Co-Authored-By: Francesco Di Natale <[email protected]> paths and git dependencies are now array types Co-Authored-By: Francesco Di Natale <[email protected]> removed redundant logic swapped number type to integer moved env schema validation to top, which avoids some types of ambiguous errors removed test yaml removed some additionalProperties restrictions unknown commit removed debug print
|
I ~think~ I successfully rebased and fixed the conflicts. |
This is my first attempt at adding valid key checking to Maestro. Why? Because indentation slip ups and typos can screw up a yaml spec. Worse, this type of error can be difficult to trace.
P.S. I'm sure I missed some keys that Maestro supports in
step.cmd, so make sure to remind me of those.P.P.S. Your
loggerappears to be broken. You'll only see this working for now if you replace mylogger.warningwith aprint.P.P.P.S. Speaking of logging, have you considered using color? Merlin is using the open source library coloredlogs.