fix(lib/cli): relative paths, empty slides, and tests (#223)

* fix(lib/cli): relative paths, empty slides, and tests

This fixes two issues:

1. Empty slides are now reported as error, to prevent indexing error;
2. Changing the folder path will now produce an absolute path to slides, which was not the case before and would lead to a "file does not exist error".

A few tests were also added to cover those

* fix(lib): fix from_file, remove useless field, and more

* chore(tests): remove print

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
Jérome Eertmans
2023-07-24 13:58:54 +02:00
committed by GitHub
parent 2b6240c4d3
commit 529a6c534f
14 changed files with 200 additions and 18 deletions

View File

@ -1,6 +1,6 @@
import os
import sys
from functools import partial
from pathlib import Path
from typing import Any
import click
@ -102,7 +102,7 @@ class Wizard(QWidget): # type: ignore
def saveConfig(self) -> None:
try:
Config.parse_obj(self.config.dict())
Config.model_validate(self.config.dict())
except ValueError:
msg = QMessageBox()
msg.setIcon(QMessageBox.Critical)
@ -130,7 +130,7 @@ class Wizard(QWidget): # type: ignore
@config_options
@click.help_option("-h", "--help")
@verbosity_option
def wizard(config_path: str, force: bool, merge: bool) -> None:
def wizard(config_path: Path, force: bool, merge: bool) -> None:
"""Launch configuration wizard."""
return _init(config_path, force, merge, skip_interactive=False)
@ -140,18 +140,18 @@ def wizard(config_path: str, force: bool, merge: bool) -> None:
@click.help_option("-h", "--help")
@verbosity_option
def init(
config_path: str, force: bool, merge: bool, skip_interactive: bool = False
config_path: Path, force: bool, merge: bool, skip_interactive: bool = False
) -> None:
"""Initialize a new default configuration file."""
return _init(config_path, force, merge, skip_interactive=True)
def _init(
config_path: str, force: bool, merge: bool, skip_interactive: bool = False
config_path: Path, force: bool, merge: bool, skip_interactive: bool = False
) -> None:
"""Actual initialization code for configuration file, with optional interactive mode."""
if os.path.exists(config_path):
if config_path.exists():
click.secho(f"The `{CONFIG_PATH}` configuration file exists")
if not force and not merge:
@ -175,8 +175,8 @@ def _init(
logger.debug("Merging new config into `{config_path}`")
if not skip_interactive:
if os.path.exists(config_path):
config = Config.parse_file(config_path)
if config_path.exists():
config = Config.from_file(config_path)
app = QApplication(sys.argv)
app.setApplicationName("Manim Slides Wizard")
@ -187,9 +187,8 @@ def _init(
config = window.config
if merge:
config = Config.parse_file(config_path).merge_with(config)
config = Config.from_file(config_path).merge_with(config)
with open(config_path, "w") as config_file:
config_file.write(config.json(indent=2))
config.to_file(config_path)
click.secho(f"Configuration file successfully saved to `{config_path}`")