mirror of
https://github.com/PyCQA/flake8.git
synced 2026-04-10 06:44:18 +00:00
Take into account that setuptools is no longer optional
This commit is contained in:
parent
be9f2a5ffb
commit
1496579fb2
1 changed files with 21 additions and 24 deletions
|
|
@ -2,6 +2,8 @@
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
import setuptools
|
||||||
|
|
||||||
from flake8.engine import get_style_guide
|
from flake8.engine import get_style_guide
|
||||||
|
|
||||||
if sys.platform.startswith('win'):
|
if sys.platform.startswith('win'):
|
||||||
|
|
@ -53,32 +55,27 @@ def check_code(code, ignore=(), complexity=-1, reporter=None):
|
||||||
return flake8_style.input_file('-', lines=code.split('\n'))
|
return flake8_style.input_file('-', lines=code.split('\n'))
|
||||||
|
|
||||||
|
|
||||||
try:
|
class Flake8Command(setuptools.Command):
|
||||||
from setuptools import Command
|
description = "Run flake8 on modules registered in setuptools"
|
||||||
except ImportError:
|
user_options = []
|
||||||
Flake8Command = None
|
|
||||||
else:
|
|
||||||
class Flake8Command(Command):
|
|
||||||
description = "Run flake8 on modules registered in setuptools"
|
|
||||||
user_options = []
|
|
||||||
|
|
||||||
def initialize_options(self):
|
def initialize_options(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def finalize_options(self):
|
def finalize_options(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def distribution_files(self):
|
def distribution_files(self):
|
||||||
if self.distribution.packages:
|
if self.distribution.packages:
|
||||||
for package in self.distribution.packages:
|
for package in self.distribution.packages:
|
||||||
yield package.replace(".", os.path.sep)
|
yield package.replace(".", os.path.sep)
|
||||||
|
|
||||||
if self.distribution.py_modules:
|
if self.distribution.py_modules:
|
||||||
for filename in self.distribution.py_modules:
|
for filename in self.distribution.py_modules:
|
||||||
yield "%s.py" % filename
|
yield "%s.py" % filename
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
flake8_style = get_style_guide(config_file=DEFAULT_CONFIG)
|
flake8_style = get_style_guide(config_file=DEFAULT_CONFIG)
|
||||||
paths = self.distribution_files()
|
paths = self.distribution_files()
|
||||||
report = flake8_style.check_files(paths)
|
report = flake8_style.check_files(paths)
|
||||||
raise SystemExit(report.total_errors > 0)
|
raise SystemExit(report.total_errors > 0)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue