Skip to content

Commit

Permalink
Merge pull request SciTools#1515 from QuLogic/setup-header
Browse files Browse the repository at this point in the history
Remove unused HeaderCheck from setup.py.
  • Loading branch information
greglucas authored Apr 11, 2020
2 parents ccf4c3b + 20f500a commit 700bd14
Showing 1 changed file with 0 additions and 62 deletions.
62 changes: 0 additions & 62 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,68 +90,6 @@ def find_package_tree(root_path, root_package):
return packages


class MissingHeaderError(Exception):
"""
Raised when one or more files do not have the required copyright
and licence header.
"""
pass


class HeaderCheck(Command):
"""
Checks that all the necessary files have the copyright and licence
header.
"""

description = "check for copyright/licence headers"
user_options = []

exclude_patterns = ('./setup.py',
'./build/*',
'./docs/build/*',
'./dist/*',
'./lib/cartopy/examples/*.py')

def initialize_options(self):
pass

def finalize_options(self):
pass

def run(self):
check_paths = []
for root, dirs, files in os.walk('.'):
for file in files:
if file.endswith('.py') or file.endswith('.c'):
path = os.path.join(root, file)
check_paths.append(path)

for pattern in self.exclude_patterns:
exclude = lambda path: not fnmatch.fnmatch(path, pattern)
check_paths = list(filter(exclude, check_paths))

bad_paths = list(filter(self._header_bad, check_paths))
if bad_paths:
raise MissingHeaderError(bad_paths)

def _header_bad(self, path):
target = '(C) British Crown Copyright 2011 - 2012, Met Office'
with open(path, 'rt') as text_file:
# Check for the header on the first line.
line = text_file.readline().rstrip()
bad = target not in line

# Check if it was an executable script, with the header
# starting on the second line.
if bad and line == '#!/usr/bin/env python':
line = text_file.readline().rstrip()
bad = target not in line
return bad


# Dependency checks
# =================

Expand Down

0 comments on commit 700bd14

Please sign in to comment.