Skip to content

Commit

Permalink
style: make core comply with pep8-naming
Browse files Browse the repository at this point in the history
  • Loading branch information
tgamblin committed Jul 19, 2018
1 parent 1713cb3 commit 20e4038
Show file tree
Hide file tree
Showing 35 changed files with 106 additions and 104 deletions.
5 changes: 4 additions & 1 deletion .flake8
Expand Up @@ -16,6 +16,9 @@
# These are required to get the package.py files to test clean:
# - F999: syntax error in doctest
#
# Exempt to allow decorator classes to be lowercase, but follow otherwise:
# - N801: CapWords for class names.
#
[flake8]
ignore = E129,E221,E241,E272,E731,F999
ignore = E129,E221,E241,E272,E731,F999,N801
max-line-length = 79
4 changes: 2 additions & 2 deletions lib/spack/llnl/util/lang.py
Expand Up @@ -282,8 +282,8 @@ def _cmp_key(self):
def copy(self):
"""Type-agnostic clone method. Preserves subclass type."""
# Construct a new dict of my type
T = type(self)
clone = T()
self_type = type(self)
clone = self_type()

# Copy everything from this dict into it.
for key in self:
Expand Down
6 changes: 3 additions & 3 deletions lib/spack/llnl/util/multiproc.py
Expand Up @@ -39,10 +39,10 @@ def fun(pipe, x):
return fun


def parmap(f, X):
pipe = [Pipe() for x in X]
def parmap(f, elements):
pipe = [Pipe() for x in elements]
proc = [Process(target=spawn(f), args=(c, x))
for x, (p, c) in zip(X, pipe)]
for x, (p, c) in zip(elements, pipe)]
[p.start() for p in proc]
[p.join() for p in proc]
return [p.recv() for (p, c) in pipe]
Expand Down
6 changes: 3 additions & 3 deletions lib/spack/llnl/util/tty/__init__.py
Expand Up @@ -246,18 +246,18 @@ def hline(label=None, **kwargs):

def terminal_size():
"""Gets the dimensions of the console: (rows, cols)."""
def ioctl_GWINSZ(fd):
def ioctl_gwinsz(fd):
try:
rc = struct.unpack('hh', fcntl.ioctl(
fd, termios.TIOCGWINSZ, '1234'))
except BaseException:
return
return rc
rc = ioctl_GWINSZ(0) or ioctl_GWINSZ(1) or ioctl_GWINSZ(2)
rc = ioctl_gwinsz(0) or ioctl_gwinsz(1) or ioctl_gwinsz(2)
if not rc:
try:
fd = os.open(os.ctermid(), os.O_RDONLY)
rc = ioctl_GWINSZ(fd)
rc = ioctl_gwinsz(fd)
os.close(fd)
except BaseException:
pass
Expand Down
5 changes: 2 additions & 3 deletions lib/spack/spack/architecture.py
Expand Up @@ -193,14 +193,13 @@ def operating_system(self, name):
return self.operating_sys.get(name, None)

@classmethod
def setup_platform_environment(self, pkg, env):
def setup_platform_environment(cls, pkg, env):
""" Subclass can override this method if it requires any
platform-specific build environment modifications.
"""
pass

