Skip to content
Snippets Groups Projects
Commit 6bc5e41a authored by Xuefeng Ding's avatar Xuefeng Ding
Browse files

fix mypy

parent 3e6d4c20
No related branches found
No related tags found
No related merge requests found
......@@ -2,3 +2,4 @@ __pycache__/
build/
.cache/
.venv/
.coverage
......@@ -37,14 +37,19 @@ repos:
- id: nbstripout
types_or: [jupyter]
- repo: https://github.com/charliermarsh/ruff-pre-commit
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.8.0 # Use the latest version
hooks:
- id: ruff
args: ["--fix", "--show-fixes"]
- id: ruff-format
- repo: https://github.com/RobertCraigie/pyright-python
rev: v1.1.389
- repo: https://github.com/pre-commit/mirrors-mypy
rev: "v1.13.0"
hooks:
- id: pyright
- id: mypy
# - repo: https://github.com/PyCQA/pylint
# rev: "v3.3.1"
# hooks:
# - id: pylint
......@@ -21,6 +21,9 @@
"[cmake]": {
"editor.defaultFormatter": "josetr.cmake-language-support-vscode"
},
"[toml]": {
"editor.defaultFormatter": "tamasfe.even-better-toml"
},
"clangd.arguments": [
"--log=info",
"--pretty",
......
......@@ -37,6 +37,7 @@ def dev(session: nox.Session) -> None:
"pip>=23",
"nox",
"pytest",
"pytest-cov",
"pre-commit",
)
session.run(
......@@ -59,13 +60,6 @@ def cpp_lint_slow(session: nox.Session) -> None:
session.run("clang-tidy", "-p", "build", *cpp_files)
@nox.session(reuse_venv=True)
def cpp_lint(session: nox.Session) -> None:
cpp_files = glob.glob("**/*.cc", recursive=True)
session.install("clangd-tidy")
session.run("clangd-tidy", "-p", "build", *cpp_files)
@nox.session(reuse_venv=True)
def rr_run(session: nox.Session) -> None:
"""
......@@ -76,15 +70,6 @@ def rr_run(session: nox.Session) -> None:
session.run("repo-review", ".")
# @nox.session
# def rr_lint(session: nox.Session) -> None:
# """
# Run the linter.
# """
# session.install("pre-commit")
# session.run("pre-commit", "run", "--all-files", *session.posargs)
@nox.session
def rr_pylint(session: nox.Session) -> None:
"""
......@@ -95,52 +80,3 @@ def rr_pylint(session: nox.Session) -> None:
session.install("-e.")
session.install("pylint>=3.2")
session.run("pylint", "myproj.simulation", *session.posargs)
# @nox.session
# def rr_tests(session: nox.Session) -> None:
# """
# Run the unit and regular tests for sp-repo-review.
# """
# session.install("-e.[test,cli]")
# session.run("pytest", *session.posargs, env={"PYTHONWARNDEFAULTENCODING": "1"})
# @nox.session(reuse_venv=True)
# def rr_build(session: nox.Session) -> None:
# """
# Build an SDist and wheel for sp-repo-review.
# """
# build_p = DIR.joinpath("build")
# if build_p.exists():
# shutil.rmtree(build_p)
# session.install("build")
# session.run("python", "-m", "build")
@nox.session
def build_extension(session: nox.Session) -> None:
# Install build dependencies
session.install(
"pybind11", "scikit-build", "setuptools", "wheel", "pybind11-stubgen"
)
# Build the extension module using scikit-build
session.run("python", "-m", "pip", "install", ".", "--no-build-isolation")
# Generate the .pyi file using pybind11-stubgen
# Replace 'your_package._hello' with the actual module name
session.run("pybind11-stubgen", "your_package._hello")
# Move the generated .pyi file to the source directory
# By default, pybind11-stubgen outputs to 'stubs/your_package/_hello/__init__.pyi'
stub_src = (
Path("stubs") / "myproj" / "simulation" / "_csrc" / "_hello" / "__init__.pyi"
)
stub_dest = Path("myproj") / "simulation" / "_csrc" / "_hello.pyi"
session.run("mv", stub_src, stub_dest, external=True)
# Clean up the stubs directory
session.run("rm", "-r", "stubs", external=True)
......@@ -7,12 +7,8 @@ name = "myproj_simulation"
version = "0.2.1"
description = "A great package."
readme = "README.md"
authors = [
{ name = "Xuefeng Ding", email = "dingxf@ihep.ac.cn" },
]
maintainers = [
{ name = "Xuefeng Ding (IHEP)", email = "dingxf@ihep.ac.cn" },
]
authors = [{ name = "Xuefeng Ding", email = "dingxf@ihep.ac.cn" }]
maintainers = [{ name = "Xuefeng Ding (IHEP)", email = "dingxf@ihep.ac.cn" }]
requires-python = ">=3.9"
dependencies = []
......@@ -41,7 +37,7 @@ Changelog = "https://package.readthedocs.io/en/latest/changelog.html"
[tool.scikit-build.wheel]
install-dir = "myproj/simulation"
exclude = ["CMakeLists.txt","*.cc","*.h"]
exclude = ["CMakeLists.txt", "*.cc", "*.h"]
# [tool.scikit-build.package-data]
# myproj = ["py.typed"]
......@@ -52,25 +48,35 @@ strict = true
ignore_missing_imports = true
warn_unused_configs = true
warn_unreachable = true
enable_error_code = ["ignore-without-code", "redundant-expr", "truthy-bool"]
disable_error_code = []
mypy_path = ["python"]
[tool.pylint."MESSAGES CONTROL"]
disable = [
"C0114", # Missing module docstring
"C0115", # Missing class docstring
"C0116", # Missing function or method docstring
]
[tool.pylint.MASTER]
extension-pkg-allow-list = "myproj.simulation"
disallow_untyped_decorators = false
mypy_path = ["python/myproj/simulation"]
[tool.ruff.lint]
select = [
"E", # pycodestyle
"F", # Pyflakes
"UP", # pyupgrade
"B", # flake8-bugbear
"SIM", # flake8-simplify
"I", # isort
"E", # pycodestyle
"F", # Pyflakes
"UP", # pyupgrade
"B", # flake8-bugbear
"SIM", # flake8-simplify
"I", # isort
]
[tool.pytest.ini_options]
minversion = "7"
testpaths = ["python/tests"]
python_files = "test_*.py"
python_classes = "Test*"
python_functions = "test_*"
addopts = [
"--cov=myproj.simulation",
"--cov-report=term-missing",
"-ra",
"--showlocals",
"--strict-markers",
"--strict-config",
]
xfail_strict = true
filterwarnings = ["error"]
log_cli_level = "info"
......@@ -5,5 +5,5 @@ def div(a: float, b: float) -> float:
return a / b
def complex2(a, b: float) -> float:
def complex2(a: float, b: float) -> float:
return complexf(a, b) + add(a, b)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment