diff --git a/.flake8 b/.flake8
index 49199b35c80a8c76e8e101925d68c2af7c5bbb98..9e7956c919ed37d5acf95c28063da87b2e5331c5 100644
--- a/.flake8
+++ b/.flake8
@@ -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
diff --git a/lib/spack/llnl/util/lang.py b/lib/spack/llnl/util/lang.py
index edba6e38e19e35d739d00da074bb3278a354207b..4d238217a19da92d023329d2fc6f5fe2c09c46c7 100644
--- a/lib/spack/llnl/util/lang.py
+++ b/lib/spack/llnl/util/lang.py
@@ -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:
diff --git a/lib/spack/llnl/util/multiproc.py b/lib/spack/llnl/util/multiproc.py
index 2bf5d1a2001366252dd525b82f8fe8de6104ed7a..26902d02ee4b3c3138445099d43b40c168a052e4 100644
--- a/lib/spack/llnl/util/multiproc.py
+++ b/lib/spack/llnl/util/multiproc.py
@@ -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]
diff --git a/lib/spack/llnl/util/tty/__init__.py b/lib/spack/llnl/util/tty/__init__.py
index d8e5f35379111b4a81d017ddf6614b0615160183..5bf4e0f8ba0a2bc03326cfa487a195c40203276b 100644
--- a/lib/spack/llnl/util/tty/__init__.py
+++ b/lib/spack/llnl/util/tty/__init__.py
@@ -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
diff --git a/lib/spack/spack/architecture.py b/lib/spack/spack/architecture.py
index 4ef61d569fb2dd25f06f358f4899048c5d022546..ca0a647121b504577d317f4ee7be19db06fdfb42 100644
--- a/lib/spack/spack/architecture.py
+++ b/lib/spack/spack/architecture.py
@@ -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
diff --git a/lib/spack/spack/binary_distribution.py b/lib/spack/spack/binary_distribution.py
index b96237ed9968c03978a2a76e0f0539b0494e7f39..c743be726109ca74fe9232b068bc4fcbcb756fe6 100644
--- a/lib/spack/spack/binary_distribution.py
+++ b/lib/spack/spack/binary_distribution.py
@@ -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()
 
 
diff --git a/lib/spack/spack/cmd/create.py b/lib/spack/spack/cmd/create.py
index 650eb811896a7599c2dfc440f8600ae99a733d0d..eae6e6da3a311647bde5d7b7bd1f4ea38c7acce4 100644
--- a/lib/spack/spack/cmd/create.py
+++ b/lib/spack/spack/cmd/create.py
@@ -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
diff --git a/lib/spack/spack/compilers/nag.py b/lib/spack/spack/compilers/nag.py
index dbe7ae55cf15928734a243cdf9de0f6bb6dbd3b5..a279384a74d0081ff8ff98a07c6128fc4b25913a 100644
--- a/lib/spack/spack/compilers/nag.py
+++ b/lib/spack/spack/compilers/nag.py
@@ -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::
 
diff --git a/lib/spack/spack/compilers/xl_r.py b/lib/spack/spack/compilers/xl_r.py
index 9aa12a03cefad3c43ced1be3c7c14e5925beec65..d926c1d782a024cc7fd74dae6253b72d5a453fa9 100644
--- a/lib/spack/spack/compilers/xl_r.py
+++ b/lib/spack/spack/compilers/xl_r.py
@@ -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::
 
