Exemplo n.º 1
0
def test_recursive_refs():
    """Test sample inputs."""
    result = sorted(recursive_refs([
        {'in_path': 'base.in', 'refs': []},
        {'in_path': 'sub/test.in', 'refs': ['../base.in']},
        {'in_path': 'local.in', 'refs': ['sub/test.in']},
    ], 'local.in'))
    assert result == ['base.in', 'sub/test.in']

    result = sorted(recursive_refs([
        {'in_path': 'base.in', 'refs': []},
        {'in_path': 'sub/test.in', 'refs': ['../base.in']},
        {'in_path': 'local.in', 'refs': ['sub/test.in']},
    ], 'sub/test.in'))
    assert result == ['base.in']
Exemplo n.º 2
0
    def _find_sink(envs):
        """Try to find requirements sink.

        Sink is a requirements file that references all other
        requirement files.

        If no sink exists, return None.

        >>> Autoresolve._find_sink([
        ...  {'in_path': 'base', 'refs': set()},
        ...  {'in_path': 'test', 'refs': {'base'}},
        ...  {'in_path': 'local', 'refs': {'test', 'base'}},
        ... ])
        'local'
        >>> Autoresolve._find_sink([
        ...  {'in_path': 'base', 'refs': set()},
        ...  {'in_path': 'test', 'refs': {'base'}},
        ...  {'in_path': 'doc', 'refs': set()},
        ... ])
        >>> Autoresolve._find_sink([
        ...  {'in_path': 'base', 'refs': set()},
        ...  {'in_path': 'foo', 'refs': {'base'}},
        ...  {'in_path': 'bar', 'refs': {'base'}},
        ...  {'in_path': 'all', 'refs': {'foo', 'bar'}},
        ... ])
        'all'
        """
        all_envs = {env['in_path'] for env in envs}
        for env in envs:
            included_envs = set(recursive_refs(
                envs, env['in_path'])) | {env['in_path']}
            if all_envs == included_envs:
                return env['in_path']
        return None
Exemplo n.º 3
0
 def on_discover(self, env_confs):
     """Save set of all (recursive) included environments."""
     included_and_refs = self.direct_envs
     if not self.direct_envs:
         # No limit means all envs included:
         self._all_envs = [env['name'] for env in env_confs]
         return
     for name in set(included_and_refs):
         included_and_refs.update(recursive_refs(env_confs, name))
     self._all_envs = included_and_refs
Exemplo n.º 4
0
 def on_discover(self, env_confs):
     """Save set of all (recursive) included environments."""
     if not self.direct_envs:
         # No limit means all envs included:
         self._all_envs = [env['in_path'] for env in env_confs]
         return
     transitive_refs = {
         ref
         for in_path in self.direct_envs
         for ref in recursive_refs(env_confs, in_path)
     }
     self._all_envs = self.direct_envs | transitive_refs
Exemplo n.º 5
0
 def recursive_refs(self, env_name):
     """Return recursive list of environment names referenced by env_name."""
     if self.env_confs is None:
         return {}
     return recursive_refs(self.env_confs, env_name)
Exemplo n.º 6
0
 def ignored_packages(self, env_name):
     """Get package mapping from name to version for referenced environments."""
     if self.env_confs is None:
         return {}
     rrefs = recursive_refs(self.env_confs, env_name)
     return merged_packages(self.env_packages, rrefs)
Exemplo n.º 7
0
 def recursive_refs(self, in_path):
     """Return recursive list of environment names referenced by in_path."""
     if self.env_confs is None:
         return {}
     return recursive_refs(self.env_confs, in_path)