Skip to content

Commit

Permalink
begin strong typing with mypy
Browse files Browse the repository at this point in the history
  • Loading branch information
BradyAJohnston committed May 25, 2024
1 parent a5853c2 commit bb61ade
Show file tree
Hide file tree
Showing 21 changed files with 785 additions and 453 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/mypy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: mypy
on:
push: [push, pull_request]
jobs:
ruff:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: chartboost/ruff-action@v1

mypy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: 3.11.7
cache: pip

- name: Build docs using blender
run: |
wget -nv https://download.blender.org/release/Blender4.1/blender-4.1.0-linux-x64.tar.xz
tar -xf blender-4.1.0-linux-x64.tar.xz
blender-4.1.0-linux-x64/blender --version
blender-4.1.0-linux-x64/blender -b --python tests/python.py -- -m pip install poetry
blender-4.1.0-linux-x64/blender -b --python tests/python.py -- -m poetry install --with dev
blender-4.1.0-linux-x64/blender -b --python tests/python.py -- -m mypy .
2 changes: 1 addition & 1 deletion build.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@


# zips up the template file
def zip_template():
def zip_template() -> None:
# Define the directory and zip file paths
dir_path = "molecularnodes/assets/template/Molecular Nodes"
zip_file_path = "molecularnodes/assets/template/Molecular Nodes.zip"
Expand Down
2 changes: 1 addition & 1 deletion docs/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import os


def main():
def main() -> None:
python = os.path.realpath(sys.executable)

commands = [f"{python} -m pip install .", f"{python} -m pip install quartodoc"]
Expand Down
15 changes: 7 additions & 8 deletions molecularnodes/blender/coll.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import bpy
from typing import Optional


def mn():
def mn() -> bpy.types.Collection:
"""Return the MolecularNodes Collection
The collection called 'MolecularNodes' inside the Blender scene is returned. If the
Expand All @@ -14,15 +15,15 @@ def mn():
return coll


def armature(name="MN_armature"):
def armature(name: str = "MN_armature") -> bpy.types.Collection:
coll = bpy.data.collections.get(name)
if not coll:
coll = bpy.data.collections.new(name)
mn().children.link(coll)
return coll


def data(suffix=""):
def data(suffix: str = "") -> bpy.types.Collection:
"""A collection for storing MN related data objects."""
name = f"MN_data{suffix}"

Expand All @@ -32,13 +33,11 @@ def data(suffix=""):
mn().children.link(collection)

# disable the view of the data collection
bpy.context.view_layer.layer_collection.children["MolecularNodes"].children[
name
].exclude = True
bpy.context.view_layer.layer_collection.children["MolecularNodes"].children[name].exclude = True
return collection


def frames(name="", parent=None, suffix="_frames"):
def frames(name: str = "", parent: Optional[bpy.types.Object] = None, suffix: str = "_frames") -> bpy.types.Collection:
"""Create a Collection for Frames of a Trajectory
Args:
Expand All @@ -55,7 +54,7 @@ def frames(name="", parent=None, suffix="_frames"):
return coll_frames


def cellpack(name="", parent=None, fallback=False):
def cellpack(name: str = "", parent: Optional[bpy.types.Object] = None, fallback: bool = False) -> bpy.types.Collection:
full_name = f"cellpack_{name}"
coll = bpy.data.collections.get(full_name)
if coll and fallback:
Expand Down
Loading

0 comments on commit bb61ade

Please sign in to comment.