Start to make a bigger package out of utils.py
- moved none_compare functions to util.none_high and util.none_low packages - renamed utils.py to util package
This commit is contained in:
parent
618571b807
commit
f2046a4aa3
14 changed files with 111 additions and 79 deletions
|
@ -1,5 +1,5 @@
|
|||
from globals import *
|
||||
from utils import *
|
||||
from util import *
|
||||
from error import *
|
||||
|
||||
from package import Package
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
import spack
|
||||
import error as serr
|
||||
from version import Version
|
||||
from utils import memoized
|
||||
from util import memoized
|
||||
|
||||
|
||||
class InvalidSysTypeError(serr.SpackError):
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import spack
|
||||
import spack.packages as packages
|
||||
import spack.test
|
||||
from spack.utils import list_modules
|
||||
from spack.util import list_modules
|
||||
from spack.colify import colify
|
||||
from pprint import pprint
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
import spack
|
||||
import spack.compilers.gcc
|
||||
from spack.utils import list_modules, memoized
|
||||
from spack.util import list_modules, memoized
|
||||
|
||||
|
||||
@memoized
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
import os
|
||||
|
||||
import spack.spec as spec
|
||||
from spack.utils import *
|
||||
from spack.util import *
|
||||
from spack.error import SpackError
|
||||
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import os
|
||||
from version import Version
|
||||
from utils import *
|
||||
from util import *
|
||||
import arch
|
||||
from directory_layout import DefaultDirectoryLayout
|
||||
|
||||
|
|
|
@ -1,60 +0,0 @@
|
|||
"""
|
||||
Functions for comparing values that may potentially be None.
|
||||
Functions prefixed with 'none_low_' treat None as less than all other values.
|
||||
Functions prefixed with 'none_high_' treat None as greater than all other values.
|
||||
"""
|
||||
|
||||
def none_low_lt(lhs, rhs):
|
||||
"""Less-than comparison. None is lower than any value."""
|
||||
return lhs != rhs and (lhs == None or (rhs != None and lhs < rhs))
|
||||
|
||||
|
||||
def none_low_le(lhs, rhs):
|
||||
"""Less-than-or-equal comparison. None is less than any value."""
|
||||
return lhs == rhs or none_low_lt(lhs, rhs)
|
||||
|
||||
|
||||
def none_low_gt(lhs, rhs):
|
||||
"""Greater-than comparison. None is less than any value."""
|
||||
return lhs != rhs and not none_low_lt(lhs, rhs)
|
||||
|
||||
|
||||
def none_low_ge(lhs, rhs):
|
||||
"""Greater-than-or-equal comparison. None is less than any value."""
|
||||
return lhs == rhs or none_low_gt(lhs, rhs)
|
||||
|
||||
|
||||
def none_low_min(lhs, rhs):
|
||||
"""Minimum function where None is less than any value."""
|
||||
if lhs == None or rhs == None:
|
||||
return None
|
||||
else:
|
||||
return min(lhs, rhs)
|
||||
|
||||
|
||||
def none_high_lt(lhs, rhs):
|
||||
"""Less-than comparison. None is greater than any value."""
|
||||
return lhs != rhs and (rhs == None or (lhs != None and lhs < rhs))
|
||||
|
||||
|
||||
def none_high_le(lhs, rhs):
|
||||
"""Less-than-or-equal comparison. None is greater than any value."""
|
||||
return lhs == rhs or none_high_lt(lhs, rhs)
|
||||
|
||||
|
||||
def none_high_gt(lhs, rhs):
|
||||
"""Greater-than comparison. None is greater than any value."""
|
||||
return lhs != rhs and not none_high_lt(lhs, rhs)
|
||||
|
||||
|
||||
def none_high_ge(lhs, rhs):
|
||||
"""Greater-than-or-equal comparison. None is greater than any value."""
|
||||
return lhs == rhs or none_high_gt(lhs, rhs)
|
||||
|
||||
|
||||
def none_high_max(lhs, rhs):
|
||||
"""Maximum function where None is greater than any value."""
|
||||
if lhs == None or rhs == None:
|
||||
return None
|
||||
else:
|
||||
return max(lhs, rhs)
|
|
@ -8,7 +8,7 @@
|
|||
import spack
|
||||
import spack.error
|
||||
import spack.spec
|
||||
from spack.utils import *
|
||||
from spack.util import *
|
||||
import spack.arch as arch
|
||||
|
||||
# Valid package names can contain '-' but can't start with it.
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
import re
|
||||
|
||||
import spack.error
|
||||
import spack.utils
|
||||
import spack.util
|
||||
from spack.version import Version
|
||||
|
||||
#
|
||||
|
@ -61,9 +61,9 @@ def parse_version_string_with_indices(path):
|
|||
if os.path.isdir(path):
|
||||
stem = os.path.basename(path)
|
||||
elif re.search(r'((?:sourceforge.net|sf.net)/.*)/download$', path):
|
||||
stem = spack.utils.stem(os.path.dirname(path))
|
||||
stem = spack.util.stem(os.path.dirname(path))
|
||||
else:
|
||||
stem = spack.utils.stem(path)
|
||||
stem = spack.util.stem(path)
|
||||
|
||||
version_types = [
|
||||
# GitHub tarballs, e.g. v1.2.3
|
||||
|
|
46
lib/spack/spack/util/none_high.py
Normal file
46
lib/spack/spack/util/none_high.py
Normal file
|
@ -0,0 +1,46 @@
|
|||
"""
|
||||
Functions for comparing values that may potentially be None.
|
||||
These none_high functions consider None as greater than all other values.
|
||||
"""
|
||||
|
||||
# Preserve builtin min and max functions
|
||||
_builtin_min = min
|
||||
_builtin_max = max
|
||||
|
||||
|
||||
def lt(lhs, rhs):
|
||||
"""Less-than comparison. None is greater than any value."""
|
||||
return lhs != rhs and (rhs == None or (lhs != None and lhs < rhs))
|
||||
|
||||
|
||||
def le(lhs, rhs):
|
||||
"""Less-than-or-equal comparison. None is greater than any value."""
|
||||
return lhs == rhs or lt(lhs, rhs)
|
||||
|
||||
|
||||
def gt(lhs, rhs):
|
||||
"""Greater-than comparison. None is greater than any value."""
|
||||
return lhs != rhs and not lt(lhs, rhs)
|
||||
|
||||
|
||||
def ge(lhs, rhs):
|
||||
"""Greater-than-or-equal comparison. None is greater than any value."""
|
||||
return lhs == rhs or gt(lhs, rhs)
|
||||
|
||||
|
||||
def min(lhs, rhs):
|
||||
"""Minimum function where None is greater than any value."""
|
||||
if lhs == None:
|
||||
return rhs
|
||||
elif rhs == None:
|
||||
return lhs
|
||||
else:
|
||||
return _builtin_min(lhs, rhs)
|
||||
|
||||
|
||||
def max(lhs, rhs):
|
||||
"""Maximum function where None is greater than any value."""
|
||||
if lhs == None or rhs == None:
|
||||
return None
|
||||
else:
|
||||
return _builtin_max(lhs, rhs)
|
46
lib/spack/spack/util/none_low.py
Normal file
46
lib/spack/spack/util/none_low.py
Normal file
|
@ -0,0 +1,46 @@
|
|||
"""
|
||||
Functions for comparing values that may potentially be None.
|
||||
These none_low functions consider None as less than all other values.
|
||||
"""
|
||||
|
||||
# Preserve builtin min and max functions
|
||||
_builtin_min = min
|
||||
_builtin_max = max
|
||||
|
||||
|
||||
def lt(lhs, rhs):
|
||||
"""Less-than comparison. None is lower than any value."""
|
||||
return lhs != rhs and (lhs == None or (rhs != None and lhs < rhs))
|
||||
|
||||
|
||||
def le(lhs, rhs):
|
||||
"""Less-than-or-equal comparison. None is less than any value."""
|
||||
return lhs == rhs or lt(lhs, rhs)
|
||||
|
||||
|
||||
def gt(lhs, rhs):
|
||||
"""Greater-than comparison. None is less than any value."""
|
||||
return lhs != rhs and not lt(lhs, rhs)
|
||||
|
||||
|
||||
def ge(lhs, rhs):
|
||||
"""Greater-than-or-equal comparison. None is less than any value."""
|
||||
return lhs == rhs or gt(lhs, rhs)
|
||||
|
||||
|
||||
def min(lhs, rhs):
|
||||
"""Minimum function where None is less than any value."""
|
||||
if lhs == None or rhs == None:
|
||||
return None
|
||||
else:
|
||||
return _builtin_min(lhs, rhs)
|
||||
|
||||
|
||||
def max(lhs, rhs):
|
||||
"""Maximum function where None is less than any value."""
|
||||
if lhs == None:
|
||||
return rhs
|
||||
elif rhs == None:
|
||||
return lhs
|
||||
else:
|
||||
return _builtin_max(lhs, rhs)
|
|
@ -1,5 +1,5 @@
|
|||
import tty
|
||||
from utils import ALLOWED_ARCHIVE_TYPES
|
||||
from util import ALLOWED_ARCHIVE_TYPES
|
||||
from urlparse import urlparse
|
||||
|
||||
ALLOWED_SCHEMES = ["http", "https", "ftp"]
|
||||
|
|
|
@ -25,8 +25,8 @@
|
|||
from bisect import bisect_left
|
||||
from functools import total_ordering
|
||||
|
||||
import utils
|
||||
from none_compare import *
|
||||
import spack.util.none_high as none_high
|
||||
import spack.util.none_low as none_low
|
||||
import spack.error
|
||||
|
||||
# Valid version characters
|
||||
|
@ -258,9 +258,9 @@ def __lt__(self, other):
|
|||
if other is None:
|
||||
return False
|
||||
|
||||
return (none_low_lt(self.start, other.start) or
|
||||
return (none_low.lt(self.start, other.start) or
|
||||
(self.start == other.start and
|
||||
none_high_lt(self.end, other.end)))
|
||||
none_high.lt(self.end, other.end)))
|
||||
|
||||
|
||||
@coerced
|
||||
|
@ -281,8 +281,8 @@ def concrete(self):
|
|||
|
||||
@coerced
|
||||
def __contains__(self, other):
|
||||
return (none_low_ge(other.start, self.start) and
|
||||
none_high_le(other.end, self.end))
|
||||
return (none_low.ge(other.start, self.start) and
|
||||
none_high.le(other.end, self.end))
|
||||
|
||||
|
||||
@coerced
|
||||
|
@ -296,8 +296,8 @@ def overlaps(self, other):
|
|||
|
||||
@coerced
|
||||
def merge(self, other):
|
||||
return VersionRange(none_low_min(self.start, other.start),
|
||||
none_high_max(self.end, other.end))
|
||||
return VersionRange(none_low.min(self.start, other.start),
|
||||
none_high.max(self.end, other.end))
|
||||
|
||||
|
||||
def __hash__(self):
|
||||
|
|
Loading…
Reference in a new issue