Skip to content
Snippets Groups Projects
Commit f2046a4a authored by Todd Gamblin's avatar Todd Gamblin
Browse files

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
parent 618571b8
Branches
Tags
No related merge requests found
from globals import * from globals import *
from utils import * from util import *
from error import * from error import *
from package import Package from package import Package
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
import spack import spack
import error as serr import error as serr
from version import Version from version import Version
from utils import memoized from util import memoized
class InvalidSysTypeError(serr.SpackError): class InvalidSysTypeError(serr.SpackError):
......
import spack import spack
import spack.packages as packages import spack.packages as packages
import spack.test import spack.test
from spack.utils import list_modules from spack.util import list_modules
from spack.colify import colify from spack.colify import colify
from pprint import pprint from pprint import pprint
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
import spack import spack
import spack.compilers.gcc import spack.compilers.gcc
from spack.utils import list_modules, memoized from spack.util import list_modules, memoized
@memoized @memoized
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
import os import os
import spack.spec as spec import spack.spec as spec
from spack.utils import * from spack.util import *
from spack.error import SpackError from spack.error import SpackError
......
import os import os
from version import Version from version import Version
from utils import * from util import *
import arch import arch
from directory_layout import DefaultDirectoryLayout from directory_layout import DefaultDirectoryLayout
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
import spack import spack
import spack.error import spack.error
import spack.spec import spack.spec
from spack.utils import * from spack.util import *
import spack.arch as arch import spack.arch as arch
# Valid package names can contain '-' but can't start with it. # Valid package names can contain '-' but can't start with it.
......
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
import re import re
import spack.error import spack.error
import spack.utils import spack.util
from spack.version import Version from spack.version import Version
# #
...@@ -61,9 +61,9 @@ def parse_version_string_with_indices(path): ...@@ -61,9 +61,9 @@ def parse_version_string_with_indices(path):
if os.path.isdir(path): if os.path.isdir(path):
stem = os.path.basename(path) stem = os.path.basename(path)
elif re.search(r'((?:sourceforge.net|sf.net)/.*)/download$', 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: else:
stem = spack.utils.stem(path) stem = spack.util.stem(path)
version_types = [ version_types = [
# GitHub tarballs, e.g. v1.2.3 # GitHub tarballs, e.g. v1.2.3
......
File moved
""" """
Functions for comparing values that may potentially be None. Functions for comparing values that may potentially be None.
Functions prefixed with 'none_low_' treat None as less than all other values. These none_high functions consider None as greater than all other values.
Functions prefixed with 'none_high_' treat None as greater than all other values.
""" """
def none_low_lt(lhs, rhs): # Preserve builtin min and max functions
"""Less-than comparison. None is lower than any value.""" _builtin_min = min
return lhs != rhs and (lhs == None or (rhs != None and lhs < rhs)) _builtin_max = max
def none_low_le(lhs, rhs): def lt(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.""" """Less-than comparison. None is greater than any value."""
return lhs != rhs and (rhs == None or (lhs != None and lhs < rhs)) return lhs != rhs and (rhs == None or (lhs != None and lhs < rhs))
def none_high_le(lhs, rhs): def le(lhs, rhs):
"""Less-than-or-equal comparison. None is greater than any value.""" """Less-than-or-equal comparison. None is greater than any value."""
return lhs == rhs or none_high_lt(lhs, rhs) return lhs == rhs or lt(lhs, rhs)
def none_high_gt(lhs, rhs): def gt(lhs, rhs):
"""Greater-than comparison. None is greater than any value.""" """Greater-than comparison. None is greater than any value."""
return lhs != rhs and not none_high_lt(lhs, rhs) return lhs != rhs and not lt(lhs, rhs)
def none_high_ge(lhs, rhs): def ge(lhs, rhs):
"""Greater-than-or-equal comparison. None is greater than any value.""" """Greater-than-or-equal comparison. None is greater than any value."""
return lhs == rhs or none_high_gt(lhs, rhs) 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 none_high_max(lhs, rhs): def max(lhs, rhs):
"""Maximum function where None is greater than any value.""" """Maximum function where None is greater than any value."""
if lhs == None or rhs == None: if lhs == None or rhs == None:
return None return None
else: else:
return max(lhs, rhs) return _builtin_max(lhs, rhs)
"""
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)
import tty import tty
from utils import ALLOWED_ARCHIVE_TYPES from util import ALLOWED_ARCHIVE_TYPES
from urlparse import urlparse from urlparse import urlparse
ALLOWED_SCHEMES = ["http", "https", "ftp"] ALLOWED_SCHEMES = ["http", "https", "ftp"]
......
...@@ -25,8 +25,8 @@ ...@@ -25,8 +25,8 @@
from bisect import bisect_left from bisect import bisect_left
from functools import total_ordering from functools import total_ordering
import utils import spack.util.none_high as none_high
from none_compare import * import spack.util.none_low as none_low
import spack.error import spack.error
# Valid version characters # Valid version characters
...@@ -258,9 +258,9 @@ def __lt__(self, other): ...@@ -258,9 +258,9 @@ def __lt__(self, other):
if other is None: if other is None:
return False 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 (self.start == other.start and
none_high_lt(self.end, other.end))) none_high.lt(self.end, other.end)))
@coerced @coerced
...@@ -281,8 +281,8 @@ def concrete(self): ...@@ -281,8 +281,8 @@ def concrete(self):
@coerced @coerced
def __contains__(self, other): def __contains__(self, other):
return (none_low_ge(other.start, self.start) and return (none_low.ge(other.start, self.start) and
none_high_le(other.end, self.end)) none_high.le(other.end, self.end))
@coerced @coerced
...@@ -296,8 +296,8 @@ def overlaps(self, other): ...@@ -296,8 +296,8 @@ def overlaps(self, other):
@coerced @coerced
def merge(self, other): def merge(self, other):
return VersionRange(none_low_min(self.start, other.start), return VersionRange(none_low.min(self.start, other.start),
none_high_max(self.end, other.end)) none_high.max(self.end, other.end))
def __hash__(self): def __hash__(self):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment