Browse Source

Expand and split by consecutive require delimiters

Resolves #832.
6.8
Darko Poljak 2 years ago
parent
commit
c17541f24c
  1. 6
      cdist/emulator.py
  2. 10
      cdist/test/emulator/__init__.py
  3. 3
      docs/src/cdist-manifest.rst

6
cdist/emulator.py vendored

@ -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.

10
cdist/test/emulator/__init__.py vendored

@ -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

3
docs/src/cdist-manifest.rst

@ -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.
::

Loading…
Cancel
Save