mirror of
https://github.com/outbackdingo/patroni.git
synced 2026-08-25 14:53:37 +00:00
Don't rely on deprecated flake8 setuptools entrypoint (#1557)
Define and use own command class for that
This commit is contained in:
@@ -55,6 +55,55 @@ CONSOLE_SCRIPTS = ['patroni = patroni:main',
|
|||||||
"patroni_aws = patroni.scripts.aws:main"]
|
"patroni_aws = patroni.scripts.aws:main"]
|
||||||
|
|
||||||
|
|
||||||
|
class Flake8(Command):
|
||||||
|
|
||||||
|
user_options = []
|
||||||
|
|
||||||
|
def initialize_options(self):
|
||||||
|
from flake8.main import application
|
||||||
|
|
||||||
|
self.flake8 = application.Application()
|
||||||
|
self.flake8.initialize([])
|
||||||
|
|
||||||
|
def finalize_options(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def package_files(self):
|
||||||
|
seen_package_directories = ()
|
||||||
|
directories = self.distribution.package_dir or {}
|
||||||
|
empty_directory_exists = "" in directories
|
||||||
|
packages = self.distribution.packages or []
|
||||||
|
for package in packages:
|
||||||
|
if package in directories:
|
||||||
|
package_directory = directories[package]
|
||||||
|
elif empty_directory_exists:
|
||||||
|
package_directory = os.path.join(directories[""], package)
|
||||||
|
else:
|
||||||
|
package_directory = package
|
||||||
|
|
||||||
|
if not package_directory.startswith(seen_package_directories):
|
||||||
|
seen_package_directories += (package_directory + ".",)
|
||||||
|
yield package_directory
|
||||||
|
|
||||||
|
def targets(self):
|
||||||
|
return [package for package in self.package_files()] + ['tests', 'setup.py']
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
self.flake8.run_checks(self.targets())
|
||||||
|
self.flake8.formatter.start()
|
||||||
|
self.flake8.report_errors()
|
||||||
|
self.flake8.report_statistics()
|
||||||
|
self.flake8.report_benchmarks()
|
||||||
|
self.flake8.formatter.stop()
|
||||||
|
try:
|
||||||
|
self.flake8.exit()
|
||||||
|
except SystemExit as e:
|
||||||
|
# Cause system exit only if exit code is not zero (terminates
|
||||||
|
# other possibly remaining/pending setuptools commands).
|
||||||
|
if e.code:
|
||||||
|
raise
|
||||||
|
|
||||||
|
|
||||||
class PyTest(Command):
|
class PyTest(Command):
|
||||||
|
|
||||||
user_options = [('cov=', None, 'Run coverage'), ('cov-xml=', None, 'Generate junit xml report'),
|
user_options = [('cov=', None, 'Run coverage'), ('cov-xml=', None, 'Generate junit xml report'),
|
||||||
@@ -106,7 +155,7 @@ def read(fname):
|
|||||||
|
|
||||||
def setup_package(version):
|
def setup_package(version):
|
||||||
# Assemble additional setup commands
|
# Assemble additional setup commands
|
||||||
cmdclass = {'test': PyTest}
|
cmdclass = {'test': PyTest, 'flake8': Flake8}
|
||||||
|
|
||||||
install_requires = []
|
install_requires = []
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user