Skip to content

Commit

Permalink
fix(lib): deprecation warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
jeertmans committed Aug 27, 2024
1 parent 924d821 commit 3ac577f
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 29 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
[#447](https://github.com/jeertmans/manim-slides/pull/447)
- Improved issue templates.
[#456](https://github.com/jeertmans/manim-slides/pull/456)
- Enhancer the error message when the slides folder does not exist.
- Enhanced the error message when the slides folder does not exist.
[#462](https://github.com/jeertmans/manim-slides/pull/462)
- Fixed deprecation warnings.
[#467](https://github.com/jeertmans/manim-slides/pull/467)

(unreleased-fixed)=
### Fixed
Expand Down
25 changes: 12 additions & 13 deletions manim_slides/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
FilePath,
PositiveInt,
PrivateAttr,
conset,
field_serializer,
field_validator,
model_validator,
)
Expand Down Expand Up @@ -47,20 +49,13 @@ def key_id(name: str) -> PositiveInt:
class Key(BaseModel): # type: ignore[misc]
"""Represents a list of key codes, with optionally a name."""

ids: list[PositiveInt] = Field(unique=True)
ids: conset(PositiveInt, min_length=1)
name: Optional[str] = None

__signal: Signal = PrivateAttr(default_factory=Signal)

@field_validator("ids")
@classmethod
def ids_is_non_empty_set(cls, ids: set[Any]) -> set[Any]:
if len(ids) <= 0:
raise ValueError("Key's ids must be a non-empty set")
return ids

def set_ids(self, *ids: int) -> None:
self.ids = list(set(ids))
self.ids = set(ids)

def match(self, key_id: int) -> bool:
m = key_id in self.ids
Expand All @@ -77,6 +72,10 @@ def signal(self) -> Signal:
def connect(self, function: Receiver) -> None:
self.__signal.connect(function)

@field_serializer("ids")
def serialize_dt(self, ids: set[int]) -> list[int]:
return list(self.ids)


class Keys(BaseModel): # type: ignore[misc]
QUIT: Key = Field(default_factory=lambda: Key(ids=[key_id("Q")], name="QUIT"))
Expand Down Expand Up @@ -180,7 +179,7 @@ def __wrapper__(*args: Any, **kwargs: Any) -> Any: # noqa: N807
fun_kwargs = {
key: value
for key, value in kwargs.items()
if key not in cls.__fields__
if key not in cls.model_fields
}
fun_kwargs[arg_name] = cls(**kwargs)
return fun(*args, **fun_kwargs)
Expand All @@ -194,7 +193,7 @@ def __wrapper__(*args: Any, **kwargs: Any) -> Any: # noqa: N807
default=field_info.default,
annotation=field_info.annotation,
)
for field_name, field_info in cls.__fields__.items()
for field_name, field_info in cls.model_fields.items()
]

sig = sig.replace(parameters=parameters)
Expand Down Expand Up @@ -231,7 +230,7 @@ def from_base_slide_config_and_animation_indices(
return cls(
start_animation=start_animation,
end_animation=end_animation,
**base_slide_config.dict(),
**base_slide_config.model_dump(),
)

@field_validator("start_animation", "end_animation")
Expand Down Expand Up @@ -277,7 +276,7 @@ class SlideConfig(BaseSlideConfig):
def from_pre_slide_config_and_files(
cls, pre_slide_config: PreSlideConfig, file: Path, rev_file: Path
) -> "SlideConfig":
return cls(file=file, rev_file=rev_file, **pre_slide_config.dict())
return cls(file=file, rev_file=rev_file, **pre_slide_config.model_dump())


class PresentationConfig(BaseModel): # type: ignore[misc]
Expand Down
4 changes: 2 additions & 2 deletions manim_slides/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ def prefix(i: int) -> str:
with open(dest, "w") as f:
revealjs_template = Template(self.load_template())

options = self.dict()
options = self.model_dump()
options["assets_dir"] = assets_dir

has_notes = any(
Expand Down Expand Up @@ -692,7 +692,7 @@ def convert(
try:
cls = Converter.from_string(fmt)
except KeyError:
logger.warn(
logger.warning(
f"Could not guess conversion format from {dest!s}, defaulting to HTML."
)
cls = RevealJS
Expand Down
2 changes: 1 addition & 1 deletion manim_slides/ipython/ipython_magic.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ def construct(self):
# TODO: FIXME
# Seems like files are blocked so date-uri is the only working option...
if kwargs.get("data_uri", "false").lower().strip() == "false":
logger.warn(
logger.warning(
"data_uri option is currently automatically enabled, "
"because using local video files does not seem to work properly."
)
Expand Down
2 changes: 1 addition & 1 deletion manim_slides/present/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def _list_scenes(folder: Path) -> list[str]:
except (
Exception
) as e: # Could not parse this file as a proper presentation config
logger.warn(
logger.warning(
f"Something went wrong with parsing presentation config `{filepath}`: {e}"
)

Expand Down
4 changes: 2 additions & 2 deletions manim_slides/present/player.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ def current_presentation_index(self, index: int) -> None:
elif -self.presentations_count <= index < 0:
self.__current_presentation_index = index + self.presentations_count
else:
logger.warn(f"Could not set presentation index to {index}.")
logger.warning(f"Could not set presentation index to {index}.")
return

self.presentation_changed.emit()
Expand All @@ -343,7 +343,7 @@ def current_slide_index(self, index: int) -> None:
elif -self.current_slides_count <= index < 0:
self.__current_slide_index = index + self.current_slides_count
else:
logger.warn(f"Could not set slide index to {index}.")
logger.warning(f"Could not set slide index to {index}.")
return

self.slide_changed.emit()
Expand Down
2 changes: 1 addition & 1 deletion manim_slides/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def _filter(files: list[Path]) -> Iterator[Path]:
if len(container.streams.video) > 0:
yield file
else:
logger.warn(
logger.warning(
f"Skipping video file {file} because it does "
"not contain any video stream. "
"This is probably caused by Manim, see: "
Expand Down
4 changes: 2 additions & 2 deletions manim_slides/wizard/wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def __init__(self, config: Config):

self.layout = QGridLayout()

for i, (key, value) in enumerate(self.config.keys.dict().items()):
for i, (key, value) in enumerate(self.config.keys.model_dump().items()):
# Create label for key name information
label = QLabel()
key_info = value["name"] or key
Expand Down Expand Up @@ -97,7 +97,7 @@ def closeEvent(self, event: Any) -> None: # noqa: N802

def save_config(self) -> None:
try:
Config.model_validate(self.config.dict())
Config.model_validate(self.config.model_dump())
except ValueError:
msg = QMessageBox()
msg.setIcon(QMessageBox.Critical)
Expand Down
8 changes: 7 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ dependencies = [
"rtoml==0.9.0;sys_platform=='win32' and python_version<'3.13'",
"rtoml>=0.9.0;sys_platform!='win32' or python_version>='3.13'",
"tqdm>=4.64.1",
"pytest-missing-modules>=0.1.0",
]
description = "Tool for live presentations using manim"
dynamic = ["readme", "version"]
Expand Down Expand Up @@ -70,6 +69,7 @@ tests = [
"pytest>=7.4.0",
"pytest-cov>=4.1.0",
"pytest-env>=0.8.2",
"pytest-missing-modules>=0.1.0",
"pytest-qt>=4.2.0",
]

Expand Down Expand Up @@ -185,6 +185,12 @@ env = [
"QT_API=pyside6",
"QT_QPA_PLATFORM=offscreen",
]
filterwarnings = [
"error",
'''ignore:'audioop' is deprecated:DeprecationWarning''',
'ignore:pkg_resources is deprecated as an API:DeprecationWarning',
'ignore::DeprecationWarning:pkg_resources.*:',
]

[tool.ruff]
extend-exclude = ["manim_slides/resources.py"]
Expand Down
10 changes: 5 additions & 5 deletions tests/test_wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def exec_patched(self: QMessageBox) -> None:

monkeypatch.setattr(QMessageBox, "exec", exec_patched)

for i, (key, _) in enumerate(wizard.config.keys.dict().items()):
for i, (key, _) in enumerate(wizard.config.keys.model_dump().items()):
open_dialog(i, getattr(wizard.config.keys, key))

wizard.button_box.accepted.emit()
Expand All @@ -89,7 +89,7 @@ def test_init() -> None:

assert results.exit_code == 0
assert CONFIG_PATH.exists()
assert Config().dict() == Config.from_file(CONFIG_PATH).dict()
assert Config().model_dump() == Config.from_file(CONFIG_PATH).model_dump()


def test_init_custom_path() -> None:
Expand All @@ -106,7 +106,7 @@ def test_init_custom_path() -> None:
assert results.exit_code == 0
assert not CONFIG_PATH.exists()
assert custom_path.exists()
assert Config().dict() == Config.from_file(custom_path).dict()
assert Config().model_dump() == Config.from_file(custom_path).model_dump()


def test_init_path_exists() -> None:
Expand All @@ -120,7 +120,7 @@ def test_init_path_exists() -> None:

assert results.exit_code == 0
assert CONFIG_PATH.exists()
assert Config().dict() == Config.from_file(CONFIG_PATH).dict()
assert Config().model_dump() == Config.from_file(CONFIG_PATH).model_dump()

results = runner.invoke(init, input="o")

Expand Down Expand Up @@ -156,7 +156,7 @@ def exec_patched(self: QApplication) -> None:

assert results.exit_code == 0
assert CONFIG_PATH.exists()
assert Config().dict() == Config.from_file(CONFIG_PATH).dict()
assert Config().model_dump() == Config.from_file(CONFIG_PATH).model_dump()


def test_wizard_closed_without_saving(monkeypatch: MonkeyPatch) -> None:
Expand Down

0 comments on commit 3ac577f

Please sign in to comment.