Fix circular import
This commit is contained in:
parent
6eda1b4d04
commit
9c03f15cbd
@ -63,7 +63,7 @@
|
||||
import spack.util.web as web_util
|
||||
from spack import traverse
|
||||
from spack.caches import misc_cache_location
|
||||
from spack.mirrors.utils import MirrorSpecFilter
|
||||
from spack.mirrors.filter import MirrorSpecFilter
|
||||
from spack.oci.image import (
|
||||
Digest,
|
||||
ImageReference,
|
||||
|
38
lib/spack/spack/mirrors/filter.py
Normal file
38
lib/spack/spack/mirrors/filter.py
Normal file
@ -0,0 +1,38 @@
|
||||
# Copyright Spack Project Developers. See COPYRIGHT file for details.
|
||||
#
|
||||
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
|
||||
from typing import List
|
||||
|
||||
import spack.spec
|
||||
from spack.mirrors.mirror import Mirror
|
||||
|
||||
|
||||
class MirrorSpecFilter:
|
||||
def __init__(self, mirror: Mirror):
|
||||
self.exclude = [spack.spec.Spec(spec) for spec in mirror.exclusions]
|
||||
self.include = [spack.spec.Spec(spec) for spec in mirror.inclusions]
|
||||
|
||||
def __call__(self, specs: List[spack.spec.Spec]):
|
||||
"""
|
||||
Determine the intersection of include/exclude filters
|
||||
Tie goes to keeping
|
||||
|
||||
skip | keep | outcome
|
||||
------------------------
|
||||
False | False | Keep
|
||||
True | True | Keep
|
||||
False | True | Keep
|
||||
True | False | Skip
|
||||
"""
|
||||
filter = []
|
||||
filtrate = []
|
||||
for spec in specs:
|
||||
skip = any([spec.satisfies(test) for test in self.exclude])
|
||||
keep = any([spec.satisfies(test) for test in self.include])
|
||||
|
||||
if skip and not keep:
|
||||
filtrate.append(spec)
|
||||
else:
|
||||
filter.append(spec)
|
||||
|
||||
return filter, filtrate
|
@ -3,7 +3,6 @@
|
||||
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
|
||||
import os
|
||||
import traceback
|
||||
from typing import List
|
||||
|
||||
import llnl.util.tty as tty
|
||||
from llnl.util.filesystem import mkdirp
|
||||
@ -255,34 +254,3 @@ def require_mirror_name(mirror_name):
|
||||
if not mirror:
|
||||
raise ValueError(f'no mirror named "{mirror_name}"')
|
||||
return mirror
|
||||
|
||||
|
||||
class MirrorSpecFilter:
|
||||
def __init__(self, mirror: Mirror):
|
||||
self.exclude = [spack.spec.Spec(spec) for spec in mirror.exclusions]
|
||||
self.include = [spack.spec.Spec(spec) for spec in mirror.inclusions]
|
||||
|
||||
def __call__(self, specs: List[spack.spec.Spec]):
|
||||
"""
|
||||
Determine the intersection of include/exclude filters
|
||||
Tie goes to keeping
|
||||
|
||||
skip | keep | outcome
|
||||
------------------------
|
||||
False | False | Keep
|
||||
True | True | Keep
|
||||
False | True | Keep
|
||||
True | False | Skip
|
||||
"""
|
||||
filter = []
|
||||
filtrate = []
|
||||
for spec in specs:
|
||||
skip = any([spec.satisfies(test) for test in self.exclude])
|
||||
keep = any([spec.satisfies(test) for test in self.include])
|
||||
|
||||
if skip and not keep:
|
||||
filtrate.append(spec)
|
||||
else:
|
||||
filter.append(spec)
|
||||
|
||||
return filter, filtrate
|
||||
|
@ -24,6 +24,7 @@
|
||||
import spack.util.spack_json as sjson
|
||||
import spack.util.url as url_util
|
||||
from spack.cmd.common.arguments import mirror_name_or_url
|
||||
from spack.mirrors.filter import MirrorSpecFilter
|
||||
from spack.spec import Spec
|
||||
from spack.util.executable import which
|
||||
from spack.util.spack_yaml import SpackYAMLError
|
||||
@ -473,7 +474,7 @@ def test_filter_specs(include, exclude, gold):
|
||||
input_specs = [spack.spec.Spec(s) for s in INPUT_SPEC_STRS]
|
||||
data = {"include": include, "exclude": exclude}
|
||||
m = spack.mirrors.mirror.Mirror(data)
|
||||
filter = spack.mirrors.utils.MirrorSpecFilter(m)
|
||||
filter = MirrorSpecFilter(m)
|
||||
|
||||
filtered, filtrate = filter(input_specs)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user