formatting to appease flake8

This commit is contained in:
Tom Scogland 2016-05-16 05:12:30 -07:00
parent 71d9911539
commit dacedfcc0e
4 changed files with 178 additions and 135 deletions

View File

@ -57,7 +57,6 @@
from spack.util.compression import decompressor_for, extension from spack.util.compression import decompressor_for, extension
import spack.util.pattern as pattern import spack.util.pattern as pattern
"""List of all fetch strategies, created by FetchStrategy metaclass.""" """List of all fetch strategies, created by FetchStrategy metaclass."""
all_strategies = [] all_strategies = []
@ -82,13 +81,16 @@ class FetchStrategy(object):
class __metaclass__(type): class __metaclass__(type):
"""This metaclass registers all fetch strategies in a list.""" """This metaclass registers all fetch strategies in a list."""
def __init__(cls, name, bases, dict): def __init__(cls, name, bases, dict):
type.__init__(cls, name, bases, dict) type.__init__(cls, name, bases, dict)
if cls.enabled: all_strategies.append(cls) if cls.enabled:
all_strategies.append(cls)
def __init__(self): def __init__(self):
# The stage is initialized late, so that fetch strategies can be constructed # The stage is initialized late, so that fetch strategies can be
# at package construction time. This is where things will be fetched. # constructed at package construction time. This is where things
# will be fetched.
self.stage = None self.stage = None
def set_stage(self, stage): def set_stage(self, stage):
@ -97,15 +99,20 @@ def set_stage(self, stage):
self.stage = stage self.stage = stage
# Subclasses need to implement these methods # Subclasses need to implement these methods
def fetch(self): pass # Return True on success, False on fail. def fetch(self):
pass # Return True on success, False on fail.
def check(self): pass # Do checksum. def check(self):
pass # Do checksum.
def expand(self): pass # Expand archive. def expand(self):
pass # Expand archive.
def reset(self): pass # Revert to freshly downloaded state. def reset(self):
pass # Revert to freshly downloaded state.
def archive(self, destination): pass # Used to create tarball for mirror. def archive(self, destination):
pass # Used to create tarball for mirror.
def __str__(self): # Should be human readable URL. def __str__(self): # Should be human readable URL.
return "FetchStrategy.__str___" return "FetchStrategy.__str___"
@ -139,10 +146,12 @@ def __init__(self, url=None, digest=None, **kwargs):
# If URL or digest are provided in the kwargs, then prefer # If URL or digest are provided in the kwargs, then prefer
# those values. # those values.
self.url = kwargs.get('url', None) self.url = kwargs.get('url', None)
if not self.url: self.url = url if not self.url:
self.url = url
self.digest = kwargs.get('md5', None) self.digest = kwargs.get('md5', None)
if not self.digest: self.digest = digest if not self.digest:
self.digest = digest
self.expand_archive = kwargs.get('expand', True) self.expand_archive = kwargs.get('expand', True)
@ -167,16 +176,20 @@ def fetch(self):
tty.msg("Trying to fetch from %s" % self.url) tty.msg("Trying to fetch from %s" % self.url)
if partial_file: if partial_file:
save_args = ['-C', '-', # continue partial downloads save_args = ['-C',
'-o', partial_file] # use a .part file '-', # continue partial downloads
'-o',
partial_file] # use a .part file
else: else:
save_args = ['-O'] save_args = ['-O']
curl_args = save_args + [ curl_args = save_args + [
'-f', # fail on >400 errors '-f', # fail on >400 errors
'-D', '-', # print out HTML headers '-D',
'-L', # resolve 3xx redirects '-', # print out HTML headers
self.url, ] '-L', # resolve 3xx redirects
self.url,
]
if sys.stdout.isatty(): if sys.stdout.isatty():
curl_args.append('-#') # status bar when using a tty curl_args.append('-#') # status bar when using a tty
@ -184,8 +197,7 @@ def fetch(self):
curl_args.append('-sS') # just errors when not. curl_args.append('-sS') # just errors when not.
# Run curl but grab the mime type from the http headers # Run curl but grab the mime type from the http headers
headers = spack.curl( headers = spack.curl(*curl_args, output=str, fail_on_error=False)
*curl_args, output=str, fail_on_error=False)
if spack.curl.returncode != 0: if spack.curl.returncode != 0:
# clean up archive on failure. # clean up archive on failure.
@ -198,33 +210,36 @@ def fetch(self):
if spack.curl.returncode == 22: if spack.curl.returncode == 22:
# This is a 404. Curl will print the error. # This is a 404. Curl will print the error.
raise FailedDownloadError( raise FailedDownloadError(
self.url, "URL %s was not found!" % self.url) self.url, "URL %s was not found!" % self.url)
elif spack.curl.returncode == 60: elif spack.curl.returncode == 60:
# This is a certificate error. Suggest spack -k # This is a certificate error. Suggest spack -k
raise FailedDownloadError( raise FailedDownloadError(
self.url, self.url,
"Curl was unable to fetch due to invalid certificate. " "Curl was unable to fetch due to invalid certificate. "
"This is either an attack, or your cluster's SSL configuration " "This is either an attack, or your cluster's SSL "
"is bad. If you believe your SSL configuration is bad, you " "configuration is bad. If you believe your SSL "
"can try running spack -k, which will not check SSL certificates." "configuration is bad, you can try running spack -k, "
"Use this at your own risk.") "which will not check SSL certificates."
"Use this at your own risk.")
else: else:
# This is some other curl error. Curl will print the # This is some other curl error. Curl will print the
# error, but print a spack message too # error, but print a spack message too
raise FailedDownloadError( raise FailedDownloadError(
self.url, "Curl failed with error %d" % spack.curl.returncode) self.url,
"Curl failed with error %d" % spack.curl.returncode)
# Check if we somehow got an HTML file rather than the archive we # Check if we somehow got an HTML file rather than the archive we
# asked for. We only look at the last content type, to handle # asked for. We only look at the last content type, to handle
# redirects properly. # redirects properly.
content_types = re.findall(r'Content-Type:[^\r\n]+', headers) content_types = re.findall(r'Content-Type:[^\r\n]+', headers)
if content_types and 'text/html' in content_types[-1]: if content_types and 'text/html' in content_types[-1]:
tty.warn("The contents of " + self.archive_file + " look like HTML.", tty.warn(
"The checksum will likely be bad. If it is, you can use", "The contents of " + self.archive_file + " look like HTML.",
"'spack clean <package>' to remove the bad archive, then fix", "The checksum will likely be bad. If it is, you can use",
"your internet gateway issue and install again.") "'spack clean <package>' to remove the bad archive, then fix",
"your internet gateway issue and install again.")
if save_file: if save_file:
os.rename(partial_file, save_file) os.rename(partial_file, save_file)
@ -247,14 +262,16 @@ def expand(self):
self.stage.chdir() self.stage.chdir()
if not self.archive_file: if not self.archive_file:
raise NoArchiveFileError("URLFetchStrategy couldn't find archive file", raise NoArchiveFileError(
"Failed on expand() for URL %s" % self.url) "URLFetchStrategy couldn't find archive file",
"Failed on expand() for URL %s" % self.url)
decompress = decompressor_for(self.archive_file) decompress = decompressor_for(self.archive_file)
# Expand all tarballs in their own directory to contain # Expand all tarballs in their own directory to contain
# exploding tarballs. # exploding tarballs.
tarball_container = os.path.join(self.stage.path, "spack-expanded-archive") tarball_container = os.path.join(self.stage.path,
"spack-expanded-archive")
mkdirp(tarball_container) mkdirp(tarball_container)
os.chdir(tarball_container) os.chdir(tarball_container)
decompress(self.archive_file) decompress(self.archive_file)
@ -295,20 +312,25 @@ def check(self):
"""Check the downloaded archive against a checksum digest. """Check the downloaded archive against a checksum digest.
No-op if this stage checks code out of a repository.""" No-op if this stage checks code out of a repository."""
if not self.digest: if not self.digest:
raise NoDigestError("Attempt to check URLFetchStrategy with no digest.") raise NoDigestError(
"Attempt to check URLFetchStrategy with no digest.")
checker = crypto.Checker(self.digest) checker = crypto.Checker(self.digest)
if not checker.check(self.archive_file): if not checker.check(self.archive_file):
raise ChecksumError( raise ChecksumError(
"%s checksum failed for %s" % (checker.hash_name, self.archive_file), "%s checksum failed for %s" %
"Expected %s but got %s" % (self.digest, checker.sum)) (checker.hash_name, self.archive_file),
"Expected %s but got %s" % (self.digest, checker.sum))
@_needs_stage @_needs_stage
def reset(self): def reset(self):
"""Removes the source path if it exists, then re-expands the archive.""" """
Removes the source path if it exists, then re-expands the archive.
"""
if not self.archive_file: if not self.archive_file:
raise NoArchiveFileError("Tried to reset URLFetchStrategy before fetching", raise NoArchiveFileError(
"Failed on reset() for URL %s" % self.url) "Tried to reset URLFetchStrategy before fetching",
"Failed on reset() for URL %s" % self.url)
# Remove everythigng but the archive from the stage # Remove everythigng but the archive from the stage
for filename in os.listdir(self.stage.path): for filename in os.listdir(self.stage.path):
@ -337,14 +359,16 @@ def __init__(self, name, *rev_types, **kwargs):
# Set a URL based on the type of fetch strategy. # Set a URL based on the type of fetch strategy.
self.url = kwargs.get(name, None) self.url = kwargs.get(name, None)
if not self.url: raise ValueError( if not self.url:
raise ValueError(
"%s requires %s argument." % (self.__class__, name)) "%s requires %s argument." % (self.__class__, name))
# Ensure that there's only one of the rev_types # Ensure that there's only one of the rev_types
if sum(k in kwargs for k in rev_types) > 1: if sum(k in kwargs for k in rev_types) > 1:
raise FetchStrategyError( raise FetchStrategyError(
"Supply only one of %s to fetch with %s" % ( "Supply only one of %s to fetch with %s" % (
comma_or(rev_types), name)) comma_or(rev_types), name
))
# Set attributes for each rev type. # Set attributes for each rev type.
for rt in rev_types: for rt in rev_types:
@ -381,19 +405,23 @@ def __str__(self):
def __repr__(self): def __repr__(self):
return "%s<%s>" % (self.__class__, self.url) return "%s<%s>" % (self.__class__, self.url)
class GoFetchStrategy(VCSFetchStrategy): class GoFetchStrategy(VCSFetchStrategy):
"""Fetch strategy that employs the `go get` infrastructure """
Use like this in a package: Fetch strategy that employs the `go get` infrastructure
Use like this in a package:
version('name', go='github.com/monochromegane/the_platinum_searcher/...') version('name',
go='github.com/monochromegane/the_platinum_searcher/...')
Go get does not natively support versions, they can be faked with git Go get does not natively support versions, they can be faked with git
""" """
enabled = True enabled = True
required_attributes = ('go',) required_attributes = ('go', )
def __init__(self, **kwargs): def __init__(self, **kwargs):
# Discards the keywords in kwargs that may conflict with the next call to __init__ # Discards the keywords in kwargs that may conflict with the next
# call to __init__
forwarded_args = copy.copy(kwargs) forwarded_args = copy.copy(kwargs)
forwarded_args.pop('name', None) forwarded_args.pop('name', None)
@ -422,8 +450,8 @@ def fetch(self):
except OSError: except OSError:
pass pass
env = dict(os.environ) env = dict(os.environ)
env['GOPATH'] = os.path.join(os.getcwd(),'go') env['GOPATH'] = os.path.join(os.getcwd(), 'go')
self.go('get', '-v', '-d', self.url, env=env) self.go('get', '-v', '-d', self.url, env=env)
def archive(self, destination): def archive(self, destination):
super(GoFetchStrategy, self).archive(destination, exclude='.git') super(GoFetchStrategy, self).archive(destination, exclude='.git')
@ -436,32 +464,35 @@ def reset(self):
def __str__(self): def __str__(self):
return "[go] %s" % self.url return "[go] %s" % self.url
class GitFetchStrategy(VCSFetchStrategy): class GitFetchStrategy(VCSFetchStrategy):
"""Fetch strategy that gets source code from a git repository. """
Use like this in a package: Fetch strategy that gets source code from a git repository.
Use like this in a package:
version('name', git='https://github.com/project/repo.git') version('name', git='https://github.com/project/repo.git')
Optionally, you can provide a branch, or commit to check out, e.g.: Optionally, you can provide a branch, or commit to check out, e.g.:
version('1.1', git='https://github.com/project/repo.git', tag='v1.1') version('1.1', git='https://github.com/project/repo.git', tag='v1.1')
You can use these three optional attributes in addition to ``git``: You can use these three optional attributes in addition to ``git``:
* ``branch``: Particular branch to build from (default is master) * ``branch``: Particular branch to build from (default is master)
* ``tag``: Particular tag to check out * ``tag``: Particular tag to check out
* ``commit``: Particular commit hash in the repo * ``commit``: Particular commit hash in the repo
""" """
enabled = True enabled = True
required_attributes = ('git',) required_attributes = ('git', )
def __init__(self, **kwargs): def __init__(self, **kwargs):
# Discards the keywords in kwargs that may conflict with the next call to __init__ # Discards the keywords in kwargs that may conflict with the next call
# to __init__
forwarded_args = copy.copy(kwargs) forwarded_args = copy.copy(kwargs)
forwarded_args.pop('name', None) forwarded_args.pop('name', None)
super(GitFetchStrategy, self).__init__( super(GitFetchStrategy, self).__init__(
'git', 'tag', 'branch', 'commit', **forwarded_args) 'git', 'tag', 'branch', 'commit', **forwarded_args)
self._git = None self._git = None
@property @property
@ -569,12 +600,13 @@ class SvnFetchStrategy(VCSFetchStrategy):
required_attributes = ['svn'] required_attributes = ['svn']
def __init__(self, **kwargs): def __init__(self, **kwargs):
# Discards the keywords in kwargs that may conflict with the next call to __init__ # Discards the keywords in kwargs that may conflict with the next call
# to __init__
forwarded_args = copy.copy(kwargs) forwarded_args = copy.copy(kwargs)
forwarded_args.pop('name', None) forwarded_args.pop('name', None)
super(SvnFetchStrategy, self).__init__( super(SvnFetchStrategy, self).__init__(
'svn', 'revision', **forwarded_args) 'svn', 'revision', **forwarded_args)
self._svn = None self._svn = None
if self.revision is not None: if self.revision is not None:
self.revision = str(self.revision) self.revision = str(self.revision)
@ -630,32 +662,35 @@ def __str__(self):
class HgFetchStrategy(VCSFetchStrategy): class HgFetchStrategy(VCSFetchStrategy):
"""Fetch strategy that gets source code from a Mercurial repository. """
Use like this in a package: Fetch strategy that gets source code from a Mercurial repository.
Use like this in a package:
version('name', hg='https://jay.grs.rwth-aachen.de/hg/lwm2') version('name', hg='https://jay.grs.rwth-aachen.de/hg/lwm2')
Optionally, you can provide a branch, or revision to check out, e.g.: Optionally, you can provide a branch, or revision to check out, e.g.:
version('torus', hg='https://jay.grs.rwth-aachen.de/hg/lwm2', branch='torus') version('torus',
hg='https://jay.grs.rwth-aachen.de/hg/lwm2', branch='torus')
You can use the optional 'revision' attribute to check out a You can use the optional 'revision' attribute to check out a
branch, tag, or particular revision in hg. To prevent branch, tag, or particular revision in hg. To prevent
non-reproducible builds, using a moving target like a branch is non-reproducible builds, using a moving target like a branch is
discouraged. discouraged.
* ``revision``: Particular revision, branch, or tag. * ``revision``: Particular revision, branch, or tag.
""" """
enabled = True enabled = True
required_attributes = ['hg'] required_attributes = ['hg']
def __init__(self, **kwargs): def __init__(self, **kwargs):
# Discards the keywords in kwargs that may conflict with the next call to __init__ # Discards the keywords in kwargs that may conflict with the next call
# to __init__
forwarded_args = copy.copy(kwargs) forwarded_args = copy.copy(kwargs)
forwarded_args.pop('name', None) forwarded_args.pop('name', None)
super(HgFetchStrategy, self).__init__( super(HgFetchStrategy, self).__init__(
'hg', 'revision', **forwarded_args) 'hg', 'revision', **forwarded_args)
self._hg = None self._hg = None
@property @property
@ -729,7 +764,8 @@ def from_kwargs(**kwargs):
return fetcher(**kwargs) return fetcher(**kwargs)
# Raise an error in case we can't instantiate any known strategy # Raise an error in case we can't instantiate any known strategy
message = "Cannot instantiate any FetchStrategy" message = "Cannot instantiate any FetchStrategy"
long_message = message + " from the given arguments : {arguments}".format(srguments=kwargs) long_message = message + " from the given arguments : {arguments}".format(
srguments=kwargs)
raise FetchError(message, long_message) raise FetchError(message, long_message)
@ -741,7 +777,7 @@ def for_package_version(pkg, version):
"""Determine a fetch strategy based on the arguments supplied to """Determine a fetch strategy based on the arguments supplied to
version() in the package description.""" version() in the package description."""
# If it's not a known version, extrapolate one. # If it's not a known version, extrapolate one.
if not version in pkg.versions: if version not in pkg.versions:
url = pkg.url_for_version(version) url = pkg.url_for_version(version)
if not url: if not url:
raise InvalidArgsError(pkg, version) raise InvalidArgsError(pkg, version)
@ -779,7 +815,7 @@ class FailedDownloadError(FetchError):
def __init__(self, url, msg=""): def __init__(self, url, msg=""):
super(FailedDownloadError, self).__init__( super(FailedDownloadError, self).__init__(
"Failed to fetch file from URL: %s" % url, msg) "Failed to fetch file from URL: %s" % url, msg)
self.url = url self.url = url
@ -795,7 +831,8 @@ def __init__(self, msg, long_msg=None):
class InvalidArgsError(FetchError): class InvalidArgsError(FetchError):
def __init__(self, pkg, version): def __init__(self, pkg, version):
msg = "Could not construct a fetch strategy for package %s at version %s" msg = ("Could not construct a fetch strategy for package %s at "
"version %s")
msg %= (pkg.name, version) msg %= (pkg.name, version)
super(InvalidArgsError, self).__init__(msg) super(InvalidArgsError, self).__init__(msg)
@ -812,4 +849,5 @@ class NoStageError(FetchError):
def __init__(self, method): def __init__(self, method):
super(NoStageError, self).__init__( super(NoStageError, self).__init__(
"Must call FetchStrategy.set_stage() before calling %s" % method.__name__) "Must call FetchStrategy.set_stage() before calling %s" %
method.__name__)

