msmasnadi / OPGEEv4

OPGEE v4
Other
10 stars 4 forks source link

Allow finding stream contents using regular expressions #38

Open rjplevin opened 2 weeks ago

rjplevin commented 2 weeks ago

Added regex=False argument to the stack of methods in Process and Stream used to find streams. Setting regex=True allows use of regular expressions. Modified tests to exercise this option.

rjplevin commented 2 days ago

A few updates to the PR:

  1. I changed Stream.contains() to use re.fullmatch() instead of re.match() to avoid erroneous partial matches. Now, unless the string used in _required_inputs or _required_outputs in a Process includes regex characters, it devolves to a simple string match.
  2. I also added a dict option for the elements of the _required_* lists. Keys are pattern, min, and max. Default for both min and max is 1. There's a new method, Process.valdict() to create these conveniently.
  3. I modified test_stream.py to exercise the dict option:

    class Proc3(Process):
    def __init__(self, name, **kwargs):
        super().__init__(name, **kwargs)
    
        self._required_inputs = [
            self.valdict(r'.*gas.*', min=2, max=2),
        ]
        self._required_outputs = [
            "CO2",
        ]

All tests passed.