@classmethod
def detect(self):
def detect(cls):
""" Subclass is responsible for implementing this method.
Returns True if the Platform class detects that
it is the current platform
Expand Down
6 changes: 3 additions & 3 deletions lib/spack/spack/binary_distribution.py
Expand Up @@ -203,13 +203,13 @@ def tarball_path_name(spec, ext):

def checksum_tarball(file):
# calculate sha256 hash of tar file
BLOCKSIZE = 65536
block_size = 65536
hasher = hashlib.sha256()
with open(file, 'rb') as tfile:
buf = tfile.read(BLOCKSIZE)
buf = tfile.read(block_size)
while len(buf) > 0:
hasher.update(buf)
buf = tfile.read(BLOCKSIZE)
buf = tfile.read(block_size)
return hasher.hexdigest()


Expand Down
4 changes: 2 additions & 2 deletions lib/spack/spack/cmd/create.py
Expand Up @@ -676,8 +676,8 @@ def create(parser, args):
build_system = get_build_system(args, guesser)

# Create the package template object
PackageClass = templates[build_system]
package = PackageClass(name, url, versions)
package_class = templates[build_system]
package = package_class(name, url, versions)
tty.msg("Created template for {0} package".format(package.name))

# Create a directory for the new package
Expand Down
2 changes: 1 addition & 1 deletion lib/spack/spack/compilers/nag.py
Expand Up @@ -72,7 +72,7 @@ def fc_rpath_arg(self):
return '-Wl,-Wl,,-rpath,,'

@classmethod
def default_version(self, comp):
def default_version(cls, comp):
"""The ``-V`` option works for nag compilers.
Output looks like this::
Expand Down
2 changes: 1 addition & 1 deletion lib/spack/spack/compilers/xl_r.py
Expand Up @@ -74,7 +74,7 @@ def fflags(self):
return "-qzerosize"

@classmethod
def default_version(self, comp):
def default_version(cls, comp):
"""The '-qversion' is the standard option fo XL compilers.
Output looks like this::
Expand Down
4 changes: 2 additions & 2 deletions lib/spack/spack/config.py
Expand Up @@ -542,9 +542,9 @@ def _validate_section(data, schema):
"""
import jsonschema
if not hasattr(_validate_section, 'validator'):
DefaultSettingValidator = _extend_with_default(
default_setting_validator = _extend_with_default(
jsonschema.Draft4Validator)
_validate_section.validator = DefaultSettingValidator
_validate_section.validator = default_setting_validator

try:
_validate_section.validator(schema).validate(data)
Expand Down
6 changes: 3 additions & 3 deletions lib/spack/spack/directives.py
Expand Up @@ -80,7 +80,7 @@ class DirectiveMeta(type):
_directive_names = set()
_directives_to_be_executed = []

def __new__(mcs, name, bases, attr_dict):
def __new__(cls, name, bases, attr_dict):
# Initialize the attribute containing the list of directives
# to be executed. Here we go reversed because we want to execute
# commands:
Expand Down Expand Up @@ -109,8 +109,8 @@ def __new__(mcs, name, bases, attr_dict):
DirectiveMeta._directives_to_be_executed)
DirectiveMeta._directives_to_be_executed = []

return super(DirectiveMeta, mcs).__new__(
mcs, name, bases, attr_dict)
return super(DirectiveMeta, cls).__new__(
cls, name, bases, attr_dict)

def __init__(cls, name, bases, attr_dict):
# The class is being created: if it is a package we must ensure
Expand Down
8 changes: 4 additions & 4 deletions lib/spack/spack/fetch_strategy.py
Expand Up @@ -1026,7 +1026,7 @@ class FsCache(object):
def __init__(self, root):
self.root = os.path.abspath(root)

def store(self, fetcher, relativeDst):
def store(self, fetcher, relative_dest):
# skip fetchers that aren't cachable
if not fetcher.cachable:
return
Expand All @@ -1035,12 +1035,12 @@ def store(self, fetcher, relativeDst):
if isinstance(fetcher, CacheURLFetchStrategy):
return

dst = os.path.join(self.root, relativeDst)
dst = os.path.join(self.root, relative_dest)
mkdirp(os.path.dirname(dst))
fetcher.archive(dst)

def fetcher(self, targetPath, digest, **kwargs):
path = os.path.join(self.root, targetPath)
def fetcher(self, target_path, digest, **kwargs):
path = os.path.join(self.root, target_path)
return CacheURLFetchStrategy(path, digest, **kwargs)

def destroy(self):
Expand Down
10 changes: 5 additions & 5 deletions lib/spack/spack/mirror.py
Expand Up @@ -44,7 +44,7 @@
from spack.util.compression import allowed_archive


