Merge branch 'feature/expand-require-separator' into 'master'

Expand and split by consecutive require delimiters

Closes #832

See merge request ungleich-public/cdist!930
This commit is contained in:
poljakowski 2020-08-27 12:22:55 +02:00
commit a4a3b98568
3 changed files with 17 additions and 2 deletions

View file

@ -25,6 +25,7 @@ import argparse
import logging
import os
import sys
import re
import cdist
from cdist import core
@ -389,12 +390,15 @@ class Emulator:
if "require" in self.env:
requirements = self.env['require']
self.log.debug("reqs = " + requirements)
for requirement in requirements.split(" "):
for requirement in self._parse_require(requirements):
# Ignore empty fields - probably the only field anyway
if len(requirement) == 0:
continue
self.record_requirement(requirement)
def _parse_require(self, require):
return re.split(r'[ \t\n]+', require)
def record_auto_requirements(self):
"""An object shall automatically depend on all objects that it
defined in it's type manifest.

View file

@ -685,6 +685,16 @@ class EmulatorAlreadyExistingRequirementsWarnTestCase(test.CdistTestCase):
self.env['require'] = '__directory/spam'
emu = emulator.Emulator(argv, env=self.env)
def test_parse_require(self):
require = " \t \n \t\t\n\t\na\tb\nc d \te\t\nf\ng\t "
expected = ['', 'a', 'b', 'c', 'd', 'e', 'f', 'g', '', ]
argv = ['__directory', 'spam']
emu = emulator.Emulator(argv, env=self.env)
requirements = emu._parse_require(require)
self.assertEqual(expected, requirements)
if __name__ == '__main__':
import unittest

View file

@ -95,7 +95,8 @@ Dependencies
------------
If you want to describe that something requires something else, just
setup the variable "require" to contain the requirements. Multiple
requirements can be added white space separated.
requirements can be added separated with (optionally consecutive)
delimiters including space, tab and newline.
::