def test_flake8(self): """ Test codebase for compliance with the flake8 tool. """ if not HAS_FLAKE8: raise Exception('flake8 is required to check code formatting') import flake8.main test_dir = os.path.abspath(inspect.getfile(inspect.currentframe())) obspy_dir = os.path.dirname(os.path.dirname(os.path.dirname(test_dir))) error_count = 0 file_count = 0 untracked_files = get_untracked_files_from_git() or [] for dirpath, _, filenames in os.walk(obspy_dir): filenames = [_i for _i in filenames if os.path.splitext(_i)[-1] == os.path.extsep + "py"] if not filenames: continue for py_file in filenames: py_file = os.path.join(dirpath, py_file) # ignore untracked files if os.path.abspath(py_file) in untracked_files: continue # Check files that do not match any exclusion pattern for exclude_pattern in EXCLUDE_FILES: if fnmatch.fnmatch(py_file, exclude_pattern): break else: file_count += 1 if flake8.main.check_file(py_file): error_count += 1 self.assertTrue(file_count > 10) self.assertEqual(error_count, 0)
def test_flake8(self): """ Test codebase for compliance with the flake8 tool. """ # Import the legacy API as flake8 3.0 currently has not official # public API - this has to be changed at some point. from flake8.api import legacy as flake8 # not sure if there's a better way to get a hold of default ignore # codes.. default_ignore_codes = \ flake8.get_style_guide().options.__dict__['ignore'] ignore_codes = list(set(default_ignore_codes + FLAKE8_IGNORE_CODES)) style_guide = flake8.get_style_guide(ignore=ignore_codes) untracked_files = get_untracked_files_from_git() or [] files = [] for filename in get_all_py_files(): if filename in untracked_files: continue for pattern in FLAKE8_EXCLUDE_FILES: if fnmatch.fnmatch(filename, pattern): break else: files.append(filename) report = style_guide.check_files(files) # Make sure no error occured. assert report.total_errors == 0
def check_flake8(): if not HAS_FLAKE8: raise Exception('flake8 is required to check code formatting') import flake8.main from flake8.engine import get_style_guide test_dir = os.path.abspath(inspect.getfile(inspect.currentframe())) obspy_dir = os.path.dirname(os.path.dirname(os.path.dirname(test_dir))) untracked_files = get_untracked_files_from_git() or [] files = [] for dirpath, _, filenames in os.walk(obspy_dir): filenames = [_i for _i in filenames if os.path.splitext(_i)[-1] == os.path.extsep + "py"] if not filenames: continue for py_file in filenames: py_file = os.path.join(dirpath, py_file) # ignore untracked files if os.path.abspath(py_file) in untracked_files: continue # Check files that do not match any exclusion pattern for exclude_pattern in FLAKE8_EXCLUDE_FILES: if fnmatch.fnmatch(py_file, exclude_pattern): break else: files.append(py_file) flake8_style = get_style_guide(parse_argv=False, config_file=flake8.main.DEFAULT_CONFIG) sys.stdout = StringIO.StringIO() report = flake8_style.check_files(files) sys.stdout.seek(0) message = sys.stdout.read() sys.stdout = sys.__stdout__ return report, message
def test_flake8(self): """ Test codebase for compliance with the flake8 tool. """ # Import the legacy API as flake8 3.0 currently has not official # public API - this has to be changed at some point. from flake8.api import legacy as flake8 # not sure if there's a better way to get a hold of default ignore # codes.. default_ignore_codes = \ flake8.get_style_guide().options.__dict__['ignore'] ignore_codes = list(set(default_ignore_codes + FLAKE8_IGNORE_CODES)) style_guide = flake8.get_style_guide(ignore=ignore_codes) untracked_files = get_untracked_files_from_git() or [] files = [] for filename in get_all_py_files(): if filename in untracked_files: continue for pattern in FLAKE8_EXCLUDE_FILES: if fnmatch.fnmatch(filename, pattern): break else: files.append(filename) report = style_guide.check_files(files) # Make sure no error occurred. assert report.total_errors == 0
def check_flake8(): if not HAS_FLAKE8: raise Exception('flake8 is required to check code formatting') # pyflakes autodetection of PY2 does not work with the future library. # Therefore, overwrite the pyflakes autodetection manually if PY2: import pyflakes.checker # @UnusedImport pyflakes.checker.PY2 = True test_dir = os.path.abspath(inspect.getfile(inspect.currentframe())) obspy_dir = os.path.dirname(os.path.dirname(os.path.dirname(test_dir))) untracked_files = get_untracked_files_from_git() or [] files = [] for dirpath, _, filenames in os.walk(obspy_dir): filenames = [ _i for _i in filenames if os.path.splitext(_i)[-1] == os.path.extsep + "py" ] if not filenames: continue for py_file in filenames: py_file = os.path.join(dirpath, py_file) # ignore untracked files if os.path.abspath(py_file) in untracked_files: continue # exclude *.py files in obspy/lib try: tmp_dir, _ = os.path.split(py_file) _, tmp_dir = os.path.split(tmp_dir) if tmp_dir == "lib": continue except: pass # Check files that do not match any exclusion pattern for exclude_pattern in FLAKE8_EXCLUDE_FILES: if fnmatch.fnmatch(py_file, exclude_pattern): break else: files.append(py_file) if flake8_version >= LooseVersion('3.0.0'): from flake8.api.legacy import get_style_guide else: from flake8.engine import get_style_guide flake8_kwargs = {'parse_argv': False} if flake8_version < LooseVersion('2.5.5'): import flake8.main flake8_kwargs['config_file'] = flake8.main.DEFAULT_CONFIG flake8_style = get_style_guide(**flake8_kwargs) flake8_style.options.ignore = tuple( set(flake8_style.options.ignore).union(set(FLAKE8_IGNORE_CODES))) with CatchOutput() as out: files = [native_str(f) for f in files] report = flake8_style.check_files(files) return report, out.stdout
def test_flake8(self): """ Test codebase for compliance with the flake8 tool. """ # Import the legacy API as flake8 3.0 currently has not official # public API - this has to be changed at some point. from flake8.api import legacy as flake8 # --hang-closing allows valid indented closing brackets, see # https://github.com/PyCQA/pycodestyle/issues/103#issuecomment-17366719 style_guide = flake8.get_style_guide( ignore=FLAKE8_IGNORE_CODES, hang_closing=True) untracked_files = get_untracked_files_from_git() or [] files = [] for filename in get_all_py_files(): if filename in untracked_files: continue for pattern in FLAKE8_EXCLUDE_FILES: if fnmatch.fnmatch(filename, pattern): break else: files.append(filename) report = style_guide.check_files(files) # Make sure no error occurred. assert report.total_errors == 0
def check_flake8(): if not HAS_FLAKE8: raise Exception('flake8 is required to check code formatting') # pyflakes autodetection of PY2 does not work with the future library. # Therefore, overwrite the pyflakes autodetection manually if PY2: import pyflakes.checker # @UnusedImport pyflakes.checker.PY2 = True test_dir = os.path.abspath(inspect.getfile(inspect.currentframe())) obspy_dir = os.path.dirname(os.path.dirname(os.path.dirname(test_dir))) untracked_files = get_untracked_files_from_git() or [] files = [] for dirpath, _, filenames in os.walk(obspy_dir): filenames = [_i for _i in filenames if os.path.splitext(_i)[-1] == os.path.extsep + "py"] if not filenames: continue for py_file in filenames: py_file = os.path.join(dirpath, py_file) # ignore untracked files if os.path.abspath(py_file) in untracked_files: continue # exclude *.py files in obspy/lib try: tmp_dir, _ = os.path.split(py_file) _, tmp_dir = os.path.split(tmp_dir) if tmp_dir == "lib": continue except: pass # Check files that do not match any exclusion pattern for exclude_pattern in FLAKE8_EXCLUDE_FILES: if fnmatch.fnmatch(py_file, exclude_pattern): break else: files.append(py_file) if flake8_version >= LooseVersion('3.0.0'): from flake8.api.legacy import get_style_guide else: from flake8.engine import get_style_guide flake8_kwargs = {'parse_argv': False} if flake8_version < LooseVersion('2.5.5'): import flake8.main flake8_kwargs['config_file'] = flake8.main.DEFAULT_CONFIG flake8_style = get_style_guide(**flake8_kwargs) flake8_style.options.ignore = tuple(set( flake8_style.options.ignore).union(set(FLAKE8_IGNORE_CODES))) with CatchOutput() as out: files = [native_str(f) for f in files] report = flake8_style.check_files(files) return report, out.stdout
def check_flake8(): if not HAS_FLAKE8: raise Exception('flake8 is required to check code formatting') # pyflakes autodetection of PY2 does not work with the future library. # Therefore, overwrite the pyflakes autodetection manually if PY2: import pyflakes.checker pyflakes.checker.PY2 = True import flake8.main from flake8.engine import get_style_guide test_dir = os.path.abspath(inspect.getfile(inspect.currentframe())) obspy_dir = os.path.dirname(os.path.dirname(os.path.dirname(test_dir))) untracked_files = get_untracked_files_from_git() or [] files = [] for dirpath, _, filenames in os.walk(obspy_dir): filenames = [_i for _i in filenames if os.path.splitext(_i)[-1] == os.path.extsep + "py"] if not filenames: continue for py_file in filenames: py_file = os.path.join(dirpath, py_file) # ignore untracked files if os.path.abspath(py_file) in untracked_files: continue # exclude *.py files in obspy/lib try: tmp_dir, _ = os.path.split(py_file) _, tmp_dir = os.path.split(tmp_dir) if tmp_dir == "lib": continue except: pass # Check files that do not match any exclusion pattern for exclude_pattern in FLAKE8_EXCLUDE_FILES: if fnmatch.fnmatch(py_file, exclude_pattern): break else: files.append(py_file) flake8_style = get_style_guide(parse_argv=False, config_file=flake8.main.DEFAULT_CONFIG) flake8_style.options.ignore = \ tuple(set(flake8_style.options.ignore + tuple(FLAKE8_IGNORE_CODES))) sys.stdout = compatibility.StringIO() if PY2: files = [native_str(f) for f in files] report = flake8_style.check_files(files) sys.stdout.seek(0) message = sys.stdout.read() sys.stdout = sys.__stdout__ return report, message
def check_flake8(): if not HAS_FLAKE8: raise Exception('flake8 is required to check code formatting') import flake8.main from flake8.engine import get_style_guide test_dir = os.path.abspath(inspect.getfile(inspect.currentframe())) obspy_dir = os.path.dirname(os.path.dirname(os.path.dirname(test_dir))) untracked_files = get_untracked_files_from_git() or [] files = [] for dirpath, _, filenames in os.walk(obspy_dir): filenames = [ _i for _i in filenames if os.path.splitext(_i)[-1] == os.path.extsep + "py" ] if not filenames: continue for py_file in filenames: py_file = os.path.join(dirpath, py_file) # ignore untracked files if os.path.abspath(py_file) in untracked_files: continue # exclude *.py files in obspy/lib try: tmp_dir, _ = os.path.split(py_file) _, tmp_dir = os.path.split(tmp_dir) if tmp_dir == "lib": continue except: pass # Check files that do not match any exclusion pattern for exclude_pattern in FLAKE8_EXCLUDE_FILES: if fnmatch.fnmatch(py_file, exclude_pattern): break else: files.append(py_file) flake8_style = get_style_guide(parse_argv=False, config_file=flake8.main.DEFAULT_CONFIG) sys.stdout = compatibility.StringIO() if PY2: files = [native_str(f) for f in files] report = flake8_style.check_files(files) sys.stdout.seek(0) message = sys.stdout.read() sys.stdout = sys.__stdout__ return report, message
def test_flake8(self): """ Test codebase for compliance with the flake8 tool. """ # Import the legacy API as flake8 3.0 currently has not official # public API - this has to be changed at some point. from flake8.api import legacy as flake8 style_guide = flake8.get_style_guide(ignore=FLAKE8_IGNORE_CODES) untracked_files = get_untracked_files_from_git() or [] files = [] for filename in get_all_py_files(): if filename in untracked_files: continue for pattern in FLAKE8_EXCLUDE_FILES: if fnmatch.fnmatch(filename, pattern): break else: files.append(filename) report = style_guide.check_files(files) # Make sure no error occured. assert report.total_errors == 0
def test_flake8(self): """ Test codebase for compliance with the flake8 tool. """ # Import the legacy API as flake8 3.0 currently has not official # public API - this has to be changed at some point. from flake8.api import legacy as flake8 # not sure if there's a better way to get a hold of default ignore # codes.. default_ignore_codes = \ flake8.get_style_guide().options.__dict__['ignore'] try: import pycodestyle except ImportError: pass else: default_ignore_codes += pycodestyle.DEFAULT_IGNORE.split(',') ignore_codes = list(set(default_ignore_codes + FLAKE8_IGNORE_CODES)) # --hang-closing allows valid indented closing brackets, see # https://github.com/PyCQA/pycodestyle/issues/103#issuecomment-17366719 style_guide = flake8.get_style_guide( ignore=ignore_codes, hang_closing=True) untracked_files = get_untracked_files_from_git() or [] files = [] for filename in get_all_py_files(): if filename in untracked_files: continue for pattern in FLAKE8_EXCLUDE_FILES: if fnmatch.fnmatch(filename, pattern): break else: files.append(filename) report = style_guide.check_files(files) # Make sure no error occurred. assert report.total_errors == 0