Loading .pre-commit-hooks.yaml 0 → 100644 +7 −0 Original line number Diff line number Diff line - id: pylint name: PyLint entry: pre-commit-pylint language: python require_serial: true types: [python] verbose: true pre_commit_pylint.py 0 → 100644 +64 −0 Original line number Diff line number Diff line """ Run pylint from pre-commit with project dependencies installed """ import argparse import subprocess from pylint import lint __version__ = '0.1' def argument_parser(): parser = argparse.ArgumentParser(description=__doc__) parser.add_argument( '--extras', '-e', action='append', help="The names of optional requirements sets to install", ) parser.add_argument( '--cache-file', '-c', action='append', help=""" The names of files to use for keying the environment cache: if these files change a new environment is created. Defaults to any that exist of the following: pyproject.toml, setup.py, setup.cfg, requirements.txt """, ) parser.add_argument( '--fail-under', '-f', default=10.0, type=float, help=""" If the score is below the given threshold a non-zero exit code will be returned """ ) parser.add_argument( 'files', nargs='*', help="Files to lint; these will typically be supplied by pre-commit", ) return parser def main(): ap = argument_parser() opts = ap.parse_args() cmd = ['pip', 'install', '-e', '.'] if opts.extras: cmd.extend(f'.[{target}]' for target in opts.extras) proc = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) if proc.returncode: ap.error(proc.stdout) run = lint.Run(opts.files, do_exit=False) score = run.linter.stats['global_note'] if score < opts.fail_under: ap.exit(1) if __name__ == '__main__': main() pyproject.toml 0 → 100644 +23 −0 Original line number Diff line number Diff line [build-system] requires = ["flit_core >=2,<4"] build-backend = "flit_core.buildapi" [tool.flit.metadata] module = "pre_commit_pylint" author = "Dom Sekotill" author-email = "dom.sekotill@kodo.org.uk" home-page = "https://code.kodo.org.uk/dom/pre-commit-pylint" requires = [ "pylint >=2,<3", ] classifiers = [ "Development Status :: 3 - Alpha", "Intended Audience :: Developers", "License :: OSI Approved :: Mozilla Public License 2.0 (MPL 2.0)", "Natural Language :: English", "Programming Language :: Python :: 3 :: Only", "Topic :: Software Development :: Quality Assurance", ] [tool.flit.scripts] pre-commit-pylint = "pre_commit_pylint:main" Loading
.pre-commit-hooks.yaml 0 → 100644 +7 −0 Original line number Diff line number Diff line - id: pylint name: PyLint entry: pre-commit-pylint language: python require_serial: true types: [python] verbose: true
pre_commit_pylint.py 0 → 100644 +64 −0 Original line number Diff line number Diff line """ Run pylint from pre-commit with project dependencies installed """ import argparse import subprocess from pylint import lint __version__ = '0.1' def argument_parser(): parser = argparse.ArgumentParser(description=__doc__) parser.add_argument( '--extras', '-e', action='append', help="The names of optional requirements sets to install", ) parser.add_argument( '--cache-file', '-c', action='append', help=""" The names of files to use for keying the environment cache: if these files change a new environment is created. Defaults to any that exist of the following: pyproject.toml, setup.py, setup.cfg, requirements.txt """, ) parser.add_argument( '--fail-under', '-f', default=10.0, type=float, help=""" If the score is below the given threshold a non-zero exit code will be returned """ ) parser.add_argument( 'files', nargs='*', help="Files to lint; these will typically be supplied by pre-commit", ) return parser def main(): ap = argument_parser() opts = ap.parse_args() cmd = ['pip', 'install', '-e', '.'] if opts.extras: cmd.extend(f'.[{target}]' for target in opts.extras) proc = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) if proc.returncode: ap.error(proc.stdout) run = lint.Run(opts.files, do_exit=False) score = run.linter.stats['global_note'] if score < opts.fail_under: ap.exit(1) if __name__ == '__main__': main()
pyproject.toml 0 → 100644 +23 −0 Original line number Diff line number Diff line [build-system] requires = ["flit_core >=2,<4"] build-backend = "flit_core.buildapi" [tool.flit.metadata] module = "pre_commit_pylint" author = "Dom Sekotill" author-email = "dom.sekotill@kodo.org.uk" home-page = "https://code.kodo.org.uk/dom/pre-commit-pylint" requires = [ "pylint >=2,<3", ] classifiers = [ "Development Status :: 3 - Alpha", "Intended Audience :: Developers", "License :: OSI Approved :: Mozilla Public License 2.0 (MPL 2.0)", "Natural Language :: English", "Programming Language :: Python :: 3 :: Only", "Topic :: Software Development :: Quality Assurance", ] [tool.flit.scripts] pre-commit-pylint = "pre_commit_pylint:main"