diff --git a/.flake8 b/.flake8 new file mode 100644 index 0000000000..2bcd70e390 --- /dev/null +++ b/.flake8 @@ -0,0 +1,2 @@ +[flake8] +max-line-length = 88 diff --git a/CMakeLists.txt b/CMakeLists.txt index 9b46433114..b079e5c4bb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -516,6 +516,7 @@ if(NOT BUSTED_OUTPUT_TYPE) endif() find_program(LUACHECK_PRG luacheck) +find_program(FLAKE8_PRG flake8) find_program(GPERF_PRG gperf) include(InstallHelpers) @@ -667,6 +668,15 @@ else() COMMENT "lualint: LUACHECK_PRG not defined") endif() +if(FLAKE8_PRG) + add_custom_target(pylint + COMMAND ${FLAKE8_PRG} contrib/ scripts/ src/ test/ + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) +else() + add_custom_target(pylint false + COMMENT "flake8: FLAKE8_PRG not defined") +endif() + set(CPACK_PACKAGE_NAME "Neovim") set(CPACK_PACKAGE_VENDOR "neovim.io") set(CPACK_PACKAGE_VERSION ${NVIM_VERSION_MEDIUM}) diff --git a/Makefile b/Makefile index 6d8f6cb07d..9fe458cf9d 100644 --- a/Makefile +++ b/Makefile @@ -138,6 +138,9 @@ functionaltest-lua: | nvim lualint: | build/.ran-cmake deps $(BUILD_CMD) -C build lualint +pylint: | build/.ran-cmake deps + $(BUILD_CMD) -C build pylint + unittest: | nvim +$(BUILD_CMD) -C build unittest @@ -179,6 +182,6 @@ appimage: appimage-%: bash scripts/genappimage.sh $* -lint: check-single-includes clint lualint +lint: check-single-includes clint lualint pylint -.PHONY: test lualint functionaltest unittest lint clint clean distclean nvim libnvim cmake deps install appimage checkprefix +.PHONY: test lualint pylint functionaltest unittest lint clint clean distclean nvim libnvim cmake deps install appimage checkprefix diff --git a/ci/install.sh b/ci/install.sh index afe55bbff5..134eb7968d 100755 --- a/ci/install.sh +++ b/ci/install.sh @@ -4,6 +4,7 @@ set -e set -o pipefail if [[ "${CI_TARGET}" == lint ]]; then + python -m pip -q install --user --upgrade flake8 exit fi diff --git a/ci/run_lint.sh b/ci/run_lint.sh index 54e76e10da..88af163e80 100755 --- a/ci/run_lint.sh +++ b/ci/run_lint.sh @@ -9,26 +9,24 @@ source "${CI_DIR}/common/build.sh" source "${CI_DIR}/common/suite.sh" enter_suite 'clint' - run_test 'make clint-full' clint - exit_suite --continue enter_suite 'lualint' - run_test 'make lualint' lualint +exit_suite --continue +enter_suite 'pylint' +run_test 'make pylint' pylint exit_suite --continue enter_suite single-includes - CLICOLOR_FORCE=1 run_test_wd \ --allow-hang \ 10s \ 'make check-single-includes' \ 'csi_clean' \ single-includes - exit_suite --continue end_tests diff --git a/contrib/gdb/nvim-gdb-pretty-printers.py b/contrib/gdb/nvim-gdb-pretty-printers.py index 609ceeb7ab..a6a3d90ce4 100644 --- a/contrib/gdb/nvim-gdb-pretty-printers.py +++ b/contrib/gdb/nvim-gdb-pretty-printers.py @@ -26,13 +26,13 @@ def get_color_code(bg, color_num): prefix += 1 color_num %= 8 else: - prefix = '48;5;' if bg else '38;5;' + prefix = '48;5;' if bg else '38;5;' return '\x1b[{0}{1}m'.format(prefix, color_num) def highlight(attrs): fg, bg = [int(attrs['foreground']), int(attrs['background'])] - rv = [SGR0] # start with sgr0 + rv = [SGR0] # start with sgr0 if fg != -1: rv.append(get_color_code(False, fg)) if bg != -1: diff --git a/scripts/check-includes.py b/scripts/check-includes.py index 21308a21aa..ed1fe407c5 100755 --- a/scripts/check-includes.py +++ b/scripts/check-includes.py @@ -9,58 +9,56 @@ from argparse import ArgumentParser GENERATED_INCLUDE_RE = re.compile( - r'^\s*#\s*include\s*"([/a-z_0-9.]+\.generated\.h)"(\s+//.*)?$') + r'^\s*#\s*include\s*"([/a-z_0-9.]+\.generated\.h)"(\s+//.*)?$') def main(argv): - argparser = ArgumentParser() - argparser.add_argument('--generated-includes-dir', action='append', - help='Directory where generated includes are located.') - argparser.add_argument('--file', type=open, help='File to check.') - argparser.add_argument('iwyu_args', nargs='*', - help='IWYU arguments, must go after --.') - args = argparser.parse_args(argv) + argparser = ArgumentParser() + argparser.add_argument('--generated-includes-dir', action='append', + help='Directory where generated includes are located.') + argparser.add_argument('--file', type=open, help='File to check.') + argparser.add_argument('iwyu_args', nargs='*', + help='IWYU arguments, must go after --.') + args = argparser.parse_args(argv) - with args.file: - include_dirs = [] + with args.file: + iwyu = Popen(['include-what-you-use', '-xc'] + args.iwyu_args + ['/dev/stdin'], + stdin=PIPE, stdout=PIPE, stderr=PIPE) - iwyu = Popen(['include-what-you-use', '-xc'] + args.iwyu_args + ['/dev/stdin'], - stdin=PIPE, stdout=PIPE, stderr=PIPE) + for line in args.file: + match = GENERATED_INCLUDE_RE.match(line) + if match: + for d in args.generated_includes_dir: + try: + f = open(os.path.join(d, match.group(1))) + except IOError: + continue + else: + with f: + for generated_line in f: + iwyu.stdin.write(generated_line) + break + else: + raise IOError('Failed to find {0}'.format(match.group(1))) + else: + iwyu.stdin.write(line) - for line in args.file: - match = GENERATED_INCLUDE_RE.match(line) - if match: - for d in args.generated_includes_dir: - try: - f = open(os.path.join(d, match.group(1))) - except IOError: - continue - else: - with f: - for generated_line in f: - iwyu.stdin.write(generated_line) - break - else: - raise IOError('Failed to find {0}'.format(match.group(1))) - else: - iwyu.stdin.write(line) + iwyu.stdin.close() - iwyu.stdin.close() + out = iwyu.stdout.read() + err = iwyu.stderr.read() - out = iwyu.stdout.read() - err = iwyu.stderr.read() + ret = iwyu.wait() - ret = iwyu.wait() - - if ret != 2: - print('IWYU failed with exit code {0}:'.format(ret)) - print('{0} stdout {0}'.format('=' * ((80 - len(' stdout ')) // 2))) - print(out) - print('{0} stderr {0}'.format('=' * ((80 - len(' stderr ')) // 2))) - print(err) - return 1 - return 0 + if ret != 2: + print('IWYU failed with exit code {0}:'.format(ret)) + print('{0} stdout {0}'.format('=' * ((80 - len(' stdout ')) // 2))) + print(out) + print('{0} stderr {0}'.format('=' * ((80 - len(' stderr ')) // 2))) + print(err) + return 1 + return 0 if __name__ == '__main__': - raise SystemExit(main(sys.argv[1:])) + raise SystemExit(main(sys.argv[1:])) diff --git a/scripts/gen_help_html.py b/scripts/gen_help_html.py index dbdeb3c162..0b8e77ac22 100644 --- a/scripts/gen_help_html.py +++ b/scripts/gen_help_html.py @@ -81,12 +81,12 @@ SITENAVI_PLAIN = '
' + SITENAVI_LINKS_PLAIN + '
' SITENAVI_WEB = '' + SITENAVI_LINKS_WEB + '
' SITENAVI_SEARCH = '' + SITENAVI_LINKS_WEB + \ -' | ' \
-' |
+
""" + (" " * 80) + """
""" @@ -100,74 +100,76 @@ FOOTER2 = """