View File

@ -22,10 +22,8 @@
# License along with this program; if not, write to the Free Software # License along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
############################################################################## ##############################################################################
__all__ = ['Executable', 'which', 'ProcessError']
import os import os
import sys
import re import re
import subprocess import subprocess
import inspect import inspect
@ -34,9 +32,12 @@
import spack import spack
import spack.error import spack.error
__all__ = ['Executable', 'which', 'ProcessError']
class Executable(object): class Executable(object):
"""Class representing a program that can be run on the command line.""" """Class representing a program that can be run on the command line."""
def __init__(self, name): def __init__(self, name):
self.exe = name.split(' ') self.exe = name.split(' ')
self.returncode = None self.returncode = None
@ -44,16 +45,13 @@ def __init__(self, name):
if not self.exe: if not self.exe:
raise ProcessError("Cannot construct executable for '%s'" % name) raise ProcessError("Cannot construct executable for '%s'" % name)
def add_default_arg(self, arg): def add_default_arg(self, arg):
self.exe.append(arg) self.exe.append(arg)
@property @property
def command(self): def command(self):
return ' '.join(self.exe) return ' '.join(self.exe)
def __call__(self, *args, **kwargs): def __call__(self, *args, **kwargs):
"""Run this executable in a subprocess. """Run this executable in a subprocess.
@ -105,7 +103,7 @@ def __call__(self, *args, **kwargs):
fail_on_error = kwargs.pop("fail_on_error", True) fail_on_error = kwargs.pop("fail_on_error", True)
ignore_errors = kwargs.pop("ignore_errors", ()) ignore_errors = kwargs.pop("ignore_errors", ())
env = kwargs.get('env', None) env = kwargs.get('env', None)
# TODO: This is deprecated. Remove in a future version. # TODO: This is deprecated. Remove in a future version.
return_output = kwargs.pop("return_output", False) return_output = kwargs.pop("return_output", False)
@ -116,8 +114,8 @@ def __call__(self, *args, **kwargs):
else: else:
output = kwargs.pop("output", None) output = kwargs.pop("output", None)
error = kwargs.pop("error", None) error = kwargs.pop("error", None)
input = kwargs.pop("input", None) input = kwargs.pop("input", None)
if input is str: if input is str:
raise ValueError("Cannot use `str` as input stream.") raise ValueError("Cannot use `str` as input stream.")
@ -128,85 +126,90 @@ def streamify(arg, mode):
return subprocess.PIPE, False return subprocess.PIPE, False
else: else:
return arg, False return arg, False
ostream, close_ostream = streamify(output, 'w') ostream, close_ostream = streamify(output, 'w')
estream, close_estream = streamify(error, 'w') estream, close_estream = streamify(error, 'w')
istream, close_istream = streamify(input, 'r') istream, close_istream = streamify(input, 'r')
# if they just want to ignore one error code, make it a tuple. # if they just want to ignore one error code, make it a tuple.
if isinstance(ignore_errors, int): if isinstance(ignore_errors, int):
ignore_errors = (ignore_errors,) ignore_errors = (ignore_errors, )
quoted_args = [arg for arg in args if re.search(r'^"|^\'|"$|\'$', arg)] quoted_args = [arg for arg in args if re.search(r'^"|^\'|"$|\'$', arg)]
if quoted_args: if quoted_args:
tty.warn("Quotes in command arguments can confuse scripts like configure.", tty.warn(
"The following arguments may cause problems when executed:", "Quotes in command arguments can confuse scripts like"
str("\n".join([" "+arg for arg in quoted_args])), " configure.",
"Quotes aren't needed because spack doesn't use a shell.", "The following arguments may cause problems when executed:",
"Consider removing them") str("\n".join([" " + arg for arg in quoted_args])),
"Quotes aren't needed because spack doesn't use a shell.",
"Consider removing them")
cmd = self.exe + list(args) cmd = self.exe + list(args)
cmd_line = "'%s'" % "' '".join(map(lambda arg: arg.replace("'", "'\"'\"'"), cmd)) cmd_line = "'%s'" % "' '".join(
map(lambda arg: arg.replace("'", "'\"'\"'"), cmd))
tty.debug(cmd_line) tty.debug(cmd_line)
try: try:
proc = subprocess.Popen( proc = subprocess.Popen(
cmd, stdin=istream, stderr=estream, stdout=ostream, env=env) cmd,
stdin=istream,
stderr=estream,
stdout=ostream,
env=env)
out, err = proc.communicate() out, err = proc.communicate()
rc = self.returncode = proc.returncode rc = self.returncode = proc.returncode
if fail_on_error and rc != 0 and (rc not in ignore_errors): if fail_on_error and rc != 0 and (rc not in ignore_errors):
raise ProcessError("Command exited with status %d:" raise ProcessError("Command exited with status %d:" %
% proc.returncode, cmd_line) proc.returncode, cmd_line)
if output is str or error is str: if output is str or error is str:
result = '' result = ''
if output is str: result += out if output is str:
if error is str: result += err result += out
if error is str:
result += err
return result return result
except OSError, e: except OSError, e:
raise ProcessError( raise ProcessError(
"%s: %s" % (self.exe[0], e.strerror), "%s: %s" % (self.exe[0], e.strerror), "Command: " + cmd_line)
"Command: " + cmd_line)
except subprocess.CalledProcessError, e: except subprocess.CalledProcessError, e:
if fail_on_error: if fail_on_error:
raise ProcessError( raise ProcessError(
str(e), str(e), "\nExit status %d when invoking command: %s" %
"\nExit status %d when invoking command: %s" (proc.returncode, cmd_line))
% (proc.returncode, cmd_line))
finally: finally:
if close_ostream: output.close() if close_ostream:
if close_estream: error.close() output.close()
if close_istream: input.close() if close_estream:
error.close()
if close_istream:
input.close()
def __eq__(self, other): def __eq__(self, other):
return self.exe == other.exe return self.exe == other.exe
def __neq__(self, other): def __neq__(self, other):
return not (self == other) return not (self == other)
def __hash__(self): def __hash__(self):
return hash((type(self),) + tuple(self.exe)) return hash((type(self), ) + tuple(self.exe))
def __repr__(self): def __repr__(self):
return "<exe: %s>" % self.exe return "<exe: %s>" % self.exe
def __str__(self): def __str__(self):
return ' '.join(self.exe) return ' '.join(self.exe)
def which(name, **kwargs): def which(name, **kwargs):
"""Finds an executable in the path like command-line which.""" """Finds an executable in the path like command-line which."""
path = kwargs.get('path', os.environ.get('PATH', '').split(os.pathsep)) path = kwargs.get('path', os.environ.get('PATH', '').split(os.pathsep))
required = kwargs.get('required', False) required = kwargs.get('required', False)
if not path: if not path:
@ -235,14 +238,16 @@ def __init__(self, msg, long_message=None):
@property @property
def long_message(self): def long_message(self):
msg = self._long_message msg = self._long_message
if msg: msg += "\n\n" if msg:
msg += "\n\n"
if self.build_log: if self.build_log:
msg += "See build log for details:\n" msg += "See build log for details:\n"
msg += " %s" % self.build_log msg += " %s" % self.build_log
if self.package_context: if self.package_context:
if msg: msg += "\n\n" if msg:
msg += "\n\n"
msg += '\n'.join(self.package_context) msg += '\n'.join(self.package_context)
return msg return msg
@ -269,7 +274,7 @@ def _get_package_context():
frame = f[0] frame = f[0]
# Find a frame with 'self' in the local variables. # Find a frame with 'self' in the local variables.
if not 'self' in frame.f_locals: if 'self' not in frame.f_locals:
continue continue
# Look only at a frame in a subclass of spack.Package # Look only at a frame in a subclass of spack.Package
@ -282,9 +287,8 @@ def _get_package_context():
# Build a message showing where in install we failed. # Build a message showing where in install we failed.
lines.append("%s:%d, in %s:" % ( lines.append("%s:%d, in %s:" % (
inspect.getfile(frame.f_code), inspect.getfile(frame.f_code), frame.f_lineno, frame.f_code.co_name
frame.f_lineno, ))
frame.f_code.co_name))
sourcelines, start = inspect.getsourcelines(frame) sourcelines, start = inspect.getsourcelines(frame)
for i, line in enumerate(sourcelines): for i, line in enumerate(sourcelines):

