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

Adding linting checks for buildbot_steps.yml #14051

Merged
merged 1 commit into from Dec 9, 2016

Conversation

@leikahing
Copy link
Contributor

leikahing commented Nov 3, 2016

This pull request adds some tidy checks around YAML files, and specifically buildbot_steps.yml.

Tidy checks added:

  • YAML files are checked for well-formedness/parse-ability
  • Whether a YAML file has duplicate keys
  • Whether a buildbot_steps.yml file contains only mappings to list-of-strings.

  • ./mach build -d does not report any errors
  • ./mach test-tidy does not report any errors
  • These changes fix #13838 (github issue number if applicable).
  • There are tests for these changes OR

…ing checking for correct mappings and duplicate YAML keys. Added unit tests to test_tidy.py.


This change is Reviewable

@leikahing leikahing force-pushed the leikahing:tidy-check-buildbot-steps branch from 6a7aae3 to 7357244 Nov 3, 2016
@leikahing
Copy link
Contributor Author

leikahing commented Nov 3, 2016

This is still a work-in-progress per @aneeshusa. I'd like some feedback on if I'm taking the right approach with adding linting checks for buildbot_steps files, and YML files in general, along with using somewhat-descriptive messages.

@wafflespeanut
Copy link
Member

wafflespeanut commented Nov 4, 2016

@bors-servo
Copy link
Contributor

bors-servo commented Nov 7, 2016

The latest upstream changes (presumably #14092) made this pull request unmergeable. Please resolve the merge conflicts.

@leikahing leikahing force-pushed the leikahing:tidy-check-buildbot-steps branch from 7357244 to f247ca4 Nov 9, 2016
if not file_name.endswith("buildbot_steps.yml"):
raise StopIteration

# YAML specification doesn't necessarily prevent

This comment has been minimized.

@aneeshusa

aneeshusa Nov 15, 2016

Member

necessarily prevent -> explicitly disallow

return loader.construct_mapping(node, deep)


class SafeYamlLoader(yaml.SafeLoader):

This comment has been minimized.

@aneeshusa

aneeshusa Nov 15, 2016

Member

I don't see the benefit of this over using yaml.SafeLoader in the qualified form.

This comment has been minimized.

@leikahing

leikahing Nov 15, 2016

Author Contributor

I guess for the unit tests, it's not necessary. Only reason to do this is because I do the SafeYamlLoader.add_constructor later on, which mutates the YAML loader. If I did this to the default yaml.SafeLoader, it would modify it globally.

This comment has been minimized.

@aneeshusa

aneeshusa Nov 15, 2016

Member

Oh, I misread and thought we were calling add_constructor on an object returned by the Loader constructor, i.e.

loader = yaml.SafeLoader()
loader.add_constructor(...)
yaml.load(contents, loader=loader)

Since we're mutating the Loader itself, having the SafeYamlLoader seems like a better idea, so let's go back to that approach.

This comment has been minimized.

@aneeshusa

aneeshusa Nov 15, 2016

Member

Oh, and please add a comment with this explanation for why we're making a subclass.

Copy link
Member

aneeshusa left a comment

Looks pretty good overall - just a few nits that I can see right now. The error messages are fine for now IMO.

# buildbot_steps.yml as it could lead to confusion
SafeYamlLoader.add_constructor(
yaml.resolver.BaseResolver.DEFAULT_MAPPING_TAG,
duplicate_key_yaml_constructor)

This comment has been minimized.

@aneeshusa

aneeshusa Nov 15, 2016

Member

nit: closing paren on next line

@leikahing
Copy link
Contributor Author

leikahing commented Nov 15, 2016

@aneeshusa Thanks for the feedback/review! Just updated my PR with changes addressing the issues you pointed out.

Copy link
Member

aneeshusa left a comment

Everything else looks good aside from these last two nits, so go ahead and squash everything into one commit. Please also update the commit message to follow the guidelines I mentioned on your other PR.


def lint_buildbot_steps_yaml(mapping):
# Check for well-formedness of contents
# A well-formed buildbot_steps.yml should just be a map to list of strings

This comment has been minimized.

@aneeshusa

aneeshusa Nov 15, 2016

Member

nit: remove just

@leikahing leikahing force-pushed the leikahing:tidy-check-buildbot-steps branch from e0373c6 to 81b257f Nov 16, 2016
@leikahing leikahing changed the title [WIP] Adding linting checks for buildbot_steps.yml Adding linting checks for buildbot_steps.yml Nov 16, 2016
@leikahing
Copy link
Contributor Author

leikahing commented Dec 7, 2016

Review ping @aneeshusa

@aneeshusa
Copy link
Member

aneeshusa commented Dec 7, 2016

Sorry about the delay! Looks good, but I'd still like to move back to subclassing yaml.SafeLoader (along with an explanatory comment) now that you've explained why.

@leikahing leikahing force-pushed the leikahing:tidy-check-buildbot-steps branch from 81b257f to e28d1b2 Dec 8, 2016
@leikahing
Copy link
Contributor Author

leikahing commented Dec 8, 2016

@aneeshusa Sorry, I didn't see the continuation of our code review discussion - GitHub apparently doesn't notify me of that.

I put the SafeLoader subclass back in with a comment, squashed my commits, and re-pushed.

@aneeshusa
Copy link
Member

aneeshusa commented Dec 8, 2016

Thanks @birryree! @bors-servo r+

@bors-servo
Copy link
Contributor

bors-servo commented Dec 8, 2016

📌 Commit e28d1b2 has been approved by aneeshusa

@bors-servo
Copy link
Contributor

bors-servo commented Dec 8, 2016

Testing commit e28d1b2 with merge 5251f02...

bors-servo added a commit that referenced this pull request Dec 8, 2016
Adding linting checks for buildbot_steps.yml

This pull request adds some tidy checks around YAML files, and specifically `buildbot_steps.yml`.

Tidy checks added:

* YAML files are checked for well-formedness/parse-ability
* Whether a YAML file has duplicate keys
* Whether a `buildbot_steps.yml` file contains only mappings to list-of-strings.

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [x] These changes fix #13838 (github issue number if applicable).

<!-- Either: -->
- [X] There are tests for these changes OR

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

…ing checking for correct mappings and duplicate YAML keys. Added unit tests to test_tidy.py.

<!-- Reviewable:start -->

---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/14051)
<!-- Reviewable:end -->
@bors-servo
Copy link
Contributor

