Skip to content

Commit

Permalink
chore: include saturday06/starry-bpy-type-stubs
Browse files Browse the repository at this point in the history
  • Loading branch information
saturday06 committed Jun 19, 2024
1 parent 543b1e0 commit 39e73b6
Show file tree
Hide file tree
Showing 46 changed files with 3,469 additions and 32 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
!/tools/*.wsb
!/tests/ruff.toml
!/tests/resources
!/typings/ruff.toml

*.blend1
*~
Expand Down
19 changes: 2 additions & 17 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 14 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,18 @@ description = ""
authors = ["Isamu Mogi <isamu@leafytree.jp>", "iCyP"]
license = "MIT"

packages = [
{ include = "*", from = "src" },
{ include = "bgl-stubs", from = "typings" },
{ include = "bmesh-stubs", from = "typings" },
{ include = "bpy-stubs", from = "typings" },
{ include = "bpy_extras-stubs", from = "typings" },
{ include = "gpu-stubs", from = "typings" },
{ include = "gpu_extras-stubs", from = "typings" },
{ include = "idprop-stubs", from = "typings" },
{ include = "mathutils-stubs", from = "typings" },
]

[tool.poetry.dependencies]
python = "3.10.*" # I actually want to use 3.9, but bpy 3.6.* doesn't allow it.

Expand All @@ -25,12 +37,11 @@ dulwich = "*"
mypy = "*"
pyright = "*"
ruff = "*"
starry-bpy-type-stubs = { git = "https://github.com/saturday06/starry-bpy-type-stubs.git" }
tqdm = "*"
types-tqdm = "*"

[tool.ruff]
src = ["src"]
src = ["typings", "src"]

[tool.ruff.lint]
allowed-confusables = [
Expand Down Expand Up @@ -122,7 +133,7 @@ ignore-regex = ".* # codespell-ignore"

[tool.mypy]
python_version = "3.9"
mypy_path = "$MYPY_CONFIG_FILE_DIR/src"
mypy_path = "$MYPY_CONFIG_FILE_DIR/typings:$MYPY_CONFIG_FILE_DIR/src"
strict = true
disallow_any_unimported = true
disallow_any_decorated = true
Expand All @@ -145,7 +156,6 @@ typeCheckingMode = "strict"
reportMissingModuleSource = false
reportCallInDefaultInitializer = true
reportImplicitStringConcatenation = true
reportPropertyTypeMismatch = true
reportShadowedImports = true

[build-system]
Expand Down
5 changes: 3 additions & 2 deletions tools/format.bat
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ setlocal enabledelayedexpansion
pushd "%~dp0.."
set PYTHONUTF8=1
for /f "tokens=* usebackq" %%f in (`git ls-files "*.py"`) do ( set py_files=!py_files! %%f )
call poetry run ruff format %py_files%
call poetry run ruff check --fix %py_files%
for /f "tokens=* usebackq" %%f in (`git ls-files "*.pyi"`) do ( set pyi_files=!pyi_files! %%f )
call poetry run ruff format %py_files% %pyi_files%
call poetry run ruff check --fix %py_files% %pyi_files%
echo on
popd
endlocal
Expand Down
4 changes: 2 additions & 2 deletions tools/format.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ set -eux

cd "$(dirname "$0")/.."

git ls-files "*.py" | xargs poetry run ruff format
git ls-files "*.py" | xargs poetry run ruff check --fix
git ls-files "*.py" "*.pyi" | xargs poetry run ruff format
git ls-files "*.py" "*.pyi" | xargs poetry run ruff check --fix
git ls-files "*.sh" | xargs shfmt -w -s
7 changes: 4 additions & 3 deletions tools/lint.bat
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ set PYTHONUTF8=1
echo ### poetry check ###
poetry check
for /f "tokens=* usebackq" %%f in (`git ls-files "*.py"`) do ( set py_files=!py_files! %%f )
for /f "tokens=* usebackq" %%f in (`git ls-files "*.pyi"`) do ( set pyi_files=!pyi_files! %%f )
echo ### ruff ###
call poetry run ruff check %py_files%
call poetry run ruff check %py_files% %pyi_files%
echo ### codespell ###
call poetry run codespell %py_files%
echo ### mypy ###
call poetry run mypy --show-error-codes %py_files%
call poetry run mypy --show-error-codes %py_files% %pyi_files%
echo ### pyright ###
call poetry run pyright %py_files%
call poetry run pyright %py_files% %pyi_files%
popd
endlocal
endlocal
Expand Down
8 changes: 4 additions & 4 deletions tools/lint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ cd "$(dirname "$0")/.."

poetry check
git ls-files "*.sh" | xargs shellcheck
git ls-files "*.py" | xargs poetry run ruff check
git ls-files "*.py" | xargs poetry run codespell
git ls-files "*.py" | xargs poetry run mypy --show-error-codes
git ls-files "*.py" | xargs poetry run pyright
git ls-files "*.py" "*.pyi" | xargs poetry run ruff check
git ls-files "*.py" "*.pyi" | xargs poetry run codespell
git ls-files "*.py" "*.pyi" | xargs poetry run mypy --show-error-codes
git ls-files "*.py" "*.pyi" | xargs poetry run pyright
git ls-files "*.sh" | xargs shfmt -d -s
git ls-files "*/Dockerfile" "*.dockerfile" | xargs hadolint
28 changes: 28 additions & 0 deletions typings/bgl-stubs/__init__.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
GL_BACK: int
GL_BLEND: int
GL_CLAMP_TO_EDGE: int
GL_COLOR_BUFFER_BIT: int
GL_CULL_FACE: int
GL_DEPTH_BUFFER_BIT: int
GL_DEPTH_TEST: int
GL_ONE: int
GL_ONE_MINUS_SRC_ALPHA: int
GL_SRC_ALPHA: int
GL_TEXTURE0: int
GL_TEXTURE1: int
GL_TEXTURE_2D: int
GL_TEXTURE_WRAP_S: int
GL_TEXTURE_WRAP_T: int
GL_TRUE: int
GL_ZERO: int