diff --git a/lib/spack/spack/config.py b/lib/spack/spack/config.py
index ec37c0a972bda23f2f6a7eb25c13bb93d7f20593..2e67f0e1da34e126b517ad4cddc46c5cb19bcd89 100644
--- a/lib/spack/spack/config.py
+++ b/lib/spack/spack/config.py
@@ -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)
diff --git a/lib/spack/spack/directives.py b/lib/spack/spack/directives.py
index 68678d904deb21d280af938d300ea87f3f5878df..56490f8452fab29f415ea13853d62e85f5173c3d 100644
--- a/lib/spack/spack/directives.py
+++ b/lib/spack/spack/directives.py
@@ -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:
@@ -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
diff --git a/lib/spack/spack/fetch_strategy.py b/lib/spack/spack/fetch_strategy.py
index d1c6f607b309e0828865f70883d38c2fdc5dac6b..3a08deb7540a648b77196faaede17564c94975df 100644
--- a/lib/spack/spack/fetch_strategy.py
+++ b/lib/spack/spack/fetch_strategy.py
@@ -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
@@ -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):
diff --git a/lib/spack/spack/mirror.py b/lib/spack/spack/mirror.py
index 14e4b482efeaf108721fa1269cedee6a5f6314f7..c04a769ba4b355cebc0a6ba6187b05366ab57ab9 100644
--- a/lib/spack/spack/mirror.py
+++ b/lib/spack/spack/mirror.py
@@ -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.")
@@ -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):
diff --git a/lib/spack/spack/operating_systems/mac_os.py b/lib/spack/spack/operating_systems/mac_os.py
index 8f283e2fe198ffb432ceec675f3a227060e57c85..39e3afbda3a3d6a3080b08c1a8bb91bbf5fab590 100644
--- a/lib/spack/spack/operating_systems/mac_os.py
+++ b/lib/spack/spack/operating_systems/mac_os.py
@@ -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]))
diff --git a/lib/spack/spack/package.py b/lib/spack/spack/package.py
index b203551b0766c9474551aa06ca439ad3a67f9685..75aed2e899152db3462319a8befad448c234c721 100644
--- a/lib/spack/spack/package.py
+++ b/lib/spack/spack/package.py
@@ -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
@@ -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:
@@ -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):
@@ -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,
@@ -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):
diff --git a/lib/spack/spack/platforms/bgq.py b/lib/spack/spack/platforms/bgq.py
index 1c465420187ceb5dc4d350052927314182b26516..18004d88806b640c4eff4337d563694b9f4c9ba4 100644
--- a/lib/spack/spack/platforms/bgq.py
+++ b/lib/spack/spack/platforms/bgq.py
@@ -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')
diff --git a/lib/spack/spack/platforms/darwin.py b/lib/spack/spack/platforms/darwin.py
index 3d9e4df9c5db5c5ddfbc6121d5a1225a84dc016e..fba3de7fe9e9b51706f2ce3b4e87a64866c82f4c 100644
--- a/lib/spack/spack/platforms/darwin.py
+++ b/lib/spack/spack/platforms/darwin.py
@@ -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()
diff --git a/lib/spack/spack/platforms/linux.py b/lib/spack/spack/platforms/linux.py
index cf263bb457ac69a01b196895ee23bb7490af07bd..0cf906e355e7cc5124f5b1504f83f94cab178723 100644
--- a/lib/spack/spack/platforms/linux.py
+++ b/lib/spack/spack/platforms/linux.py
@@ -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()
diff --git a/lib/spack/spack/platforms/test.py b/lib/spack/spack/platforms/test.py
index a1ad34b46f22e2961c4151dde89ae1b45356b7b0..fa1c86effa3f4f75b4cc31176019b7e4a413e5a9 100644
--- a/lib/spack/spack/platforms/test.py
+++ b/lib/spack/spack/platforms/test.py
@@ -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):
@@ -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
diff --git a/lib/spack/spack/stage.py b/lib/spack/spack/stage.py
index 0111ccd840887f6700501c54756ee578cf532222..82363f31ee3aa2008c4f8fd6fb1c1d1d0604c1da 100644
--- a/lib/spack/spack/stage.py
+++ b/lib/spack/spack/stage.py
@@ -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.
diff --git a/lib/spack/spack/tengine.py b/lib/spack/spack/tengine.py
index 731ce787824fa324c5441e5fe607540ec02e473e..c3ce16ac04e8907001e90a7be4964a0282b69d32 100644
--- a/lib/spack/spack/tengine.py
+++ b/lib/spack/spack/tengine.py
@@ -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)
@@ -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)
 
 
diff --git a/lib/spack/spack/test/conftest.py b/lib/spack/spack/test/conftest.py
index 6649fa6a5e2345a45d58b8b7c12281bb30491cc3..4f4e01930a1a39e6d126ecc833f76d79f1ac1386 100644
--- a/lib/spack/spack/test/conftest.py
+++ b/lib/spack/spack/test/conftest.py
@@ -44,7 +44,7 @@
 import spack.repo
 import spack.stage
 import spack.util.executable
-import spack.util.pattern
+from spack.util.pattern import Bunch
 from spack.dependency import Dependency
 from spack.package import PackageBase
 from spack.fetch_strategy import FetchStrategyComposite, URLFetchStrategy
