Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typestub #2238

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions .github/workflows/type-stub.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Typestub

on:
pull_request:
branches: [ master ]

jobs:
build:
name: Typestub
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.10'
- name: Get packages
run: |
python -m pip install --upgrade pip
pip install flake8
- name: Clone w/ submodules
uses: actions/checkout@v3
with:
submodules: recursive
- name: Install self
run: pip install .
- name: Check typestub
run: ./ci/check_stub.py
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,7 @@ _skbuild

# generated by test scripts
results

# IDEs
.idea/
.vscode/
22 changes: 22 additions & 0 deletions ci/check_stub.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import ast
from pathlib import Path

import arbor

with open(Path(__file__).resolve().parent / "../python/__init__.pyi", "r") as stubfile:
stub = ast.parse(stubfile.read())
typed = {'env'}

for node in stub.body:
if isinstance(node, ast.AnnAssign):
if isinstance(node.target, ast.Name):
typed.add(node.target.id)
elif isinstance(node, ast.ClassDef) or isinstance(node, ast.FunctionDef):
typed.add(node.name)

missing = set(attr for attr in dir(arbor) if not attr.startswith("_")) - typed

if missing:
for attr in missing:
print(f"Missing typedef in `__init__.pyi` for `{attr}`!")
exit(1)
9 changes: 8 additions & 1 deletion python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,14 @@ endif()
add_subdirectory(test)

# Create the Python module in the build directory.
# The module contains the dynamic library, __init__.py and VERSION information.
# The module contains the dynamic library, __init__.py, the .pyi type stubs, py.typed
# marker and VERSION information.
set(python_mod_path "${CMAKE_CURRENT_BINARY_DIR}/arbor")
set_target_properties(pyarb PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${python_mod_path}")
file(COPY "${PROJECT_SOURCE_DIR}/python/__init__.py" DESTINATION "${python_mod_path}")
file(COPY "${PROJECT_SOURCE_DIR}/python/__init__.pyi" DESTINATION "${python_mod_path}")
file(COPY "${PROJECT_SOURCE_DIR}/python/env.pyi" DESTINATION "${python_mod_path}")
file(COPY "${PROJECT_SOURCE_DIR}/python/py.typed" DESTINATION "${python_mod_path}")
file(COPY "${PROJECT_SOURCE_DIR}/VERSION" DESTINATION "${python_mod_path}")

# Set the installation path
Expand Down Expand Up @@ -117,4 +121,7 @@ endif()

install(TARGETS pyarb DESTINATION ${_python_module_install_path})
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/__init__.py DESTINATION ${_python_module_install_path})
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/__init__.pyi DESTINATION ${_python_module_install_path})
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/env.pyi DESTINATION ${_python_module_install_path})
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/py.typed DESTINATION ${_python_module_install_path})
install(FILES ${PROJECT_SOURCE_DIR}/VERSION ${PROJECT_SOURCE_DIR}/README.md ${PROJECT_SOURCE_DIR}/LICENSE DESTINATION ${_python_module_install_path})
Loading
Loading