View File

@ -1,15 +1,16 @@
from spack import * from spack import *
class Hub(Package): class Hub(Package):
"""The github git wrapper""" """The github git wrapper"""
homepage = "https://github.com/github/hub" homepage = "https://github.com/github/hub"
url = "https://github.com/github/hub/archive/v2.2.3.tar.gz" url = "https://github.com/github/hub/archive/v2.2.3.tar.gz"
version('head' , git='https://github.com/github/hub') version('head', git='https://github.com/github/hub')
version('2.2.3' , '6675992ddd16d186eac7ba4484d57f5b') version('2.2.3', '6675992ddd16d186eac7ba4484d57f5b')
version('2.2.2' , '7edc8f5b5d3c7c392ee191dd999596fc') version('2.2.2', '7edc8f5b5d3c7c392ee191dd999596fc')
version('2.2.1' , '889a31ee9d10ae9cb333480d8dbe881f') version('2.2.1', '889a31ee9d10ae9cb333480d8dbe881f')
version('2.2.0' , 'eddce830a079b8480f104aa7496f46fe') version('2.2.0', 'eddce830a079b8480f104aa7496f46fe')
version('1.12.4', '4f2ebb14834c9981b04e40b0d1754717') version('1.12.4', '4f2ebb14834c9981b04e40b0d1754717')
extends("go") extends("go")
@ -17,4 +18,5 @@ class Hub(Package):
def install(self, spec, prefix): def install(self, spec, prefix):
os.environ['GOPATH'] = os.getcwd() os.environ['GOPATH'] = os.getcwd()
bash = which('bash') bash = which('bash')
bash(os.path.join('script', 'build'), '-o', os.path.join(prefix, 'bin', 'hub')) bash(os.path.join('script', 'build'), '-o', os.path.join(prefix, 'bin',
'hub'))

View File

@ -5,9 +5,8 @@
class ThePlatinumSearcher(Package): class ThePlatinumSearcher(Package):
"""Fast parallel recursive grep alternative""" """Fast parallel recursive grep alternative"""
# FIXME: add a proper url for your package's homepage here.
homepage = "https://github.com/monochromegane/the_platinum_searcher" homepage = "https://github.com/monochromegane/the_platinum_searcher"
url = "https://github.com/monochromegane/the_platinum_searcher" url = "https://github.com/monochromegane/the_platinum_searcher"
package = 'github.com/monochromegane/the_platinum_searcher/...' package = 'github.com/monochromegane/the_platinum_searcher/...'