@@ -165,10 +165,10 @@ def mock_fetch_cache(monkeypatch):
     and raises on fetch.
     """
     class MockCache(object):
-        def store(self, copyCmd, relativeDst):
+        def store(self, copy_cmd, relative_dest):
             pass
 
-        def fetcher(self, targetPath, digest, **kwargs):
+        def fetcher(self, target_path, digest, **kwargs):
             return MockCacheFetcher()
 
     class MockCacheFetcher(object):
@@ -508,7 +508,6 @@ def mock_git_repository(tmpdir_factory):
         r1 = rev_hash(branch)
         r1_file = branch_file
 
-    Bunch = spack.util.pattern.Bunch
     checks = {
         'master': Bunch(
             revision='master', file=r0_file, args={'git': str(repodir)}
@@ -561,7 +560,6 @@ def mock_hg_repository(tmpdir_factory):
         hg('commit', '-m' 'revision 1', '-u', 'test')
         r1 = get_rev()
 
-    Bunch = spack.util.pattern.Bunch
     checks = {
         'default': Bunch(
             revision=r1, file=r1_file, args={'hg': str(repodir)}
@@ -618,7 +616,6 @@ def mock_svn_repository(tmpdir_factory):
         r0 = '1'
         r1 = '2'
 
-    Bunch = spack.util.pattern.Bunch
     checks = {
         'default': Bunch(
             revision=r1, file=r1_file, args={'svn': url}),
diff --git a/lib/spack/spack/test/flag_handlers.py b/lib/spack/spack/test/flag_handlers.py
index cd6955646d33088e04c7583580aab1ce543e0e0d..a81e00ca891b6195421f523e0f23e2a6bfa92453 100644
--- a/lib/spack/spack/test/flag_handlers.py
+++ b/lib/spack/spack/test/flag_handlers.py
@@ -37,7 +37,7 @@ def temp_env():
     os.environ = old_env
 
 
-def add_O3_to_build_system_cflags(pkg, name, flags):
+def add_o3_to_build_system_cflags(pkg, name, flags):
     build_system_flags = []
     if name == 'cflags':
         build_system_flags.append('-O3')
@@ -137,7 +137,7 @@ def test_add_build_system_flags_autotools(self, temp_env):
         s = spack.spec.Spec('libelf cppflags=-g')
         s.concretize()
         pkg = spack.repo.get(s)
-        pkg.flag_handler = add_O3_to_build_system_cflags
+        pkg.flag_handler = add_o3_to_build_system_cflags
         spack.build_environment.setup_package(pkg, False)
 
         assert '-g' in os.environ['SPACK_CPPFLAGS']
@@ -149,7 +149,7 @@ def test_add_build_system_flags_cmake(self, temp_env):
         s = spack.spec.Spec('callpath cppflags=-g')
         s.concretize()
         pkg = spack.repo.get(s)
-        pkg.flag_handler = add_O3_to_build_system_cflags
+        pkg.flag_handler = add_o3_to_build_system_cflags
         spack.build_environment.setup_package(pkg, False)
 
         assert '-g' in os.environ['SPACK_CPPFLAGS']
diff --git a/lib/spack/spack/test/llnl/util/file_list.py b/lib/spack/spack/test/llnl/util/file_list.py
index 56716614356fdcaba304f1268b905508d6be75ae..6499befd3ce6f803722860c45d60ac3caf28e2ee 100644
--- a/lib/spack/spack/test/llnl/util/file_list.py
+++ b/lib/spack/spack/test/llnl/util/file_list.py
@@ -263,7 +263,7 @@ def test_searching_order(search_fn, search_list, root, kwargs):
     # Now reverse the result and start discarding things
     # as soon as you have matches. In the end the list should
     # be emptied.
-    L = list(reversed(result))
+    rlist = list(reversed(result))
 
     # At this point make sure the search list is a sequence
     if isinstance(search_list, six.string_types):
@@ -272,14 +272,14 @@ def test_searching_order(search_fn, search_list, root, kwargs):
     # Discard entries in the order they appear in search list
     for x in search_list:
         try:
-            while fnmatch.fnmatch(L[-1], x) or x in L[-1]:
-                L.pop()
+            while fnmatch.fnmatch(rlist[-1], x) or x in rlist[-1]:
+                rlist.pop()
         except IndexError:
             # List is empty
             pass
 
     # List should be empty here
-    assert len(L) == 0
+    assert len(rlist) == 0
 
 
 @pytest.mark.parametrize('root,search_list,kwargs,expected', [
diff --git a/lib/spack/spack/test/module_parsing.py b/lib/spack/spack/test/module_parsing.py
index 978de51559dfd443e7e831d4eb773c2b03467b49..59ea6402d156c470a312e75114311c56c02f802e 100644
--- a/lib/spack/spack/test/module_parsing.py
+++ b/lib/spack/spack/test/module_parsing.py
@@ -42,13 +42,13 @@
 
 @pytest.fixture
 def save_env():
-    old_PATH = os.environ.get('PATH', None)
+    old_path = os.environ.get('PATH', None)
     old_bash_func = os.environ.get('BASH_FUNC_module()', None)
 
     yield
 
-    if old_PATH:
-        os.environ['PATH'] = old_PATH
+    if old_path:
+        os.environ['PATH'] = old_path
     if old_bash_func:
         os.environ['BASH_FUNC_module()'] = old_bash_func
 
diff --git a/lib/spack/spack/test/modules/lmod.py b/lib/spack/spack/test/modules/lmod.py
index 7371a9a0d7a7922a7019cdafbde4ed9614e924f4..82a31b03a3f085aebc208f33db2910441fe524f0 100644
--- a/lib/spack/spack/test/modules/lmod.py
+++ b/lib/spack/spack/test/modules/lmod.py
@@ -171,11 +171,11 @@ def test_no_hash(self, factory, patch_configuration):
         path = module.layout.filename
         mpi_spec = spec['mpi']
 
-        mpiElement = "{0}/{1}-{2}/".format(
+        mpi_element = "{0}/{1}-{2}/".format(
             mpi_spec.name, mpi_spec.version, mpi_spec.dag_hash(length=7)
         )
 
-        assert mpiElement in path
+        assert mpi_element in path
 
         mpileaks_spec = spec
         mpileaks_element = "{0}/{1}.lua".format(
diff --git a/lib/spack/spack/test/repo.py b/lib/spack/spack/test/repo.py
index 1bac0bb32a360304cf1fba079cb7790fbe945d92..789f0c2dec1ce102a2a47915ed582e5f8c349d42 100644
--- a/lib/spack/spack/test/repo.py
+++ b/lib/spack/spack/test/repo.py
@@ -42,8 +42,8 @@ def extra_repo(tmpdir_factory):
     repo_dir = tmpdir_factory.mktemp(repo_namespace)
     repo_dir.ensure('packages', dir=True)
 
-    with open(str(repo_dir.join('repo.yaml')), 'w') as F:
-        F.write("""
+    with open(str(repo_dir.join('repo.yaml')), 'w') as f:
+        f.write("""
 repo:
   namespace: extra_test_repo
 """)
