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

add more

parent 49dabc33
No related branches found
No related tags found
No related merge requests found
repos:
- repo: https://github.com/kynan/nbstripout
rev: main # Use a specific tag or commit hash for stability
hooks:
- id: nbstripout
files: \.ipynb$
{
"[python]": {
"editor.codeActionsOnSave": {
"source.organizeImports": "always"
},
"editor.defaultFormatter": "ms-python.black-formatter"
},
"isort.args": ["--profile", "black"],
"notebook.lineNumbers": "on"
}
......@@ -3,7 +3,7 @@ project("${SKBUILD_PROJECT_NAME}"
LANGUAGES CXX
VERSION "${SKBUILD_PROJECT_VERSION}")
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
# set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
# include(GNUInstallDirs)
add_subdirectory(cpp)
......
......@@ -8,16 +8,24 @@ use scikit-build-core to setup a python-cmake project that can be installed with
## Conclusion
- cannot make packages like import myproj.simulation. It replaces "." with "_"
- most of the case, check following
- package name has nothing to do with the import path. pacakge named my_package is installed with `pip install .`, uninstalled with `pip uninstall my_package`, but can be used as `import kk.ss as ks`.
- installation of cpp files:
```cmake
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/my_main.py DESTINATION .)
install(TARGET mylib LIBRARY DESTINATION .)
```
and set
```
[tool.scikit-build]
wheel.install-dir = "kk/ss"
```
- installation of python files:
```
[tool.scikit-build.wheel.packages]
"mm/tt" = "python/myproj/simulation"
[tool.scikit-build]
wheel.exclude = ["CMakeLists.txt","*.cc","*.h"]
```
## special variable
......@@ -38,3 +46,43 @@ wheel.install-dir = "kk/ss"
- `${SKBUILD_NULL_DIR}`: Anything installed here will not be placed in the
wheel.
## style and lint check
### notebook otuput stripping
- use pre-commit
1. install
```bash
pip install pre-commit nbstripout
```
2. set
```yaml
repos:
- repo: https://github.com/kynan/nbstripout
rev: master # Pin to a specific version if desired
hooks:
- id: nbstripout
files: \.ipynb$
```
3. install
```bash
pre-commit install
```
## vscode extensions to install
- "isort", which sort python import
```
Name: isort
Id: ms-python.isort
Description: Import organization support for Python files using isort.
Version: 2023.10.1
Publisher: Microsoft
VS Marketplace Link: https://marketplace.visualstudio.com/items?itemName=ms-python.isort
```
- "pylint", for complrehensive code analysis
```
Name: Pylint
Id: ms-python.pylint
Description: Linting support for Python files using Pylint.
Version: 2024.0.0
Publisher: Microsoft
VS Marketplace Link: https://marketplace.visualstudio.com/items?itemName=ms-python.pylint
```
%% Cell type:code id: tags:
``` python
import myproj.simulation as ms
print(ms.add(1,2))
print(ms.complex(1,2))
```
......@@ -2,8 +2,12 @@
nox configuration file.
"""
import nox
import sys
from pathlib import Path
import nox
DIR = Path(__file__).parent.resolve()
@nox.session(venv_backend="none")
......@@ -31,3 +35,83 @@ def dev(session: nox.Session) -> None:
"-C",
"build-dir=build",
)
@nox.session(reuse_venv=True)
def rr_run(session: nox.Session) -> None:
"""
Run sp-repo-review.
"""
session.install("sp-repo-review[cli]")
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:
"""
Run PyLint.
"""
# This needs to be installed into the package environment, and is slower
# than a pre-commit check
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)
......@@ -15,9 +15,7 @@ maintainers = [
]
requires-python = ">=3.9"
dependencies = [
"typing_extensions",
]
dependencies = []
classifiers = [
"Development Status :: 4 - Beta",
......@@ -43,4 +41,26 @@ Changelog = "https://package.readthedocs.io/en/latest/changelog.html"
[tool.scikit-build]
wheel.install-dir = "myproj/simulation"
wheel.exclude = ["CMakeLists.txt","*.cc","*.h"]
\ No newline at end of file
wheel.exclude = ["CMakeLists.txt","*.cc","*.h"]
[tool.mypy]
strict = true
ignore_missing_imports = true
warn_unused_configs = true
warn_unreachable = true
disable_error_code = []
mypy_path = ["python"]
[tool.isort]
multi_line_output = 3
include_trailing_comma = true
force_grid_wrap = 0
line_length = 88
profile = "black"
[tool.pylint."MESSAGES CONTROL"]
disable = [
"C0114", # Missing module docstring
"C0115", # Missing class docstring
"C0116" # Missing function or method docstring
]
\ No newline at end of file
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