def mirror_archive_filename(spec, fetcher, resourceId=None):
def mirror_archive_filename(spec, fetcher, resource_id=None):
"""Get the name of the spec's archive in the mirror."""
if not spec.version.concrete:
raise ValueError("mirror.path requires spec with concrete version.")
Expand Down Expand Up @@ -87,18 +87,18 @@ def mirror_archive_filename(spec, fetcher, resourceId=None):
# Otherwise we'll make a .tar.gz ourselves
ext = 'tar.gz'

if resourceId:
filename = "%s-%s" % (resourceId, spec.version) + ".%s" % ext
if resource_id:
filename = "%s-%s" % (resource_id, spec.version) + ".%s" % ext
else:
filename = "%s-%s" % (spec.package.name, spec.version) + ".%s" % ext

return filename


def mirror_archive_path(spec, fetcher, resourceId=None):
def mirror_archive_path(spec, fetcher, resource_id=None):
"""Get the relative path to the spec's archive within a mirror."""
return os.path.join(
spec.name, mirror_archive_filename(spec, fetcher, resourceId))
spec.name, mirror_archive_filename(spec, fetcher, resource_id))


def get_matching_versions(specs, **kwargs):
Expand Down
2 changes: 1 addition & 1 deletion lib/spack/spack/operating_systems/mac_os.py
Expand Up @@ -29,7 +29,7 @@


# FIXME: store versions inside OperatingSystem as a Version instead of string
def macOS_version():
def macos_version():
"""temporary workaround to return a macOS version as a Version object
"""
return Version('.'.join(py_platform.mac_ver()[0].split('.')[:2]))
Expand Down
23 changes: 12 additions & 11 deletions lib/spack/spack/package.py
Expand Up @@ -163,7 +163,7 @@ class PackageMeta(
_InstallPhase_run_before = {}
_InstallPhase_run_after = {}

def __new__(mcs, name, bases, attr_dict):
def __new__(cls, name, bases, attr_dict):

if 'phases' in attr_dict:
# Turn the strings in 'phases' into InstallPhase instances
Expand All @@ -176,7 +176,7 @@ def __new__(mcs, name, bases, attr_dict):
def _flush_callbacks(check_name):
# Name of the attribute I am going to check it exists
attr_name = PackageMeta.phase_fmt.format(check_name)
checks = getattr(mcs, attr_name)
checks = getattr(cls, attr_name)
if checks:
for phase_name, funcs in checks.items():
try:
Expand All @@ -202,12 +202,12 @@ def _flush_callbacks(check_name):
PackageMeta.phase_fmt.format(phase_name)]
getattr(phase, check_name).extend(funcs)
# Clear the attribute for the next class
setattr(mcs, attr_name, {})
setattr(cls, attr_name, {})

_flush_callbacks('run_before')
_flush_callbacks('run_after')

return super(PackageMeta, mcs).__new__(mcs, name, bases, attr_dict)
return super(PackageMeta, cls).__new__(cls, name, bases, attr_dict)

@staticmethod
def register_callback(check_type, *phases):
Expand Down Expand Up @@ -1229,7 +1229,7 @@ def content_hash(self, content=None):
" if the associated spec is not concrete")
raise spack.error.SpackError(err_msg)

hashContent = list()
hash_content = list()
source_id = fs.for_package_version(self, self.version).source_id()
if not source_id:
# TODO? in cases where a digest or source_id isn't available,
Expand All @@ -1238,14 +1238,15 @@ def content_hash(self, content=None):
# referenced by branch name rather than tag or commit ID.
message = 'Missing a source id for {s.name}@{s.version}'
tty.warn(message.format(s=self))
hashContent.append(''.encode('utf-8'))
hash_content.append(''.encode('utf-8'))
else:
hashContent.append(source_id.encode('utf-8'))
hashContent.extend(':'.join((p.sha256, str(p.level))).encode('utf-8')
for p in self.spec.patches)
hashContent.append(package_hash(self.spec, content))
hash_content.append(source_id.encode('utf-8'))
hash_content.extend(':'.join((p.sha256, str(p.level))).encode('utf-8')
for p in self.spec.patches)
hash_content.append(package_hash(self.spec, content))
return base64.b32encode(
hashlib.sha256(bytes().join(sorted(hashContent))).digest()).lower()
hashlib.sha256(bytes().join(
sorted(hash_content))).digest()).lower()