diff --git a/lib/spack/spack/test/test_activations.py b/lib/spack/spack/test/test_activations.py
index 04f5580cd949d8f3c8c7faea4e99a80176b2a047..d9b69446a9a0952fac5b4d096a995b5c03dab0b5 100644
--- a/lib/spack/spack/test/test_activations.py
+++ b/lib/spack/spack/test/test_activations.py
@@ -137,8 +137,8 @@ def python_and_extension_dirs(tmpdir):
     create_dir_structure(ext_prefix, ext_dirs)
 
     easy_install_location = 'lib/python2.7/site-packages/easy-install.pth'
-    with open(str(ext_prefix.join(easy_install_location)), 'w') as F:
-        F.write("""path/to/ext1.egg
+    with open(str(ext_prefix.join(easy_install_location)), 'w') as f:
+        f.write("""path/to/ext1.egg
 path/to/setuptools.egg""")
 
     return str(python_prefix), str(ext_prefix)
@@ -204,8 +204,8 @@ def test_python_activation_with_files(tmpdir, python_and_extension_dirs):
     assert os.path.exists(os.path.join(python_prefix, 'bin/py-ext-tool'))
 
     easy_install_location = 'lib/python2.7/site-packages/easy-install.pth'
-    with open(os.path.join(python_prefix, easy_install_location), 'r') as F:
-        easy_install_contents = F.read()
+    with open(os.path.join(python_prefix, easy_install_location), 'r') as f:
+        easy_install_contents = f.read()
 
     assert 'ext1.egg' in easy_install_contents
     assert 'setuptools.egg' not in easy_install_contents
diff --git a/lib/spack/spack/util/file_cache.py b/lib/spack/spack/util/file_cache.py
index 56217e3a7cef030e3b0129a5cfe2987ef09e74d9..6dce9b9bdc9b50e1598aa9c6b188ef5c6cee15aa 100644
--- a/lib/spack/spack/util/file_cache.py
+++ b/lib/spack/spack/util/file_cache.py
@@ -130,7 +130,7 @@ def write_transaction(self, key):
         """
         class WriteContextManager(object):
 
-            def __enter__(cm):
+            def __enter__(cm):  # noqa
                 cm.orig_filename = self.cache_path(key)
                 cm.orig_file = None
                 if os.path.exists(cm.orig_filename):
@@ -141,7 +141,7 @@ def __enter__(cm):
 
                 return cm.orig_file, cm.tmp_file
 
-            def __exit__(cm, type, value, traceback):
+            def __exit__(cm, type, value, traceback):  # noqa
                 if cm.orig_file:
                     cm.orig_file.close()
                 cm.tmp_file.close()
diff --git a/lib/spack/spack/util/module_cmd.py b/lib/spack/spack/util/module_cmd.py
index 66a553f60c5644a0f1ca697fb542abd7d526ca8d..d8a9ce27d65302ec40550d428297ff2bcecf4c4c 100644
--- a/lib/spack/spack/util/module_cmd.py
+++ b/lib/spack/spack/util/module_cmd.py
@@ -194,9 +194,9 @@ def get_path_from_module(mod):
 
     # If it lists a -L instruction, use that
     for line in text:
-        L = line.find('-L/')
-        if L >= 0:
-            return line[L + 2:line.find('/lib')]
+        lib_paths = line.find('-L/')
+        if lib_paths >= 0:
+            return line[lib_paths + 2:line.find('/lib')]
 
     # If it sets the PATH, use it
     for line in text:
diff --git a/lib/spack/spack/util/package_hash.py b/lib/spack/spack/util/package_hash.py
index 21514745e37c64bb000c93d977cfac33389f86d4..904234baf3779a68bf703563d8c86ba8554b74ab 100644
--- a/lib/spack/spack/util/package_hash.py
+++ b/lib/spack/spack/util/package_hash.py
@@ -44,13 +44,13 @@ def remove_docstring(self, node):
         self.generic_visit(node)
         return node
 
-    def visit_FunctionDef(self, node):
+    def visit_FunctionDef(self, node):  # noqa
         return self.remove_docstring(node)
 
-    def visit_ClassDef(self, node):
+    def visit_ClassDef(self, node):  # noqa
         return self.remove_docstring(node)
 
-    def visit_Module(self, node):
+    def visit_Module(self, node):  # noqa
         return self.remove_docstring(node)
 
 
@@ -69,7 +69,7 @@ def is_spack_attr(self, node):
                 node.targets and isinstance(node.targets[0], ast.Name) and
                 node.targets[0].id in spack.package.Package.metadata_attrs)
 
