Skip to content

Commit

Permalink
perf: add nox command to generate pyi stubs (#89)
Browse files Browse the repository at this point in the history
* perf: add nox command to generate pyi stubs

Signed-off-by: l.feng <[email protected]>

* Sync template

Signed-off-by: l.feng <[email protected]>

---------

Signed-off-by: l.feng <[email protected]>
  • Loading branch information
msclock authored Dec 30, 2024
1 parent 413c6ff commit 678b574
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 14 deletions.
12 changes: 11 additions & 1 deletion noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
nox.options.sessions = ["lint", "pylint", "tests"]


@nox.session
@nox.session(reuse_venv=True)
def lint(session: nox.Session) -> None:
"""
Run the linter.
Expand Down Expand Up @@ -92,6 +92,16 @@ def build(session: nox.Session) -> None:
session.run("python", "-m", "build")


@nox.session(reuse_venv=True)
def pyi(session: nox.Session) -> None:
"""
Generate the Pyi type stubs.
"""
session.install("pybind11-stubgen")
session.install(".[test]")
session.run("pybind11-stubgen", "ss_pybind11._core", "-o", "src")


@nox.session(reuse_venv=True)
def template(session: nox.Session) -> None:
"""
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ isort.required-imports = ["from __future__ import annotations"]

[tool.pylint]
py-version = "3.8"
ignore-paths = [".*/_version.py"]
ignore-paths = [".*/_version.py", ".*/*.pyi"]
extension-pkg-allow-list = ["ss_pybind11._core"]
reports.output-format = "colorized"
similarities.ignore-imports = "yes"
Expand Down
6 changes: 3 additions & 3 deletions src/_core/src/pybind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ PYBIND11_MODULE(_core, m) {
Pybind11 _core plugin
-----------------------
.. currentmodule:: _core
)pbdoc";
)pbdoc";

m.def("version", []() { return _core::ProjectVersion(); }, R"pbdoc(
The _core plugin version.
)pbdoc");
The _core plugin version.
)pbdoc");
}
14 changes: 12 additions & 2 deletions src/ss_pybind11/_core.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
"""Pybind11 _core plugin interfaces"""
"""
Pybind11 _core plugin
-----------------------
.. currentmodule:: _core
"""

from __future__ import annotations

__all__ = ["version"]

def version() -> str:
"""_core plugin version."""
"""
The _core plugin version.
"""
12 changes: 11 additions & 1 deletion template/noxfile.py.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ DIR = Path(__file__).parent.resolve()
nox.options.sessions = ["lint", "pylint", "tests"]


@nox.session
@nox.session(reuse_venv=True)
def lint(session: nox.Session) -> None:
"""
Run the linter.
Expand Down Expand Up @@ -110,6 +110,16 @@ def build(session: nox.Session) -> None:

session.install("build")
session.run("python", "-m", "build")


@nox.session(reuse_venv=True)
def pyi(session: nox.Session) -> None:
"""
Generate the Pyi type stubs.
"""
session.install("pybind11-stubgen")
session.install(".[test]")
session.run("pybind11-stubgen", "{{ module_name }}._core", "-o", "src")
[%- if repo_name == 'ss-pybind11' %]


Expand Down
2 changes: 1 addition & 1 deletion template/pyproject.toml.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ isort.required-imports = ["from __future__ import annotations"]

[tool.pylint]
py-version = "{{ min_py }}"
ignore-paths = [".*/_version.py"]
ignore-paths = [".*/_version.py", ".*/*.pyi"]
[%- if compiled == true %]
extension-pkg-allow-list = ["{{ module_name }}._core"]
[%- endif %]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ PYBIND11_MODULE(_core, m) {
Pybind11 _core plugin
-----------------------
.. currentmodule:: _core
)pbdoc";
)pbdoc";

m.def("version", []() { return _core::ProjectVersion(); }, R"pbdoc(
The _core plugin version.
)pbdoc");
The _core plugin version.
)pbdoc");
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
"""Pybind11 _core plugin interfaces"""
"""

Pybind11 _core plugin
-----------------------
.. currentmodule:: _core

"""

from __future__ import annotations

__all__ = ["version"]

def version() -> str:
"""_core plugin version."""
"""
The _core plugin version.
"""

0 comments on commit 678b574

Please sign in to comment.