def glClearColor(red: float, green: float, blue: float, alpha: float) -> None: ...
def glClear(mask: int) -> None: ...
def glEnable(cap: int) -> None: ...
def glDisable(cap: int) -> None: ...
def glBlendFunc(sfactor: int, dfactor: int) -> None: ...
def glDepthMask(flag: int) -> None: ...
def glCullFace(mode: int) -> None: ...
def glActiveTexture(texture: int) -> None: ...
def glBindTexture(target: int, texture: int) -> None: ...
def glTexParameteri(target: int, pname: int, param: int) -> None: ...
4 changes: 4 additions & 0 deletions typings/bmesh-stubs/__init__.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from . import ops as ops
from . import types as types

def new(use_operators: bool = True) -> types.BMesh: ...
8 changes: 8 additions & 0 deletions typings/bmesh-stubs/ops/__init__.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from bmesh.types import BMesh, BMFaceSeq

def recalc_face_normals(
bm: BMesh,
/,
*,
faces: BMFaceSeq = ...,
) -> set[str]: ...
110 changes: 110 additions & 0 deletions typings/bmesh-stubs/types/__init__.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
from collections.abc import Iterator, Sequence
from typing import Generic, Optional, TypeVar

from bpy.types import Mesh
from mathutils import Vector

__BMElemSeqElement = TypeVar("__BMElemSeqElement")

class BMElemSeq(Generic[__BMElemSeqElement]):
def __len__(self) -> int: ...
def __getitem__(self, key: int) -> __BMElemSeqElement: ...
def __iter__(self) -> Iterator[__BMElemSeqElement]: ...

class BMLoopUV:
uv: Vector

class BMVert:
index: int
co: Vector

def __getitem__(
self,
value: BMLoopUV,
) -> Vector: ... # ドキュメントには存在しない

class BMLayerItem:
def copy_from(self, other: BMLayerItem) -> None: ...
@property
def name(self) -> str: ...

class BMLayerCollection:
def __getitem__(self, key: str) -> BMLoopUV: ... # ドキュメントに記載はない?
def keys(self) -> Iterator[str]: ...
def values(self) -> Iterator[BMLayerItem]: ...
def items(self) -> Iterator[tuple[str, BMLayerItem]]: ...

class BMLayerAccessLoop:
uv: BMLayerCollection

class BMLayerAccessVert:
shape: BMLayerCollection

class BMVertSeq:
def new(
self,
co: Sequence[float] = (0.0, 0.0, 0.0),
example: Optional[BMVert] = None,
) -> BMVert: ...
@property
def layers(self) -> BMLayerAccessVert: ...

class BMEdge: ...

class BMEdgeSeq:
def new(
self,
verts: tuple[
BMVert,
BMVert,
], # 実際にはSequenceだと思うが、2要素チェックをしたいのでtuple
example: Optional[BMEdge] = None,
) -> BMEdge: ...

class BMLoop:
index: int
@property
def face(self) -> BMFace: ...
@property
def vert(self) -> BMVert: ...
def __getitem__(
self,
uv: BMLoopUV,
) -> BMLoopUV: ... # TODO: ドキュメントに存在しない