-    def visit_ClassDef(self, node):
+    def visit_ClassDef(self, node):  # noqa
         if node.name == spack.util.naming.mod_to_class(self.spec.name):
             node.body = [
                 c for c in node.body
@@ -83,7 +83,7 @@ def __init__(self, spec):
         self.spec = spec
         self.methods = {}
 
-    def visit_FunctionDef(self, node):
+    def visit_FunctionDef(self, node):  # noqa
         nodes = self.methods.setdefault(node.name, [])
         if node.decorator_list:
             dec = node.decorator_list[0]
@@ -112,7 +112,7 @@ def resolve(self, node):
                 result = n
         return result
 
-    def visit_FunctionDef(self, node):
+    def visit_FunctionDef(self, node):  # noqa
         if self.resolve(node) is node:
             node.decorator_list = []
             return node
diff --git a/var/spack/repos/builtin/packages/bison/package.py b/var/spack/repos/builtin/packages/bison/package.py
index ac920b96aacd8c65685882a1cee17176759e3391..8a2d4a111bc85b5d70c03922d6d7461d773e5142 100644
--- a/var/spack/repos/builtin/packages/bison/package.py
+++ b/var/spack/repos/builtin/packages/bison/package.py
@@ -23,7 +23,7 @@
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 ##############################################################################
 from spack import *
-from spack.operating_systems.mac_os import macOS_version
+from spack.operating_systems.mac_os import macos_version
 import sys
 
 
@@ -42,7 +42,7 @@ class Bison(AutotoolsPackage):
 
     patch('pgi.patch', when='@3.0.4')
 
-    if sys.platform == 'darwin' and macOS_version() >= Version('10.13'):
+    if sys.platform == 'darwin' and macos_version() >= Version('10.13'):
         patch('secure_snprintf.patch', level=0, when='@3.0.4')
 
     build_directory = 'spack-build'
diff --git a/var/spack/repos/builtin/packages/gcc/package.py b/var/spack/repos/builtin/packages/gcc/package.py
index fb176edcff11ec88a541a46a446afe774b1afe0f..13f7e1abf8320e908537b383309a9aab35109fc0 100644
--- a/var/spack/repos/builtin/packages/gcc/package.py
+++ b/var/spack/repos/builtin/packages/gcc/package.py
@@ -23,7 +23,7 @@
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 ##############################################################################
 from spack import *
-from spack.operating_systems.mac_os import macOS_version
+from spack.operating_systems.mac_os import macos_version
 from llnl.util import tty
 
 import glob
@@ -157,7 +157,7 @@ class Gcc(AutotoolsPackage):
     if sys.platform == 'darwin':
         # Fix parallel build on APFS filesystem
         # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81797
-        if macOS_version() >= Version('10.13'):
+        if macos_version() >= Version('10.13'):
             patch('darwin/apfs.patch', when='@5.5.0,6.1:6.4,7.1:7.3')
             # from homebrew via macports
             # https://trac.macports.org/ticket/56502#no1
diff --git a/var/spack/repos/builtin/packages/oce/package.py b/var/spack/repos/builtin/packages/oce/package.py
index 45758d69241c97b1d1c74cbd1d71573764a8ca0d..6b7b3349bdcc286740d74dbbf80ab535c1f1371c 100644
--- a/var/spack/repos/builtin/packages/oce/package.py
+++ b/var/spack/repos/builtin/packages/oce/package.py
@@ -23,7 +23,7 @@
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 ##############################################################################
 from spack import *
-from spack.operating_systems.mac_os import macOS_version
+from spack.operating_systems.mac_os import macos_version
 import platform
 
 
@@ -68,7 +68,7 @@ class Oce(Package):
     # fix build with Xcode 8 "previous definition of CLOCK_REALTIME"
     # reported 27 Sep 2016 https://github.com/tpaviot/oce/issues/643
     if (platform.system() == "Darwin") and (
-       macOS_version() == Version('10.12')):
+       macos_version() == Version('10.12')):
         patch('sierra.patch', when='@0.17.2:0.18.0')
 
     def install(self, spec, prefix):
