diff --git a/.forgejo/workflows/ci.yml b/.forgejo/workflows/ci.yml index 92092a6..7d7a63b 100644 --- a/.forgejo/workflows/ci.yml +++ b/.forgejo/workflows/ci.yml @@ -21,6 +21,3 @@ jobs: - name: Test with PyTest run: nix develop .#impure --command bash -c "uv run pytest --junit-xml test-report.xml" - - - name: Check with PyRight - run: nix develop .#impure --command bash -c "uv run pyright" diff --git a/flake.nix b/flake.nix index 0e39ef3..669701a 100644 --- a/flake.nix +++ b/flake.nix @@ -88,12 +88,14 @@ # Package a virtual environment as our main application. # # Enable no optional dependencies for production build. - packages.x86_64-linux = let - streamer = pythonSet.mkVirtualEnv "streamer-env" workspace.deps.default; - in { - inherit streamer; - default = streamer; - }; + packages.x86_64-linux = + let + streamer = pythonSet.mkVirtualEnv "streamer-env" workspace.deps.default; + in + { + inherit streamer; + default = streamer; + }; # Make streamer runnable with `nix run` apps.x86_64-linux = { @@ -116,18 +118,17 @@ pre-commit bashInteractive ]; - env = - { - # Prevent uv from managing Python downloads - UV_PYTHON_DOWNLOADS = "never"; - # Force uv to use nixpkgs Python interpreter - UV_PYTHON = python.interpreter; - } - // lib.optionalAttrs pkgs.stdenv.isLinux { - # Python libraries often load native shared objects using dlopen(3). - # Setting LD_LIBRARY_PATH makes the dynamic library loader aware of libraries without using RPATH for lookup. - LD_LIBRARY_PATH = lib.makeLibraryPath pkgs.pythonManylinuxPackages.manylinux1; - }; + env = { + # Prevent uv from managing Python downloads + UV_PYTHON_DOWNLOADS = "never"; + # Force uv to use nixpkgs Python interpreter + UV_PYTHON = python.interpreter; + } + // lib.optionalAttrs pkgs.stdenv.isLinux { + # Python libraries often load native shared objects using dlopen(3). + # Setting LD_LIBRARY_PATH makes the dynamic library loader aware of libraries without using RPATH for lookup. + LD_LIBRARY_PATH = lib.makeLibraryPath pkgs.pythonManylinuxPackages.manylinux1; + }; shellHook = '' unset PYTHONPATH ''; diff --git a/src/streamer/__init__.py b/src/streamer/__init__.py index c39eede..dbb9151 100644 --- a/src/streamer/__init__.py +++ b/src/streamer/__init__.py @@ -1,43 +1,74 @@ import glob import os -import typer +from datetime import datetime +from shutil import move +from typing import Annotated, Generator + import click +import typer from rich import print from rich.markdown import Markdown from rich.panel import Panel -from shutil import move -from datetime import datetime - -from streamer.parse.parse import parse_markdown_file -from streamer.query.task import find_by_markers +from streamer.localize import ( + LocalizedShard, + RepositoryConfiguration, + localize_stream_file, +) +from streamer.localize.preconfigured_configurations import TaskConfiguration +from streamer.parse import parse_markdown_file +from streamer.query import find_shard_by_position from streamer.settings import Settings app = typer.Typer() -@app.command() -def todo() -> None: +def all_files(config: RepositoryConfiguration) -> Generator[LocalizedShard]: for file_name in glob.glob(f"{glob.escape(Settings().base_folder)}/*.md"): with open(file_name, "r") as file: file_content = file.read() - sharded_document = parse_markdown_file(file_name, file_content) - if sharded_document.shard: - open_tasks = find_by_markers(sharded_document.shard, ["Task"], ["Done"]) + if shard := localize_stream_file( + parse_markdown_file(file_name, file_content), config + ): + yield shard - for task_shard in open_tasks: - print( - Panel( - Markdown( - "\n".join( - file_content.splitlines()[ - task_shard.start_line - 1 : task_shard.end_line - ] - ) - ), - title=f"{file_name}:{task_shard.start_line}", + +@app.command() +def todo() -> None: + all_shards = list(all_files(TaskConfiguration)) + + for task_shard in find_shard_by_position(all_shards, "task", "open"): + with open(task_shard.location["file"], "r") as file: + file_content = file.read().splitlines() + print( + Panel( + Markdown( + "\n".join( + file_content[ + task_shard.start_line - 1 : task_shard.end_line + ] ) - ) + ), + title=f"{task_shard.location['file']}:{task_shard.start_line}", + ) + ) + + +@app.command() +def edit(number: Annotated[int, typer.Argument()] = 1) -> None: + all_shards = list(all_files(TaskConfiguration)) + sorted_shards = sorted(all_shards, key=lambda s: s.moment) + + if abs(number) >= len(sorted_shards): + raise ValueError("Argument out of range") + + selected_number = number + if selected_number >= 0: + selected_number = len(sorted_shards) - selected_number + else: + selected_number = -selected_number + + click.edit(None, filename=sorted_shards[selected_number].location["file"]) @app.command() @@ -59,7 +90,9 @@ def new() -> None: parsed_content = parse_markdown_file(prelimary_path, content) final_file_name = f"{timestamp}.md" - if parsed_content.shard is not None and len(markers := parsed_content.shard.markers): + if parsed_content.shard is not None and len( + markers := parsed_content.shard.markers + ): final_file_name = f"{timestamp} {' '.join(markers)}.md" final_path = os.path.join(streamer_directory, final_file_name) diff --git a/src/streamer/localize/__init__.py b/src/streamer/localize/__init__.py index 31f4f71..97456a2 100644 --- a/src/streamer/localize/__init__.py +++ b/src/streamer/localize/__init__.py @@ -1,6 +1,6 @@ from .localize import localize_stream_file -from .repostory_configuration import RepositoryConfiguration from .localized_shard import LocalizedShard +from .repository_configuration import RepositoryConfiguration __all__ = [ "RepositoryConfiguration", diff --git a/src/streamer/localize/extract_datetime.py b/src/streamer/localize/extract_datetime.py index ed82955..df15935 100644 --- a/src/streamer/localize/extract_datetime.py +++ b/src/streamer/localize/extract_datetime.py @@ -1,9 +1,9 @@ -from datetime import datetime -import re import os +import re +from datetime import date, datetime, time -def extract_date_from_file_name(file_name: str) -> datetime | None: +def extract_datetime_from_file_name(file_name: str) -> datetime | None: FILE_NAME_REGEX = r"^(?P\d{8})(?:-(?P