Skip to content
Merged
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
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.14.14
rev: v0.16.1
hooks:
- id: ruff
args: [--fix]
Expand Down
12 changes: 8 additions & 4 deletions animate/scenes/blender/load_body.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

from __future__ import annotations

import importlib.util
import json
import sys
from pathlib import Path
Expand All @@ -24,6 +25,11 @@
SCHEMA_ID = 'solsys.blender_body_scene/v1'


def _bpyAvailable() -> bool:
"""True when running inside Blender (avoid unused ``import bpy`` for CodeQL)."""
return importlib.util.find_spec('bpy') is not None


def _argvAfterDoubleDash(argv: list[str]) -> list[str]:
if '--' in argv:
return argv[argv.index('--') + 1 :]
Expand Down Expand Up @@ -174,7 +180,5 @@ def main(argv: list[str] | None = None) -> int:
if __name__ == '__main__':
exitCode = main()
# SystemExit terminates the Blender GUI process. Only exit for host dry-runs.
try:
import bpy # type: ignore[import-not-found] # noqa: F401
except ImportError:
raise SystemExit(exitCode) from None
if not _bpyAvailable():
raise SystemExit(exitCode)
16 changes: 9 additions & 7 deletions animate/scenes/blender/render_flyby.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

from __future__ import annotations

import importlib.util
import json
import math
import sys
Expand All @@ -18,6 +19,11 @@
JOB_SCHEMA_ID = 'solsys.blender_flyby_job/v1'


def _bpyAvailable() -> bool:
"""True when running inside Blender (avoid unused ``import bpy`` for CodeQL)."""
return importlib.util.find_spec('bpy') is not None


def _argvAfterDoubleDash(argv: list[str]) -> list[str]:
if '--' in argv:
return argv[argv.index('--') + 1 :]
Expand Down Expand Up @@ -220,9 +226,7 @@ def main(argv: list[str] | None = None) -> int:
f'frames={len(job["frames"])} resolution={job["resolution"]}'
)

try:
import bpy # type: ignore[import-not-found] # noqa: F401
except ImportError:
if not _bpyAvailable():
print('bpy not available — dry-run validation only.')
return 0

Expand All @@ -233,10 +237,8 @@ def main(argv: list[str] | None = None) -> int:

if __name__ == '__main__':
exitCode = main()
try:
import bpy # type: ignore[import-not-found] # noqa: F401
except ImportError:
raise SystemExit(exitCode) from None
if not _bpyAvailable():
raise SystemExit(exitCode)
# Background mode exits on its own after the script; GUI should not SystemExit.
if '--background' in sys.argv or '-b' in sys.argv:
raise SystemExit(exitCode)
12 changes: 7 additions & 5 deletions solsys/physics/catalogs/star_catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@ def _loadStars(self, csvPath: str) -> pd.DataFrame:
starsFrame['rightAscensionDeg'] = coordinates.apply(lambda pair: pair[0])
starsFrame['declinationDeg'] = coordinates.apply(lambda pair: pair[1])
cartesianCoords = starsFrame.apply(
lambda row: OrbitCalculator.equatorialToCartesianAu(
row['rightAscensionDeg'], row['declinationDeg'], row['distanceAu']
)
if pd.notna(row['rightAscensionDeg']) and pd.notna(row['declinationDeg'])
else (np.nan, np.nan, np.nan),
lambda row: (
OrbitCalculator.equatorialToCartesianAu(
row['rightAscensionDeg'], row['declinationDeg'], row['distanceAu']
)
if pd.notna(row['rightAscensionDeg']) and pd.notna(row['declinationDeg'])
else (np.nan, np.nan, np.nan)
),
axis=1,
)
starsFrame['positionX'] = cartesianCoords.apply(lambda coord: coord[0])
Expand Down
Loading