servo: Merge #19720 - Update buildbot_steps lint to handle env variables (from aneeshusa:support-env-vars-in-buildbot-steps); r=jdm

https://github.com/servo/saltfs/pull/687 added support
for specifying environment variables in `buildbot_steps.yml`.
Update the servo-tidy buildbot_steps.yml linter to reflect this.

Use the voluptuous Python library (BSD 3-clause license) for validation
in lieu of a much larger hand-written implementation.

Extracted out of #17171. Helps with servo/saltfs#770.

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

<!-- Either: -->
- [x] There are tests for these changes OR
- [ ] These changes do not require tests because they change the tests

Source-Repo: https://github.com/servo/servo
Source-Revision: 6a6dda526961b7bb7b856e8310ffc165d8bd39aa
This commit is contained in:
Aneesh Agrawal
2018-01-09 11:40:27 -06:00
parent 60d99d8fea
commit f46a38c6a3
6 changed files with 50 additions and 34 deletions

View File

@@ -17,8 +17,10 @@ import re
import StringIO
import subprocess
import sys
import colorama
import toml
import voluptuous
import yaml
from licenseck import MPL, APACHE, COPYRIGHT, licenses_toml, licenses_dep_toml
@@ -775,15 +777,24 @@ def duplicate_key_yaml_constructor(loader, node, deep=False):
def lint_buildbot_steps_yaml(mapping):
# Check for well-formedness of contents
# A well-formed buildbot_steps.yml should be a map to list of strings
for k in mapping.keys():
if not isinstance(mapping[k], list):
raise ValueError("Key '{}' maps to type '{}', but list expected".format(k, type(mapping[k]).__name__))
from voluptuous import Any, Extra, Required, Schema
# check if value is a list of strings
for item in itertools.ifilter(lambda i: not isinstance(i, str), mapping[k]):
raise ValueError("List mapped to '{}' contains non-string element".format(k))
# Note: dictionary keys are optional by default in voluptuous
env = Schema({Extra: str})
commands = Schema([str])
schema = Schema({
'env': env,
Extra: Any(
commands,
{
'env': env,
Required('commands'): commands,
},
),
})
# Signals errors via exception throwing
schema(mapping)
class SafeYamlLoader(yaml.SafeLoader):
@@ -811,8 +822,8 @@ def check_yaml(file_name, contents):
yield (line, e)
except KeyError as e:
yield (None, "Duplicated Key ({})".format(e.message))
except ValueError as e:
yield (None, e.message)
except voluptuous.MultipleInvalid as e:
yield (None, str(e))
def check_for_possible_duplicate_json_keys(key_value_pairs):