class BMLoopSeq:
@property
def layers(self) -> BMLayerAccessLoop: ...

class BMFace:
material_index: int
@property
def loops(self) -> BMElemSeq[BMLoop]: ...

class BMFaceSeq:
def new(
self,
verts: Sequence[BMVert],
example: Optional[BMFace] = None,
) -> BMFace: ...
def __iter__(self) -> Iterator[BMFace]: ...

class BMesh:
@property
def faces(self) -> BMFaceSeq: ...
@property
def edges(self) -> BMEdgeSeq: ...
@property
def verts(self) -> BMVertSeq: ...
@property
def loops(self) -> BMLoopSeq: ...
def free(self) -> None: ...
def to_mesh(self, mesh: Mesh) -> None: ...
def from_mesh(
self,
mesh: Mesh,
face_normals: bool = True,
use_shape_key: bool = False,
shape_key_index: int = 0,
) -> None: ...
def calc_loop_triangles(self) -> list[tuple[BMLoop, ...]]: ... # TODO: 正しい型
9 changes: 9 additions & 0 deletions typings/bpy-stubs/__init__.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from . import app as app
from . import msgbus as msgbus
from . import ops as ops
from . import props as props
from . import types as types
from . import utils as utils

context: types.Context
data: types.BlendData
27 changes: 27 additions & 0 deletions typings/bpy-stubs/app/__init__.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from . import handlers as handlers
from . import timers as timers
from . import translations as translations

debug: bool
debug_depsgraph: bool
debug_depsgraph_build: bool
debug_depsgraph_eval: bool
debug_depsgraph_pretty: bool
debug_depsgraph_tag: bool
debug_depsgraph_time: bool
debug_events: bool
debug_ffmpeg: bool
debug_freestyle: bool
debug_handlers: bool
debug_io: bool
debug_python: bool
debug_simdata: bool
debug_value: bool
debug_wm: bool
tempdir: str
use_event_simulate: bool
build_platform: bytes
build_type: bytes
version_cycle: str
version: tuple[int, int, int]
binary_path: str
13 changes: 13 additions & 0 deletions typings/bpy-stubs/app/handlers/__init__.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from collections.abc import MutableSequence
from typing import Callable

def persistent(function: Callable[[object], None]) -> Callable[[object], None]: ...

# TODO: 引数の型を調べる
depsgraph_update_pre: MutableSequence[Callable[[object], None]]
depsgraph_update_post: MutableSequence[Callable[[object], None]]

save_pre: MutableSequence[Callable[[object], None]]
frame_change_pre: MutableSequence[Callable[[object], None]]
frame_change_post: MutableSequence[Callable[[object], None]]
load_post: MutableSequence[Callable[[object], None]]
8 changes: 8 additions & 0 deletions typings/bpy-stubs/app/timers/__init__.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from typing import Callable, Optional

def register(
function: Callable[[], Optional[float]],
first_interval: float = 0,
persistent: bool = False,
) -> None: ...
def is_registered(function: Callable[[], Optional[float]]) -> bool: ...
10 changes: 10 additions & 0 deletions typings/bpy-stubs/app/translations/__init__.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from typing import Optional

locale: str

def pgettext(msgid: str, msgctxt: Optional[str] = None) -> str: ...
def unregister(module_name: str) -> None: ...
def register(
module_name: str,
dictionary: dict[str, dict[tuple[str, str], str]],
) -> None: ...
1 change: 1 addition & 0 deletions typings/bpy-stubs/context/__init__.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import preferences as preferences
1 change: 1 addition & 0 deletions typings/bpy-stubs/context/preferences/__init__.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import view as view
1 change: 1 addition & 0 deletions typings/bpy-stubs/context/preferences/view/__init__.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
use_translate_interface: bool
10 changes: 10 additions & 0 deletions typings/bpy-stubs/msgbus/__init__.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# TODO: 正しい型
def subscribe_rna(
key: object,
owner: object,
args: object,
notify: object,
options: set[str] = ...,
) -> None: ...
def publish_rna(key: object) -> None: ...
def clear_by_owner(owner: object) -> None: ...
10 changes: 10 additions & 0 deletions typings/bpy-stubs/ops/__init__.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from . import export_scene as export_scene
from . import icyp as icyp
from . import import_scene as import_scene
from . import mesh as mesh
from . import object as object
from . import outliner as outliner
from . import preferences as preferences
from . import uv as uv
from . import vrm as vrm
from . import wm as wm
Loading

0 comments on commit 39e73b6

Please sign in to comment.