deckz
Advanced tools
| from pathlib import Path | ||
| from . import app | ||
| @app.command() | ||
| def upgrade(*, workdir: Path = Path()) -> None: | ||
| """Transform a deckz repo to match the new conventions. | ||
| Args: | ||
| workdir: Path to move into before running the command. | ||
| """ | ||
| from itertools import chain | ||
| from shutil import move | ||
| from sys import stderr | ||
| from rich.console import Console | ||
| from ..configuring.settings import GlobalSettings | ||
| console = Console(file=stderr) | ||
| old_settings = Path("settings.yml") | ||
| if old_settings.exists(): | ||
| move(old_settings, "deckz.yml") | ||
| settings = GlobalSettings.from_yaml(workdir) | ||
| console.print("Renaming files (config -> variables, targets -> deck)") | ||
| for old_path in chain( | ||
| settings.paths.git_dir.rglob("global-variables.yml"), | ||
| settings.paths.git_dir.rglob("company-variables.yml"), | ||
| settings.paths.git_dir.rglob("deck-variables.yml"), | ||
| (settings.paths.user_config_dir / "user-variables.yml",), | ||
| ): | ||
| new_path = old_path.parent / "variables.yml" | ||
| if old_path.exists(): | ||
| move(old_path, new_path) | ||
| console.print( | ||
| " :white_check_mark:" | ||
| f"{old_path}\n" | ||
| f" → [link=file://{new_path}]{new_path}[/link]" | ||
| ) |
| deck_title: A Bold Case |
| company_logo: img/logo.png | ||
| company_logo_height: 1cm | ||
| company_name: Company | ||
| company_website: https://www.company.com |
| presentation_size: 10pt | ||
| user_name: "John Doe" | ||
| user_email: "john@doe.me" |
+1
-1
| Metadata-Version: 2.4 | ||
| Name: deckz | ||
| Version: 23.0.0 | ||
| Version: 24.0.0 | ||
| Summary: Tool to handle multiple beamer decks. | ||
@@ -5,0 +5,0 @@ Author-email: m09 <142691+m09@users.noreply.github.com>, NyxAether <contact.nyxhemera@gmail.com> |
+1
-1
@@ -33,3 +33,3 @@ [project] | ||
| requires-python = ">= 3.12" | ||
| version = "23.0.0" | ||
| version = "24.0.0" | ||
@@ -36,0 +36,0 @@ [dependency-groups] |
@@ -224,7 +224,3 @@ from pathlib import Path | ||
| frozenset( | ||
| [ | ||
| settings.paths.tikz_dir, | ||
| settings.paths.plt_dir, | ||
| settings.paths.plotly_dir | ||
| ] | ||
| [settings.paths.tikz_dir, settings.paths.plt_dir, settings.paths.plotly_dir] | ||
| ), | ||
@@ -231,0 +227,0 @@ frozenset( |
| from functools import reduce | ||
| from pathlib import Path | ||
| from typing import Annotated, Any, Self | ||
| from typing import Annotated, Any, Literal, Self | ||
@@ -16,4 +16,3 @@ from appdirs import user_config_dir as appdirs_user_config_dir | ||
| from .. import app_name | ||
| from ..exceptions import DeckzError | ||
| from ..utils import get_git_dir, intermediate_dirs, load_all_yamls | ||
| from ..utils import dirs_hierarchy, get_git_dir, load_all_yamls | ||
@@ -47,2 +46,3 @@ | ||
| _Path = Annotated[Path, BeforeValidator(_convert), AfterValidator(Path.resolve)] | ||
| _user_config_dir = Path(appdirs_user_config_dir(app_name)).resolve() | ||
@@ -55,2 +55,3 @@ | ||
| current_dir: _Path | ||
| user_config_dir: Literal[_user_config_dir] = _user_config_dir | ||
| git_dir: _Path = Field( | ||
@@ -74,6 +75,2 @@ default_factory=lambda data: get_git_dir(data["current_dir"]) | ||
| jinja2_main_template: _Path = "{jinja2_dir}/main.tex" | ||
| user_config_dir: _Path = Field( | ||
| default_factory=lambda: Path(appdirs_user_config_dir(app_name)) | ||
| ) | ||
| global_variables: _Path = "{git_dir}/global-variables.yml" | ||
| github_issues: _Path = "{user_config_dir}/github-issues.yml" | ||
@@ -83,3 +80,2 @@ mails: _Path = "{user_config_dir}/mails.yml" | ||
| gdrive_credentials: _Path = "{user_config_dir}/gdrive-credentials.pickle" | ||
| user_variables: _Path = "{user_config_dir}/user-variables.yml" | ||
@@ -92,17 +88,2 @@ def model_post_init(self, __context: Any) -> None: | ||
| def _company_variables_factory(data: dict[str, Any]) -> Path: | ||
| if not data["current_dir"].relative_to(data["git_dir"]).match("*/*"): | ||
| msg = ( | ||
| f"not deep enough from root {data['git_dir']}. " | ||
| "Please follow the directory hierarchy root > company > deck and " | ||
| "invoke this tool from the deck directory" | ||
| ) | ||
| raise DeckzError(msg) | ||
| return ( | ||
| data["git_dir"] | ||
| / data["current_dir"].relative_to(data["git_dir"]).parts[0] | ||
| / "company-variables.yml" | ||
| ) | ||
| class DeckPaths(GlobalPaths): | ||
@@ -112,5 +93,2 @@ build_dir: _Path = "{current_dir}/.build" | ||
| local_latex_dir: _Path = "{current_dir}/latex" | ||
| company_variables: _Path = Field(default_factory=_company_variables_factory) | ||
| deck_variables: _Path = "{current_dir}/deck-variables.yml" | ||
| session_variables: _Path = "{current_dir}/session-variables.yml" | ||
| deck_definition: _Path = "{current_dir}/deck.yml" | ||
@@ -129,9 +107,8 @@ | ||
| git_dir = get_git_dir(resolved_path).resolve() | ||
| if not resolved_path.is_relative_to(git_dir): | ||
| msg = f"{path} is not relative to {git_dir}, cannot load settings" | ||
| raise DeckzError(msg) | ||
| content: dict[str, Any] = reduce( | ||
| lambda a, b: {**a, **b}, | ||
| load_all_yamls( | ||
| p / "deckz.yml" for p in intermediate_dirs(git_dir, resolved_path) | ||
| d | ||
| for p in dirs_hierarchy(git_dir, _user_config_dir, resolved_path) | ||
| if (d := p / "deckz.yml").is_file() | ||
| ), | ||
@@ -138,0 +115,0 @@ {}, |
| from functools import reduce | ||
| from typing import Any | ||
| from ..utils import load_all_yamls | ||
| from .settings import DeckSettings | ||
| from ..utils import dirs_hierarchy, load_all_yamls | ||
| from .settings import GlobalSettings | ||
| def get_variables(settings: DeckSettings) -> dict[str, Any]: | ||
| def get_variables(settings: GlobalSettings) -> dict[str, Any]: | ||
| return reduce( | ||
| lambda a, b: {**a, **b}, | ||
| load_all_yamls( | ||
| [ | ||
| settings.paths.session_variables, | ||
| settings.paths.deck_variables, | ||
| settings.paths.company_variables, | ||
| settings.paths.user_variables, | ||
| settings.paths.global_variables, | ||
| ] | ||
| d | ||
| for p in dirs_hierarchy( | ||
| settings.paths.git_dir, | ||
| settings.paths.user_config_dir, | ||
| settings.paths.current_dir, | ||
| ) | ||
| if (d := p / "variables.yml").is_file() | ||
| ), | ||
| {}, | ||
| ) |
+13
-0
@@ -69,2 +69,15 @@ """Provide general utility functions that would not fit in other modules.""" | ||
| def dirs_hierarchy( | ||
| git_dir: Path, user_config_dir: Path, current_dir: Path | ||
| ) -> Iterator[Path]: | ||
| from itertools import islice | ||
| yield git_dir | ||
| yield user_config_dir | ||
| if current_dir.is_relative_to(git_dir): | ||
| yield from islice(intermediate_dirs(git_dir, current_dir), 1, None) | ||
| else: | ||
| yield current_dir | ||
| def intermediate_dirs(start: Path, end: Path) -> Iterator[Path]: | ||
@@ -71,0 +84,0 @@ start = start.resolve() |
| import sys # noqa: F401 | ||
| from pathlib import Path | ||
| from shutil import copytree | ||
| from shutil import copytree, move | ||
| from typing import Any | ||
@@ -19,3 +19,6 @@ from unittest.mock import patch | ||
| tmp_dir = tmp_path / "data" | ||
| tmp_user_dir = tmp_path / "user" | ||
| tmp_user_dir.mkdir() | ||
| copytree(data_dir, tmp_dir) | ||
| move(tmp_dir / "user-variables.yml", tmp_user_dir / "variables.yml") | ||
| init_repository(str(tmp_dir)) | ||
@@ -22,0 +25,0 @@ working_dir = tmp_dir / "company" / "abc" |
@@ -0,2 +1,3 @@ | ||
| presentation_size: 10pt | ||
| user_name: "John Doe" | ||
| user_email: "john@doe.me" |
| deck_title: A Bold Case |
| company_logo: img/logo.png | ||
| company_logo_height: 1cm | ||
| company_name: Company | ||
| company_website: https://www.company.com |
| presentation_size: 10pt |
| company_name: Company Name | ||
| company_logo: logo_company_name | ||
| company_logo_height: 1cm | ||
| company_website: https://www.company-name.com/ |
| deck_title: Some Deck Title | ||
| deck_acronym: SDT |
| presentation_size: 10pt |
| trainer_name: John Doe | ||
| trainer_email: john@doe.me | ||
| trainer_activity: Freelance ML Consulting | ||
| trainer_specialization: NLP, NLU | ||
| trainer_training: MSc in ML |
Alert delta unavailable
Currently unable to show alert delta for PyPI packages.
376332
0.12%3293
0.64%82
-3.53%