diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index af2e2d69811c2b463798f8ca70e9f7e0ff24faeb..95b947aedaa43e77ce39bee7f9828153690c8357 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,9 +1,10 @@ ci: autoupdate_commit_msg: "chore: update pre-commit hooks" autofix_commit_msg: "style: pre-commit fixes" + autoupdate_schedule: monthly repos: - - repo: https://gitlab.cern.ch/pre-commit-hook-mirrors/pre-commit/pre-commit-hooks + - repo: https://github.com/pre-commit/pre-commit-hooks rev: v5.0.0 hooks: - id: check-added-large-files @@ -17,25 +18,36 @@ repos: - id: requirements-txt-fixer - id: trailing-whitespace - - repo: https://gitlab.cern.ch/pre-commit-hook-mirrors/kynan/nbstripout + - repo: https://github.com/kynan/nbstripout rev: 0.8.0 hooks: - id: nbstripout types_or: [jupyter] - - repo: https://gitlab.cern.ch/pre-commit-hook-mirrors/pre-commit/mirrors-clang-format + - repo: https://github.com/pre-commit/mirrors-clang-format rev: v19.1.3 hooks: - id: clang-format types_or: [c++, c, cuda] - - repo: https://gitlab.cern.ch/pre-commit-hook-mirrors/psf/black-pre-commit-mirror + - repo: https://github.com/psf/black-pre-commit-mirror rev: 24.10.0 # Use the latest stable version hooks: - id: black-jupyter + - repo: https://github.com/pycqa/isort + rev: 5.13.2 + hooks: + - id: isort + name: isort (python) + + - repo: https://github.com/Lucas-C/pre-commit-hooks + rev: "v1.5.5" + hooks: + - id: remove-tabs + - repo: https://github.com/charliermarsh/ruff-pre-commit - rev: v0.7.3 # Use the latest version + rev: v0.7.4 # Use the latest version hooks: - id: ruff args: ["--fix", "--show-fixes"] @@ -47,20 +59,20 @@ repos: types: [file] files: (\.cmake|CMakeLists.txt)(.in)?$ - # - repo: https://gitlab.cern.ch/pre-commit-hook-mirrors/codespell-project/codespell + # - repo: https://github.com/codespell-project/codespell # rev: v # hooks: # - id: codespell # args: ["-L", "sur,falsy,gaus,hist,lsit,nd,parms,retur,ue,ba,claus,fo"] - # - repo: https://gitlab.cern.ch/pre-commit-hook-mirrors/pre-commit/pygrep-hooks + # - repo: https://github.com/pre-commit/pygrep-hooks # rev: v # hooks: # - id: rst-backticks # - id: rst-directive-colons # - id: rst-inline-touching-normal - # - repo: https://gitlab.cern.ch/pre-commit-hook-mirrors/shellcheck-py/shellcheck-py + # - repo: https://github.com/shellcheck-py/shellcheck-py # rev: v0.9.0.5 # hooks: # - id: shellcheck diff --git a/.vscode/settings.json b/.vscode/settings.json index e3bf67c9991605aa4e4efe441d5ec1aa441f87c6..afcd6bb70d5b0aaa915d37673255df4c5586ee3c 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -29,5 +29,7 @@ "--function-arg-placeholders=false", "--compile-commands-dir=build" ], - "clangd.path": "clangd-17" + "clangd.path": "clangd-17", + "jupyter.debugJustMyCode": false, + "debugpy.debugJustMyCode": false } diff --git a/README.md b/README.md index 1e5e087ef5ad7207984af3c6b4d984ff1e592948..ebeb45bf39eaa0e1ff0582f7560a3260d69d4db2 100644 --- a/README.md +++ b/README.md @@ -109,7 +109,6 @@ VS Marketplace Link: https://marketplace.visualstudio.com/items?itemName=ms-pyth ### python formatting - pre-commit + vscode extensions -- install vscode extensions - install extensions ``` Name: Black Formatter @@ -131,12 +130,22 @@ and update `settings.json` ``` - install pre-commit hooks ``` -repos: - - repo: https://gitlab.cern.ch/pre-commit-hook-mirrors/psf/black + - repo: https://github.com/psf/black-pre-commit-mirror + rev: 24.10.0 # Use the latest stable version + hooks: + - id: black-jupyter + + - repo: https://github.com/pycqa/isort + rev: 5.13.2 + hooks: + - id: isort + name: isort (python)repos: + - repo: https://gitlab.cern.ch/pre-commit-hook-mirrors/psf/black-pre-commit-mirror rev: 24.10.0 # Use the latest stable version hooks: - id: black ``` + ### c++ lint - nox + vscode extensions - setup nox @@ -204,8 +213,22 @@ and set ### python lint #### ruff: pre-commit + vscode extensions - install pre-commit - +```yaml + - repo: https://github.com/charliermarsh/ruff-pre-commit + rev: v0.7.3 # Use the latest version + hooks: + - id: ruff + args: ["--fix", "--show-fixes"] +``` - install extensions +``` +Name: Ruff +Id: charliermarsh.ruff +Description: A Visual Studio Code extension with support for the Ruff linter. +Version: 2024.54.0 +Publisher: Astral Software +VS Marketplace Link: https://marketplace.visualstudio.com/items?itemName=charliermarsh.ruff +``` #### pylint: nox + vscode extensions diff --git a/cpp/CMakeLists.txt b/cpp/CMakeLists.txt index ebe861560c8aa940310f70d9370154da4803bb14..3609906722ba6de0c9f946cbfd328db096ca270a 100644 --- a/cpp/CMakeLists.txt +++ b/cpp/CMakeLists.txt @@ -2,14 +2,14 @@ add_library(hello SHARED src/hello.cc) target_include_directories( hello PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>) -install(TARGETS hello LIBRARY DESTINATION .) +install(TARGETS hello LIBRARY DESTINATION _csrc) add_library(complexf SHARED src/complexf.cc) target_include_directories( complexf PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>) target_link_libraries(complexf PRIVATE hello) -install(TARGETS complexf LIBRARY DESTINATION .) +install(TARGETS complexf LIBRARY DESTINATION _csrc) set_target_properties(complexf PROPERTIES INSTALL_RPATH "$ORIGIN") # install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/include/" DESTINATION diff --git a/notebooks/example.ipynb b/notebooks/example.ipynb index 02294a86879aae90f8eab3c36f199f806755c6e1..1c9db395dd3de0605fb40f98d28e64c0e345400d 100644 --- a/notebooks/example.ipynb +++ b/notebooks/example.ipynb @@ -13,6 +13,28 @@ "print(ms.complex(1, 2))\n", "print(np.array([1, 2, 3]))" ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "import pylint\n", + "\n", + "pylint.run_pylint([\"myproj/simulation\"])" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "from astroid.interpreter._import import util\n", + "\n", + "print(util.is_namespace(\"myproj\"))" + ] } ], "metadata": { diff --git a/pyproject.toml b/pyproject.toml index ff9bbf1310b84ca3a491ffddefeb325126afa063..4edd5205b96113c6c4b666ba78a518d69bc1ce2e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -62,5 +62,8 @@ profile = "black" disable = [ "C0114", # Missing module docstring "C0115", # Missing class docstring - "C0116" # Missing function or method docstring + "C0116", # Missing function or method docstring ] + +[tool.pylint.MASTER] +extension-pkg-allow-list = "myproj.simulation" diff --git a/python/myproj/simulation/__init__.py b/python/myproj/simulation/__init__.py index 9d2aca4229504843036666e646b9071fa1877423..95f986430a57619f9c33fbbe6cd5919104313b10 100644 --- a/python/myproj/simulation/__init__.py +++ b/python/myproj/simulation/__init__.py @@ -1,4 +1,4 @@ -from ._csrc._hello import add, complex +from ._csrc._hello import add, complexf from .core import div -__all__ = ["add", "complex", "div"] +__all__ = ["add", "complexf", "div"] diff --git a/python/myproj/simulation/_csrc/CMakeLists.txt b/python/myproj/simulation/_csrc/CMakeLists.txt index d42c7a11ae836ce68d1211021a0450b2b093a425..32fdd6630005466654ead6379c7ca7079ab1153f 100644 --- a/python/myproj/simulation/_csrc/CMakeLists.txt +++ b/python/myproj/simulation/_csrc/CMakeLists.txt @@ -7,4 +7,4 @@ find_package(pybind11 CONFIG REQUIRED) pybind11_add_module(_hello MODULE _hello_python.cc) target_link_libraries(_hello PRIVATE complexf) install(TARGETS _hello DESTINATION _csrc) -set_target_properties(_hello PROPERTIES INSTALL_RPATH "$ORIGIN/..") +set_target_properties(_hello PROPERTIES INSTALL_RPATH "$ORIGIN") diff --git a/python/myproj/simulation/_csrc/_hello.pyi b/python/myproj/simulation/_csrc/_hello.pyi new file mode 100644 index 0000000000000000000000000000000000000000..f8abbcb49bada927a00fe05f07c69d0a5cff7a9c --- /dev/null +++ b/python/myproj/simulation/_csrc/_hello.pyi @@ -0,0 +1,17 @@ +""" +pybind11 example plugin +""" + +from __future__ import annotations + +__all__ = ["add", "complexf"] + +def add(arg0: float, arg1: float) -> float: + """ + A function which adds two numbers + """ + +def complexf(arg0: float, arg1: float) -> float: + """ + complex(a,b) = add(a,b) + 2 + """ diff --git a/python/myproj/simulation/_csrc/_hello_python.cc b/python/myproj/simulation/_csrc/_hello_python.cc index 594169f84a7157fc17ecf3ab22b761d28b1d4b41..175b25e484a5f001d7ee95118de5986186136fde 100644 --- a/python/myproj/simulation/_csrc/_hello_python.cc +++ b/python/myproj/simulation/_csrc/_hello_python.cc @@ -7,5 +7,5 @@ PYBIND11_MODULE(_hello, m) { m.doc() = "pybind11 example plugin"; // optional module docstring m.def("add", &add, "A function which adds two numbers"); - m.def("complex", &complexf, "complex(a,b) = add(a,b) + 2"); + m.def("complexf", &complexf, "complex(a,b) = add(a,b) + 2"); }