Commits

DasIch  committed dc0af47

Chang config validation to allow for a Build section

  • Participants
  • Parent commits 63b0701

Comments (0)

Files changed (1)

         """
         def validate(d, trace):
             result = {}
-            for k, validate in keys:
+            for k, validate, optional in keys:
                 try:
                     result[k] = validate(d[k], add_level(trace, k))
                 except KeyError:
-                    raise ValidationError(msg % k, trace)
+                    if not optional:
+                        raise ValidationError(msg % k, trace)
             return result
         return validate
 
+    id = lambda obj, trace: obj
+
     #: Validates the `Source` section of an interpreter
     validate_source = make_validator(zip(
         ['method', 'repository', 'executable', 'commands'],
-        repeat(lambda obj, trace: obj)
+        repeat(id),
+        repeat(False)
     ))
+    #: Validates the `Build` section of an interpreter
+    validate_build = make_validator(
+        zip(['uri', 'commands'], repeat(id), repeat(False))
+    )
 
-    #: Validates an interpreter section of `interpreters`
-    validate_interpreter = make_validator([('Source', validate_source)])
+    _validate_interpreter = make_validator([
+        ('Source', validate_source, True),
+        ('Build', validate_build, True)
+    ])
+
+    def validate_interpreter(raw_config, trace):
+        result = _validate_interpreter(raw_config, trace)
+        if not any(key in result for key in ['Source', 'Build']):
+            raise ValidationError('Either Source or Build is required', trace)
 
     def validate_interpreters(interpreters, trace):
         """