Tidy up setup.py (#1308)

1. Stop using `setuptools.command.test`, it is being deprecated
2. Remove junit integration
This commit is contained in:
Alexander Kukushkin
2019-11-27 15:56:50 +01:00
committed by GitHub
parent 85341ff78b
commit a3be2958a7
+21 -27
View File
@@ -10,8 +10,7 @@ import sys
from patroni import check_psycopg2, fatal
from patroni.version import __version__ as VERSION
from setuptools.command.test import test as TestCommand
from setuptools import find_packages, setup
from setuptools import Command, find_packages, setup
if sys.version_info < (2, 7, 0):
fatal('patroni needs to be run with Python 2.7+')
@@ -23,7 +22,6 @@ __location__ = os.path.join(os.getcwd(), os.path.dirname(inspect.getfile(inspect
NAME = 'patroni'
MAIN_PACKAGE = NAME
SCRIPTS = 'scripts'
DESCRIPTION = 'PostgreSQL High-Available orchestrator and CLI'
LICENSE = 'The MIT License'
URL = 'https://github.com/zalando/patroni'
@@ -34,7 +32,6 @@ KEYWORDS = 'etcd governor patroni postgresql postgres ha haproxy confd' +\
COVERAGE_XML = True
COVERAGE_HTML = False
JUNIT_XML = False
# Add here all kinds of additional classifiers as defined under
# https://pypi.python.org/pypi?%3Aaction=list_classifiers
@@ -64,49 +61,49 @@ CONSOLE_SCRIPTS = ['patroni = patroni:main',
"patroni_aws = patroni.scripts.aws:main"]
class PyTest(TestCommand):
class PyTest(Command):
user_options = [('cov=', None, 'Run coverage'), ('cov-xml=', None, 'Generate junit xml report'), ('cov-html=',
None, 'Generate junit html report'), ('junitxml=', None, 'Generate xml of test results')]
user_options = [('cov=', None, 'Run coverage'), ('cov-xml=', None, 'Generate junit xml report'),
('cov-html=', None, 'Generate junit html report')]
def initialize_options(self):
TestCommand.initialize_options(self)
self.cov = []
self.cov_xml = False
self.cov_html = False
self.junitxml = None
def finalize_options(self):
TestCommand.finalize_options(self)
if self.cov_xml or self.cov_html:
self.cov = ['--cov', MAIN_PACKAGE, '--cov-report', 'term-missing']
if self.cov_xml:
self.cov.extend(['--cov-report', 'xml'])
if self.cov_html:
self.cov.extend(['--cov-report', 'html'])
if self.junitxml is not None:
self.junitxml = ['--junitxml', self.junitxml]
def run_tests(self):
try:
import pytest
except Exception:
raise RuntimeError('py.test is not installed, run: pip install pytest')
params = {'args': self.test_args}
if self.cov:
params['args'] += self.cov
if self.junitxml:
params['args'] += self.junitxml
params['args'] += ['--doctest-modules', MAIN_PACKAGE, '-vv']
import logging
silence = logging.WARNING
logging.basicConfig(format='%(asctime)s %(levelname)s: %(message)s', level=os.getenv('LOGLEVEL', silence))
params['args'] += ['-s' if logging.getLogger().getEffectiveLevel() < silence else '--capture=fd']
if not os.getenv('SYSTEMROOT'):
os.environ['SYSTEMROOT'] = '/'
errno = pytest.main(**params)
args = ['--verbose', 'tests', '--doctest-modules', MAIN_PACKAGE] +\
['-s' if logging.getLogger().getEffectiveLevel() < silence else '--capture=fd']
if self.cov:
args += self.cov
errno = pytest.main(args=args)
sys.exit(errno)
def run(self):
from pkg_resources import evaluate_marker
requirements = self.distribution.install_requires + ['flake8', 'mock>=2.0.0', 'pytest-cov', 'pytest'] +\
[v for k, v in self.distribution.extras_require.items() if not k.startswith(':') or evaluate_marker(k[1:])]
self.distribution.fetch_build_eggs(requirements)
self.run_tests()
def read(fname):
with open(os.path.join(__location__, fname)) as fd:
@@ -133,9 +130,7 @@ def setup_package():
if not extra:
install_requires.append(r)
command_options = {'test': {'test_suite': ('setup.py', 'tests')}}
if JUNIT_XML:
command_options['test']['junitxml'] = 'setup.py', 'junit.xml'
command_options = {'test': {}}
if COVERAGE_XML:
command_options['test']['cov_xml'] = 'setup.py', True
if COVERAGE_HTML:
@@ -152,13 +147,12 @@ def setup_package():
keywords=KEYWORDS,
long_description=read('README.rst'),
classifiers=CLASSIFIERS,
test_suite='tests',
packages=find_packages(exclude=['tests', 'tests.*']),
package_data={MAIN_PACKAGE: ["*.json"]},
python_requires='>=2.7',
install_requires=install_requires,
extras_require=extras_require,
cmdclass=cmdclass,
tests_require=['flake8', 'mock>=2.0.0', 'pytest-cov', 'pytest'],
command_options=command_options,
entry_points={'console_scripts': CONSOLE_SCRIPTS},
)