bors-servo commented Dec 8, 2016

💔 Test failed - linux-dev

@Ms2ger
Copy link
Contributor

Ms2ger commented Dec 8, 2016

python/tidy/servo_tidy/tidy.py:707: E302 expected 2 blank lines, found 1 
This commit adds tidy checks for buildbot_steps.yml, as well as unit
tests. These checks include:

* Checking buildbot_steps.yml can be parsed by a YAML loader
* buildbot_steps.yml does not contain duplicate keys
* buildbot_steps.yml keys map to a list of strings
@leikahing leikahing force-pushed the leikahing:tidy-check-buildbot-steps branch from e28d1b2 to aceb60e Dec 9, 2016
@leikahing
Copy link
Contributor Author

leikahing commented Dec 9, 2016

Forgot to run test-tidy before I pushed the last commit. 😞

Pushed an update that resolves all that.

@aneeshusa
Copy link
Member

aneeshusa commented Dec 9, 2016

@bors-servo
Copy link
Contributor

bors-servo commented Dec 9, 2016

📌 Commit aceb60e has been approved by aneeshusa

@bors-servo
Copy link
Contributor

bors-servo commented Dec 9, 2016

Testing commit aceb60e with merge 21ad1c2...

bors-servo added a commit that referenced this pull request Dec 9, 2016
Adding linting checks for buildbot_steps.yml

This pull request adds some tidy checks around YAML files, and specifically `buildbot_steps.yml`.

Tidy checks added:

* YAML files are checked for well-formedness/parse-ability
* Whether a YAML file has duplicate keys
* Whether a `buildbot_steps.yml` file contains only mappings to list-of-strings.

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [x] These changes fix #13838 (github issue number if applicable).

<!-- Either: -->
- [X] There are tests for these changes OR

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

…ing checking for correct mappings and duplicate YAML keys. Added unit tests to test_tidy.py.

<!-- Reviewable:start -->

---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/14051)
<!-- Reviewable:end -->
@bors-servo
Copy link
Contributor

bors-servo commented Dec 9, 2016

@bors-servo bors-servo merged commit aceb60e into servo:master Dec 9, 2016
3 checks passed
3 checks passed
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
homu Test successful
Details
@leikahing leikahing deleted the leikahing:tidy-check-buildbot-steps branch Dec 10, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

6 participants
You can’t perform that action at this time.