#!/usr/bin/env python # Copyright 2016 Lars Wirzenius # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . # # =*= License: GPL-3+ =*= from distutils.core import setup, Extension from distutils.cmd import Command from distutils.command.build import build from distutils.command.clean import clean import glob import os import re import shutil import subprocess import sys import tempfile import cliapp import pgpwordlist class Check(Command): user_options = [ ('unit-tests', 'u', 'run unit tests?'), ('nitpick', 'n', 'check copyright statements, line lengths, etc'), ] def set_all_options(self, new_value): self.unit_tests = new_value self.nitpick = new_value def initialize_options(self): self.set_all_options(False) def finalize_options(self): any_set = ( self.unit_tests or self.nitpick) if not any_set: self.set_all_options(True) def run(self): if self.unit_tests: self.run_unit_tests() if self.nitpick: self.run_nitpick_checks() print "setup.py check done" def run_unit_tests(self): print "run unit tests" cliapp.runcmd(['python', '-m', 'CoverageTestRunner', '--ignore-missing-from=without-tests', 'pgpwordlist']) if os.path.exists('.coverage'): os.remove('.coverage') def run_nitpick_checks(self): self.check_with_pep8() self.check_with_pylint() if os.path.exists('.git'): sources = self.find_all_source_files() self.check_copyright_statements(sources) else: print "no .git, no nitpick for you" def check_with_pep8(self): output = cliapp.runcmd(['pep8', '--version']) parts = output.strip().split('.') # pep8 version 1.5.7 is in Debian jessie. Previous versions # give bad warnings about whitespace around some operators, # and later versions don't. So we only run pep8 if it's new # enough. if parts >= ['1', '5', '7']: print 'running pep8' cliapp.runcmd(['pep8', 'pgpwordlist'], stdout=None, stderr=None) else: print 'not running pep8' def check_with_pylint(self): output = cliapp.runcmd(['pylint', '--version']) parts = output.splitlines()[0].split('.') # pylint version 1.3.1 is in Debian jessie. Previous versions # do not know all the things in the pylint.conf file we use, # so we only run pylint if it's new enough. if parts >= ['pylint 1', '3', '1,']: print 'running pylint' cliapp.runcmd( ['pylint', '--rcfile=pylint.conf', 'pgpwordlist'], stdout=None, stderr=None) else: print 'not running pylint', parts def check_copyright_statements(self, sources): if self.copylint_is_available(): print 'check copyright statements in source files' cliapp.runcmd(['copyright-statement-lint'] + sources) else: print 'no copyright-statement-lint: no copyright checks' def copylint_is_available(self): returncode, stdout, stderr = cliapp.runcmd_unchecked( ['sh', '-c', 'command -v copyright-statement-lint']) return returncode == 0 def find_all_source_files(self): exclude = [ r'^debian/', r'^README\.', r'^NEWS$', r'^COPYING$', r'^pylint\.conf$', r'^without-tests$', r'^pgpwordlist/wordlist\.py$', r'^pgpwordlist/version\.py$', ] pats = [re.compile(x) for x in exclude] output = cliapp.runcmd(['git', 'ls-files']) result = [] for line in output.splitlines(): for pat in pats: if pat.search(line): break else: result.append(line) return result setup( name='py_pgpwordlist', version=pgpwordlist.__version__, description='Convert hex strings to words from PGP word list, and back', author='Lars Wirzenius', author_email='liw@liw.fi', url='http://liw.fi/py_pgpwordlist/', packages=[ 'pgpwordlist', ], cmdclass={ 'check': Check, }, )