From d81b89a0f058ff2db5b8dc2e61f47c24d087ca54 Mon Sep 17 00:00:00 2001 From: "Xuefeng Ding (IHEP)" <dingxf@ihep.ac.cn> Date: Sun, 17 Nov 2024 07:11:19 +0800 Subject: [PATCH] update astroid --- .pre-commit-config.yaml | 28 ++++++++++++----- .vscode/settings.json | 4 ++- README.md | 31 ++++++++++++++++--- cpp/CMakeLists.txt | 4 +-- notebooks/example.ipynb | 22 +++++++++++++ pyproject.toml | 5 ++- python/myproj/simulation/__init__.py | 4 +-- python/myproj/simulation/_csrc/CMakeLists.txt | 2 +- python/myproj/simulation/_csrc/_hello.pyi | 17 ++++++++++ .../myproj/simulation/_csrc/_hello_python.cc | 2 +- 10 files changed, 99 insertions(+), 20 deletions(-) create mode 100644 python/myproj/simulation/_csrc/_hello.pyi diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index af2e2d6..95b947a 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 e3bf67c..afcd6bb 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 1e5e087..ebeb45b 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 ebe8615..3609906 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 02294a8..1c9db39 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 ff9bbf1..4edd520 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 9d2aca4..95f9864 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 d42c7a1..32fdd66 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 0000000..f8abbcb --- /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 594169f..175b25e 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"); } -- GitLab