@property
def namespace(self):
Expand Down
2 changes: 1 addition & 1 deletion lib/spack/spack/platforms/bgq.py
Expand Up @@ -53,5 +53,5 @@ def __init__(self):
self.add_operating_system(str(back_distro), back_distro)

@classmethod
def detect(self):
def detect(cls):
return os.path.exists('/bgsys')
2 changes: 1 addition & 1 deletion lib/spack/spack/platforms/darwin.py
Expand Up @@ -45,5 +45,5 @@ def __init__(self):
self.add_operating_system(str(mac_os), mac_os)

@classmethod
def detect(self):
def detect(cls):
return 'darwin' in platform.system().lower()
2 changes: 1 addition & 1 deletion lib/spack/spack/platforms/linux.py
Expand Up @@ -49,5 +49,5 @@ def __init__(self):
self.add_operating_system(str(linux_dist), linux_dist)

@classmethod
def detect(self):
def detect(cls):
return 'linux' in platform.system().lower()
10 changes: 6 additions & 4 deletions lib/spack/spack/platforms/test.py
Expand Up @@ -23,7 +23,7 @@
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
##############################################################################
from spack.architecture import Platform, Target
from spack.architecture import OperatingSystem as OS
from spack.architecture import OperatingSystem


class Test(Platform):
Expand All @@ -41,9 +41,11 @@ def __init__(self):
self.add_target(self.default, Target(self.default))
self.add_target(self.front_end, Target(self.front_end))

self.add_operating_system(self.default_os, OS('debian', 6))
self.add_operating_system(self.front_os, OS('redhat', 6))
self.add_operating_system(
self.default_os, OperatingSystem('debian', 6))
self.add_operating_system(
self.front_os, OperatingSystem('redhat', 6))

@classmethod
def detect(self):
def detect(cls):
return True
4 changes: 2 additions & 2 deletions lib/spack/spack/stage.py
Expand Up @@ -432,9 +432,9 @@ def generate_fetchers():
tty.debug(e)
continue
else:
errMessage = "All fetchers failed for %s" % self.name
err_msg = "All fetchers failed for %s" % self.name
self.fetcher = self.default_fetcher
raise fs.FetchError(errMessage, None)
raise fs.FetchError(err_msg, None)

def check(self):
"""Check the downloaded archive against a checksum digest.
Expand Down
12 changes: 6 additions & 6 deletions lib/spack/spack/tengine.py
Expand Up @@ -43,10 +43,10 @@ class ContextMeta(type):
#: by the class that is being defined
_new_context_properties = []

def __new__(mcs, name, bases, attr_dict):
def __new__(cls, name, bases, attr_dict):
# Merge all the context properties that are coming from base classes
# into a list without duplicates.
context_properties = list(mcs._new_context_properties)
context_properties = list(cls._new_context_properties)
for x in bases:
try:
context_properties.extend(x.context_properties)
Expand All @@ -55,20 +55,20 @@ def __new__(mcs, name, bases, attr_dict):
context_properties = list(llnl.util.lang.dedupe(context_properties))

# Flush the list
mcs._new_context_properties = []
cls._new_context_properties = []

# Attach the list to the class being created
attr_dict['context_properties'] = context_properties

return super(ContextMeta, mcs).__new__(mcs, name, bases, attr_dict)
return super(ContextMeta, cls).__new__(cls, name, bases, attr_dict)

@classmethod
def context_property(mcs, func):
def context_property(cls, func):
"""Decorator that adds a function name to the list of new context
properties, and then returns a property.
"""
name = func.__name__
mcs._new_context_properties.append(name)
cls._new_context_properties.append(name)
return property(func)


Expand Down

0 comments on commit 20e4038

Please sign in to comment.