Skip to content

Commit

Permalink
chore(deps): add Python 3.12 support (#3395)
Browse files Browse the repository at this point in the history
* chore(deps): add Python 3.11 and 3.12 support


chore(deps): update lock file


chore(deps): remove colour


fix(deps): force NumPy version


fix(deps): relax constraints


chore(deps): update lock file

* fix(deps): make poetry happy

* fix(ci): skia pathops on 3.12

* fix(test): doctest skip

* disable python 3.8 pipeline

* removed get_parameters, replaced by direct call to inspect

* black

---------

Co-authored-by: Benjamin Hackl <[email protected]>
  • Loading branch information
jeertmans and behackl authored Nov 4, 2023
1 parent 652f1b3 commit 8fe1665
Show file tree
Hide file tree
Showing 8 changed files with 277 additions and 141 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-22.04, macos-latest, windows-latest]
python: ["3.8", "3.9", "3.10", "3.11"]
python: ["3.9", "3.10", "3.11", "3.12"]

steps:
- name: Checkout the repository
Expand Down
6 changes: 2 additions & 4 deletions manim/animation/speedmodifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@

from __future__ import annotations

import inspect
import types
from typing import Callable

from numpy import piecewise

from manim.utils.simple_functions import get_parameters

from ..animation.animation import Animation, Wait, prepare_animation
from ..animation.composition import AnimationGroup
from ..mobject.mobject import Mobject, Updater, _AnimationBuilder
Expand Down Expand Up @@ -260,8 +259,7 @@ def add_updater(
:class:`.ChangeSpeed`
:meth:`.Mobject.add_updater`
"""
parameters = get_parameters(update_function)
if "dt" in parameters:
if "dt" in inspect.signature(update_function).parameters:
mobject.add_updater(
lambda mob, dt: update_function(
mob, ChangeSpeed.dt if ChangeSpeed.is_changing_dt else dt
Expand Down
17 changes: 11 additions & 6 deletions manim/mobject/mobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@


import copy
import inspect
import itertools as it
import math
import operator as op
Expand Down Expand Up @@ -36,7 +37,6 @@
from ..utils.exceptions import MultiAnimationOverrideException
from ..utils.iterables import list_update, remove_list_redundancies
from ..utils.paths import straight_path
from ..utils.simple_functions import get_parameters
from ..utils.space_ops import angle_between_vectors, normalize, rotation_matrix

# TODO: Explain array_attrs
Expand Down Expand Up @@ -847,8 +847,7 @@ def update(self, dt: float = 0, recursive: bool = True) -> Self:
if self.updating_suspended:
return self
for updater in self.updaters:
parameters = get_parameters(updater)
if "dt" in parameters:
if "dt" in inspect.signature(updater).parameters:
updater(self, dt)
else:
updater(self)
Expand All @@ -873,7 +872,11 @@ def get_time_based_updaters(self) -> list[TimeBasedUpdater]:
:meth:`has_time_based_updater`
"""
return [updater for updater in self.updaters if "dt" in get_parameters(updater)]
return [
updater
for updater in self.updaters
if "dt" in inspect.signature(updater).parameters
]

def has_time_based_updater(self) -> bool:
"""Test if ``self`` has a time based updater.
Expand All @@ -889,7 +892,9 @@ def has_time_based_updater(self) -> bool:
:meth:`get_time_based_updaters`
"""
return any("dt" in get_parameters(updater) for updater in self.updaters)
return any(
"dt" in inspect.signature(updater).parameters for updater in self.updaters
)

def get_updaters(self) -> list[Updater]:
"""Return all updaters.
Expand Down Expand Up @@ -982,7 +987,7 @@ def construct(self):
else:
self.updaters.insert(index, update_function)
if call_updater:
parameters = get_parameters(update_function)
parameters = inspect.signature(update_function).parameters
if "dt" in parameters:
update_function(self, 0)
else:
Expand Down
4 changes: 2 additions & 2 deletions manim/mobject/opengl/opengl_mobject.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

import copy
import inspect
import itertools as it
import random
import sys
Expand Down Expand Up @@ -37,7 +38,6 @@
uniq_chain,
)
from manim.utils.paths import straight_path
from manim.utils.simple_functions import get_parameters
from manim.utils.space_ops import (
angle_between_vectors,
normalize,
Expand Down Expand Up @@ -1383,7 +1383,7 @@ def get_family_updaters(self):
return list(it.chain(*(sm.get_updaters() for sm in self.get_family())))

def add_updater(self, update_function, index=None, call_updater=False):
if "dt" in get_parameters(update_function):
if "dt" in inspect.signature(update_function).parameters:
updater_list = self.time_based_updaters
else:
updater_list = self.non_time_updaters
Expand Down
4 changes: 2 additions & 2 deletions manim/renderer/shader.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import inspect
import re
import textwrap
from pathlib import Path
Expand All @@ -9,7 +10,6 @@

from .. import config
from ..utils import opengl
from ..utils.simple_functions import get_parameters

SHADER_FOLDER = Path(__file__).parent / "shaders"
shader_program_cache: dict = {}
Expand Down Expand Up @@ -199,7 +199,7 @@ def get_updaters(self):
return self.time_based_updaters + self.non_time_updaters

def add_updater(self, update_function, index=None, call_updater=True):
if "dt" in get_parameters(update_function):
if "dt" in inspect.signature(update_function).parameters:
updater_list = self.time_based_updaters
else:
updater_list = self.non_time_updaters
Expand Down
18 changes: 0 additions & 18 deletions manim/utils/simple_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"binary_search",
"choose",
"clip",
"get_parameters",
"sigmoid",
]

Expand Down Expand Up @@ -117,23 +116,6 @@ def clip(a, min_a, max_a):
return a


def get_parameters(function: Callable) -> MappingProxyType[str, inspect.Parameter]:
"""Return the parameters of ``function`` as an ordered mapping of parameters'
names to their corresponding ``Parameter`` objects.
Examples
--------
::
>>> get_parameters(get_parameters)
mappingproxy(OrderedDict([('function', <Parameter "function: 'Callable'">)]))
>>> tuple(get_parameters(choose))
('n', 'k')
"""
return inspect.signature(function).parameters


def sigmoid(x: float) -> float:
r"""Returns the output of the logistic function.
Expand Down
Loading

0 comments on commit 8fe1665

Please sign in to comment.