pax_global_header00006660000000000000000000000064140512142250014506gustar00rootroot0000000000000052 comment=3df8606ad821100e64743f457c77c20170bde722 pyls-flake8-0.4.0/000077500000000000000000000000001405121422500136465ustar00rootroot00000000000000pyls-flake8-0.4.0/.gitignore000066400000000000000000000000501405121422500156310ustar00rootroot00000000000000*.egg-info *.pyc build dist .spyproject pyls-flake8-0.4.0/LICENSE000066400000000000000000000020551405121422500146550ustar00rootroot00000000000000MIT License Copyright (c) 2018 Randy Eckman Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. pyls-flake8-0.4.0/Makefile000066400000000000000000000007231405121422500153100ustar00rootroot00000000000000.PHONY: clean help dist upload help: @echo " clean remove unwanted stuff" @echo " dist creates distribution packages (bdist_wheel, sdist)" @echo " upload uploads a new version to PyPI" clean: find . -name '*.pyc' -exec rm -f {} + find . -name '*.pyo' -exec rm -f {} + find . -name '*~' -exec rm -f {} + find . -name '__pycache__' -exec rm -rf {} + dist: python setup.py sdist bdist_wheel upload:dist twine upload --skip-existing dist/* pyls-flake8-0.4.0/README.md000066400000000000000000000005141405121422500151250ustar00rootroot00000000000000# pyls-flake8 A Flake8 plugin for the [Python LSP Server](https://github.com/python-lsp/python-lsp-server). Install this plugin in the same environment as `python-lsp-server`: ```shell pip install pyls-flake8 ``` pyls-flake8 will read its config from your project's ``setup.cfg``, ``tox.ini`` or ``.flake8`` file if it has one. pyls-flake8-0.4.0/pyls_flake8/000077500000000000000000000000001405121422500160675ustar00rootroot00000000000000pyls-flake8-0.4.0/pyls_flake8/__init__.py000066400000000000000000000000001405121422500201660ustar00rootroot00000000000000pyls-flake8-0.4.0/pyls_flake8/plugin.py000066400000000000000000000115051405121422500177410ustar00rootroot00000000000000import re from pylsp import hookimpl, lsp # default ignored by Flake8 package: # E121, continuation line under-indented for hanging indent # E123, closing bracket does not match indentation of opening bracket’s line # E126, continuation line over-indented for hanging indent # E226, missing whitespace around arithmetic operator # E241, multiple spaces after ‘,’ # E242, tab after ‘,’ # E704, multiple statements on one line (def) result_re = re.compile(r"stdin:(\d*):(\d*): (\w*) (.*)") # default flake messages to error except these flake_warnings = ( "F401", # module imported but unused "F402", # import module from line N shadowed by # loop variable "F403", # ‘from module import *’ used; # unable to detect undefined names "F404", # future import(s) name after other statements "F405", # name may be undefined, or defined from # star imports: module "F602", # dictionary key variable name repeated with # different values "F841", # local variable name is assigned to but never used ) # default code style messages to warnings except these style_errors = ( "E112", # expected an indented block "E113", # unexpected indentation "E741", # do not use variables named ‘l’, ‘O’, or ‘I’ "E742", # do not define classes named ‘l’, ‘O’, or ‘I’ "E743", # do not define functions named ‘l’, ‘O’, or ‘I’ "E901", # SyntaxError or IndentationError "E902", # IOError "E999", # invalid syntax ) severity_enum = lsp.DiagnosticSeverity warning = severity_enum.Warning error = severity_enum.Error def results_to_diagnostic(results: str, document): diaglist = list() for line in results.splitlines(): if line: linestr, col, code, msg = result_re.match(line).groups() lineno = int(linestr) - 1 offset = int(col) - 1 if ( code[0] == "F" and code not in flake_warnings ) or code in style_errors: severity = error else: severity = warning start_mark = {"line": lineno, "character": offset} end_mark = {"line": lineno, "character": offset + 1} if document: word = document.word_at_position(start_mark) if word: end_mark["character"] = start_mark["character"] + len(word) diag = { "source": "flake8", "range": {"start": start_mark, "end": end_mark}, "code": code, "message": msg, "severity": severity, } diaglist.append(diag) return diaglist def return_error(stderr: str): return [ { "source": "flake8", "range": { "start": {"line": 0, "character": 0}, "end": {"line": 0, "character": 1}, }, "code": "ERR", "message": stderr, "severity": error, } ] def compile_flake8_args(config): args = ["flake8"] for key, val in config.plugin_settings("flake8").items(): if key == "enabled": continue elif key == "maxLineLength": key = "max-line-length" arg = "--" + key if val and val is not True: if isinstance(val, list): val = ",".join(val) arg += f"={val}" else: arg += f"={val}" args.append(arg) args.append("-") return args def run_flake8(args, document): from subprocess import PIPE, run return run(args, stdout=PIPE, stderr=PIPE, input=document.source.encode()) @hookimpl(tryfirst=True) def pylsp_lint(config, document): args = compile_flake8_args(config) p = run_flake8(args, document) stderr = p.stderr.decode() if stderr: return return_error(stderr) return results_to_diagnostic(p.stdout.decode(), document) @hookimpl def pylsp_settings(): """ Disable all plugins which are supported by flake8 """ config = { "plugins": { "pycodestyle": {"enabled": False}, "mccabe": {"enabled": False}, "pyflakes": {"enabled": False}, } } return config if __name__ == "__main__": class test_document: def __init__(self, src: str): self.source = src class test_config: def plugin_settings(self, plugin: str) -> dict: return {"extend-ignore": "W503"} testdoc = test_document("import sys \nx.y()") testcfg = test_config() args = compile_flake8_args(testcfg) print(args) p = run_flake8(args, testdoc) err = p.stderr.decode() if err: print("stderr: " + repr(return_error(err))) res = p.stdout.decode() print(res) diag = results_to_diagnostic(res) print(diag) pyls-flake8-0.4.0/setup.cfg000066400000000000000000000000751405121422500154710ustar00rootroot00000000000000[bdist_wheel] universal=1 [metadata] license_file = LICENSE pyls-flake8-0.4.0/setup.py000066400000000000000000000017661405121422500153720ustar00rootroot00000000000000import os from setuptools import find_packages, setup def read(*parts): here = os.path.abspath(os.path.dirname(__file__)) with open(os.path.join(here, *parts), "r") as fp: return fp.read() setup( name="pyls-flake8", version="0.4.0", description="A Flake8 plugin for the Python Language Server", long_description=read("README.md"), long_description_content_type="text/markdown", url="https://github.com/emanspeaks/pyls-flake8", license="MIT", maintainer="Peter Justin", maintainer_email="peter.justin@outlook.com", author="Randy Eckman", author_email="emanspeaks@gmail.com", packages=find_packages(), install_requires=["python-lsp-server", "flake8>=3.6.0"], entry_points={"pylsp": ["pyls_flake8 = pyls_flake8.plugin"]}, classifiers=[ "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.7", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", ], )