@@ -99,7 +99,7 @@ def install(self, spec, prefix):
             ])
 
         if platform.system() == 'Darwin' and (
-           macOS_version() >= Version('10.12')):
+           macos_version() >= Version('10.12')):
             # use @rpath on Sierra due to limit of dynamic loader
             options.append('-DCMAKE_MACOSX_RPATH=ON')
         else:
diff --git a/var/spack/repos/builtin/packages/trilinos/package.py b/var/spack/repos/builtin/packages/trilinos/package.py
index 78542260792bfc471f988008247ed317d5a97b0e..9cce2f028e0e7a0896bd10513c7f88da1ac614ec 100644
--- a/var/spack/repos/builtin/packages/trilinos/package.py
+++ b/var/spack/repos/builtin/packages/trilinos/package.py
@@ -25,7 +25,7 @@
 import os
 import sys
 from spack import *
-from spack.operating_systems.mac_os import macOS_version
+from spack.operating_systems.mac_os import macos_version
 
 # Trilinos is complicated to build, as an inspiration a couple of links to
 # other repositories which build it:
@@ -703,7 +703,7 @@ def cmake_args(self):
                 '-DTrilinos_ENABLE_FEI=OFF'
             ])
 
-        if sys.platform == 'darwin' and macOS_version() >= Version('10.12'):
+        if sys.platform == 'darwin' and macos_version() >= Version('10.12'):
             # use @rpath on Sierra due to limit of dynamic loader
             options.append('-DCMAKE_MACOSX_RPATH=ON')
         else: