Renamed variables called 'spec' to 'path'

This commit is contained in:
Todd Gamblin 2013-05-17 10:38:39 -07:00
parent 340fe565d4
commit 7c98ee9644

View file

@ -27,54 +27,59 @@
import spack.utils import spack.utils
from spack.version import Version from spack.version import Version
#
# Note: We call the input to most of these functions a "path" but the functions
# work on paths and URLs. There's not a good word for both of these, but
# "path" seemed like the most generic term.
#
class UrlParseError(spack.error.SpackError): class UrlParseError(spack.error.SpackError):
"""Raised when the URL module can't parse something correctly.""" """Raised when the URL module can't parse something correctly."""
def __init__(self, msg, spec): def __init__(self, msg, path):
super(UrlParseError, self).__init__(msg) super(UrlParseError, self).__init__(msg)
self.spec = spec self.path = path
class UndetectableVersionError(UrlParseError): class UndetectableVersionError(UrlParseError):
"""Raised when we can't parse a version from a string.""" """Raised when we can't parse a version from a string."""
def __init__(self, spec): def __init__(self, path):
super(UndetectableVersionError, self).__init__( super(UndetectableVersionError, self).__init__(
"Couldn't detect version in: " + spec, spec) "Couldn't detect version in: " + path, path)
class UndetectableNameError(UrlParseError): class UndetectableNameError(UrlParseError):
"""Raised when we can't parse a package name from a string.""" """Raised when we can't parse a package name from a string."""
def __init__(self, spec): def __init__(self, path):
super(UndetectableNameError, self).__init__( super(UndetectableNameError, self).__init__(
"Couldn't parse package name in: " + spec) "Couldn't parse package name in: " + path)
def parse_version_string_with_indices(spec): def parse_version_string_with_indices(path):
"""Try to extract a version string from a filename or URL. This is taken """Try to extract a version string from a filename or URL. This is taken
largely from Homebrew's Version class.""" largely from Homebrew's Version class."""
if os.path.isdir(spec): if os.path.isdir(path):
stem = os.path.basename(spec) stem = os.path.basename(path)
elif re.search(r'((?:sourceforge.net|sf.net)/.*)/download$', spec): elif re.search(r'((?:sourceforge.net|sf.net)/.*)/download$', path):
stem = spack.utils.stem(os.path.dirname(spec)) stem = spack.utils.stem(os.path.dirname(path))
else: else:
stem = spack.utils.stem(spec) stem = spack.utils.stem(path)
version_types = [ version_types = [
# GitHub tarballs, e.g. v1.2.3 # GitHub tarballs, e.g. v1.2.3
(r'github.com/.+/(?:zip|tar)ball/v?((\d+\.)+\d+)$', spec), (r'github.com/.+/(?:zip|tar)ball/v?((\d+\.)+\d+)$', path),
# e.g. https://github.com/sam-github/libnet/tarball/libnet-1.1.4 # e.g. https://github.com/sam-github/libnet/tarball/libnet-1.1.4
(r'github.com/.+/(?:zip|tar)ball/.*-((\d+\.)+\d+)$', spec), (r'github.com/.+/(?:zip|tar)ball/.*-((\d+\.)+\d+)$', path),
# e.g. https://github.com/isaacs/npm/tarball/v0.2.5-1 # e.g. https://github.com/isaacs/npm/tarball/v0.2.5-1
(r'github.com/.+/(?:zip|tar)ball/v?((\d+\.)+\d+-(\d+))$', spec), (r'github.com/.+/(?:zip|tar)ball/v?((\d+\.)+\d+-(\d+))$', path),
# e.g. https://github.com/petdance/ack/tarball/1.93_02 # e.g. https://github.com/petdance/ack/tarball/1.93_02
(r'github.com/.+/(?:zip|tar)ball/v?((\d+\.)+\d+_(\d+))$', spec), (r'github.com/.+/(?:zip|tar)ball/v?((\d+\.)+\d+_(\d+))$', path),
# e.g. https://github.com/erlang/otp/tarball/OTP_R15B01 (erlang style) # e.g. https://github.com/erlang/otp/tarball/OTP_R15B01 (erlang style)
(r'[-_](R\d+[AB]\d*(-\d+)?)', spec), (r'[-_](R\d+[AB]\d*(-\d+)?)', path),
# e.g. boost_1_39_0 # e.g. boost_1_39_0
(r'((\d+_)+\d+)$', stem), (r'((\d+_)+\d+)$', stem),
@ -111,7 +116,7 @@ def parse_version_string_with_indices(spec):
(r'_([^_]+)', stem), (r'_([^_]+)', stem),
# e.g. http://mirrors.jenkins-ci.org/war/1.486/jenkins.war # e.g. http://mirrors.jenkins-ci.org/war/1.486/jenkins.war
(r'\/(\d\.\d+)\/', spec), (r'\/(\d\.\d+)\/', path),
# e.g. http://www.ijg.org/files/jpegsrc.v8d.tar.gz # e.g. http://www.ijg.org/files/jpegsrc.v8d.tar.gz
(r'\.v(\d+[a-z]?)', stem)] (r'\.v(\d+[a-z]?)', stem)]
@ -122,20 +127,20 @@ def parse_version_string_with_indices(spec):
if match and match.group(1) is not None: if match and match.group(1) is not None:
return match.group(1), match.start(1), match.end(1) return match.group(1), match.start(1), match.end(1)
raise UndetectableVersionError(spec) raise UndetectableVersionError(path)
def parse_version(spec): def parse_version(path):
"""Given a URL or archive name, extract a version from it and return """Given a URL or archive name, extract a version from it and return
a version object. a version object.
""" """
ver, start, end = parse_version_string_with_indices(spec) ver, start, end = parse_version_string_with_indices(path)
return Version(ver) return Version(ver)
def parse_name(spec, ver=None): def parse_name(path, ver=None):
if ver is None: if ver is None:
ver = parse_version(spec) ver = parse_version(path)
ntypes = (r'/sourceforge/([^/]+)/', ntypes = (r'/sourceforge/([^/]+)/',
r'/([^/]+)/(tarball|zipball)/', r'/([^/]+)/(tarball|zipball)/',
@ -146,21 +151,21 @@ def parse_name(spec, ver=None):
r'^([^/]+)%s' % ver) r'^([^/]+)%s' % ver)
for nt in ntypes: for nt in ntypes:
match = re.search(nt, spec) match = re.search(nt, path)
if match: if match:
return match.group(1) return match.group(1)
raise UndetectableNameError(spec) raise UndetectableNameError(path)
def parse_name_and_version(spec): def parse_name_and_version(path):
ver = parse_version(spec) ver = parse_version(path)
name = parse_name(spec, ver) name = parse_name(path, ver)
return (name, ver) return (name, ver)
def create_version_format(spec): def version_format(path):
"""Given a URL or archive name, find the version and create a format string """Given a URL or archive name, find the version and create a format string
that will allow another version to be substituted. that will allow another version to be substituted.
""" """
ver, start, end = parse_version_string_with_indices(spec) ver, start, end = parse_version_string_with_indices(path)
return spec[:start] + '%s' + spec[end:] return path[:start] + '%s' + path[end:]