From be6b7a01d647ea4ceb7de6d874b95cc794df5961 Mon Sep 17 00:00:00 2001 From: Cosmin Ciocan Date: Fri, 12 Jan 2024 18:12:49 +0100 Subject: [PATCH] Add pylint pre-commit hook --- .pre-commit-config.yaml | 7 +++++++ nvcc4jupyter/__init__.py | 4 ++++ nvcc4jupyter/parsers.py | 16 ++++++++++++++++ nvcc4jupyter/plugin.py | 17 +++++++++++++++-- pyproject.toml | 1 + 5 files changed, 43 insertions(+), 2 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 46ee56e..4cfc67f 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -37,3 +37,10 @@ repos: hooks: - id: flake8 args: ["--config", ".flake8"] + + # pylint check + - repo: https://github.com/pycqa/pylint + rev: v3.0.3 + hooks: + - id: pylint + args: ["--rcfile", "pyproject.toml"] diff --git a/nvcc4jupyter/__init__.py b/nvcc4jupyter/__init__.py index e9f7145..70a978f 100644 --- a/nvcc4jupyter/__init__.py +++ b/nvcc4jupyter/__init__.py @@ -1,3 +1,7 @@ +""" +nvcc4jupyter: CUDA C++ plugin for Jupyter Notebook +""" + from .plugin import NVCCPlugin, load_ipython_extension # noqa: F401 __version__ = "1.0.2" diff --git a/nvcc4jupyter/parsers.py b/nvcc4jupyter/parsers.py index 7679465..e94afce 100644 --- a/nvcc4jupyter/parsers.py +++ b/nvcc4jupyter/parsers.py @@ -1,7 +1,14 @@ +""" +Parsers for the CUDA magic commands. +""" + import argparse def get_parser_cuda() -> argparse.ArgumentParser: + """ + %%cuda magic command parser. + """ parser = argparse.ArgumentParser( description=( "%%cuda magic that compiles and runs CUDA C++ code in this cell." @@ -16,6 +23,9 @@ def get_parser_cuda() -> argparse.ArgumentParser: def get_parser_cuda_group_run() -> argparse.ArgumentParser: + """ + %%cuda_group_run magic command parser. + """ parser = get_parser_cuda() parser.description = ( "%%cuda_group_run magic that compiles and runs source files in a given" @@ -28,6 +38,9 @@ def get_parser_cuda_group_run() -> argparse.ArgumentParser: def get_parser_cuda_group_save() -> argparse.ArgumentParser: + """ + %%cuda_group_save magic command parser. + """ parser = argparse.ArgumentParser( description=( "%%cuda_group_save magic that saves CUDA C++ code in this cell for" @@ -42,6 +55,9 @@ def get_parser_cuda_group_save() -> argparse.ArgumentParser: def get_parser_cuda_group_delete() -> argparse.ArgumentParser: + """ + %%cuda_group_delete magic command parser. + """ parser = argparse.ArgumentParser( description=( "%%cuda_group_delete magic that deletes all files in a group. See" diff --git a/nvcc4jupyter/plugin.py b/nvcc4jupyter/plugin.py index a4ff704..269a2cc 100644 --- a/nvcc4jupyter/plugin.py +++ b/nvcc4jupyter/plugin.py @@ -1,3 +1,7 @@ +""" +nvcc4jupyter: CUDA C++ plugin for Jupyter Notebook +""" + import argparse import glob import os @@ -7,6 +11,7 @@ import tempfile import uuid from typing import List, Optional +# pylint: disable=import-error from IPython.core.interactiveshell import InteractiveShell from IPython.core.magic import Magics, cell_magic, line_magic, magics_class @@ -17,14 +22,19 @@ SHARED_GROUP_NAME = "shared" def print_out(out: str): + """Print string line by line.""" for line in out.split("\n"): print(line) @magics_class class NVCCPlugin(Magics): + """ + CUDA C++ plugin for Jupyter Notebook + """ + def __init__(self, shell: InteractiveShell): - super(NVCCPlugin, self).__init__(shell) + super().__init__(shell) self.shell: InteractiveShell # type hint not provided by parent class self.parser_cuda = parsers.get_parser_cuda() @@ -55,7 +65,7 @@ class NVCCPlugin(Magics): ValueError: If the source name does not have a proper extension. """ _, ext = os.path.splitext(source_name) - if ext != ".cu" and ext != ".h": + if ext not in (".cu", ".h"): raise ValueError( f'Given source name "{source_name}" must end in ".h" or ".cu".' ) @@ -304,5 +314,8 @@ class NVCCPlugin(Magics): def load_ipython_extension(shell: InteractiveShell): + """ + Method used by IPython to load the extension. + """ nvcc_plugin = NVCCPlugin(shell) shell.register_magics(nvcc_plugin) diff --git a/pyproject.toml b/pyproject.toml index 5f5e495..ecad9fb 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -142,6 +142,7 @@ extension-pkg-whitelist= [ ] ignore="CVS" ignore-patterns="test.*?py,conftest.py" +ignore-paths="docs,tests" init-hook='import sys; sys.setrecursionlimit(8 * sys.getrecursionlimit())' jobs=0 limit-inference-results=100