Add pylint pre-commit hook

This commit is contained in:
Cosmin Ciocan
2024-01-12 18:12:49 +01:00
parent 182e3519ad
commit be6b7a01d6
5 changed files with 43 additions and 2 deletions
+7
View File
@@ -37,3 +37,10 @@ repos:
hooks: hooks:
- id: flake8 - id: flake8
args: ["--config", ".flake8"] args: ["--config", ".flake8"]
# pylint check
- repo: https://github.com/pycqa/pylint
rev: v3.0.3
hooks:
- id: pylint
args: ["--rcfile", "pyproject.toml"]
+4
View File
@@ -1,3 +1,7 @@
"""
nvcc4jupyter: CUDA C++ plugin for Jupyter Notebook
"""
from .plugin import NVCCPlugin, load_ipython_extension # noqa: F401 from .plugin import NVCCPlugin, load_ipython_extension # noqa: F401
__version__ = "1.0.2" __version__ = "1.0.2"
+16
View File
@@ -1,7 +1,14 @@
"""
Parsers for the CUDA magic commands.
"""
import argparse import argparse
def get_parser_cuda() -> argparse.ArgumentParser: def get_parser_cuda() -> argparse.ArgumentParser:
"""
%%cuda magic command parser.
"""
parser = argparse.ArgumentParser( parser = argparse.ArgumentParser(
description=( description=(
"%%cuda magic that compiles and runs CUDA C++ code in this cell." "%%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: def get_parser_cuda_group_run() -> argparse.ArgumentParser:
"""
%%cuda_group_run magic command parser.
"""
parser = get_parser_cuda() parser = get_parser_cuda()
parser.description = ( parser.description = (
"%%cuda_group_run magic that compiles and runs source files in a given" "%%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: def get_parser_cuda_group_save() -> argparse.ArgumentParser:
"""
%%cuda_group_save magic command parser.
"""
parser = argparse.ArgumentParser( parser = argparse.ArgumentParser(
description=( description=(
"%%cuda_group_save magic that saves CUDA C++ code in this cell for" "%%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: def get_parser_cuda_group_delete() -> argparse.ArgumentParser:
"""
%%cuda_group_delete magic command parser.
"""
parser = argparse.ArgumentParser( parser = argparse.ArgumentParser(
description=( description=(
"%%cuda_group_delete magic that deletes all files in a group. See" "%%cuda_group_delete magic that deletes all files in a group. See"
+15 -2
View File
@@ -1,3 +1,7 @@
"""
nvcc4jupyter: CUDA C++ plugin for Jupyter Notebook
"""
import argparse import argparse
import glob import glob
import os import os
@@ -7,6 +11,7 @@ import tempfile
import uuid import uuid
from typing import List, Optional from typing import List, Optional
# pylint: disable=import-error
from IPython.core.interactiveshell import InteractiveShell from IPython.core.interactiveshell import InteractiveShell
from IPython.core.magic import Magics, cell_magic, line_magic, magics_class 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): def print_out(out: str):
"""Print string line by line."""
for line in out.split("\n"): for line in out.split("\n"):
print(line) print(line)
@magics_class @magics_class
class NVCCPlugin(Magics): class NVCCPlugin(Magics):
"""
CUDA C++ plugin for Jupyter Notebook
"""
def __init__(self, shell: InteractiveShell): def __init__(self, shell: InteractiveShell):
super(NVCCPlugin, self).__init__(shell) super().__init__(shell)
self.shell: InteractiveShell # type hint not provided by parent class self.shell: InteractiveShell # type hint not provided by parent class
self.parser_cuda = parsers.get_parser_cuda() 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. ValueError: If the source name does not have a proper extension.
""" """
_, ext = os.path.splitext(source_name) _, ext = os.path.splitext(source_name)
if ext != ".cu" and ext != ".h": if ext not in (".cu", ".h"):
raise ValueError( raise ValueError(
f'Given source name "{source_name}" must end in ".h" or ".cu".' 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): def load_ipython_extension(shell: InteractiveShell):
"""
Method used by IPython to load the extension.
"""
nvcc_plugin = NVCCPlugin(shell) nvcc_plugin = NVCCPlugin(shell)
shell.register_magics(nvcc_plugin) shell.register_magics(nvcc_plugin)
+1
View File
@@ -142,6 +142,7 @@ extension-pkg-whitelist= [
] ]
ignore="CVS" ignore="CVS"
ignore-patterns="test.*?py,conftest.py" ignore-patterns="test.*?py,conftest.py"
ignore-paths="docs,tests"
init-hook='import sys; sys.setrecursionlimit(8 * sys.getrecursionlimit())' init-hook='import sys; sys.setrecursionlimit(8 * sys.getrecursionlimit())'
jobs=0 jobs=0
limit-inference-results=100 limit-inference-results=100