From 8bf8145b511ff26d3761a340eebc1067a5798ad9 Mon Sep 17 00:00:00 2001 From: "Estrada Irribarra, Rodrigo Andres" Date: Tue, 22 Oct 2024 17:30:07 -0300 Subject: [PATCH] feat: include outline and worldbuilding directories, exclude cover and back-cover files - Added logic to include Markdown files from the outline and worldbuilding directories. - Excluded cover.md and back-cover.md files from processing. - Ensured directories are checked for existence before processing files. --- README.md | 2 +- docs/getting_started.md | 2 +- docs/index.html | 2 +- poetry.lock | 8 ++++---- pyproject.toml | 2 +- storycraftr/agent/agents.py | 26 +++++++++++++++++++++----- 6 files changed, 29 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index a97631b..5ab0393 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ First, install **StoryCraftr** using [pipx](https://pypa.github.io/pipx/), a too To install **StoryCraftr**, run the following command: ```bash -pipx install git+https://github.com/raestrada/storycraftr.git@v0.7.1-alpha3 +pipx install git+https://github.com/raestrada/storycraftr.git@v0.7.2-alpha3 ``` ### Important: Before using StoryCraftr, make sure to set your OpenAI API key: diff --git a/docs/getting_started.md b/docs/getting_started.md index 37d6e13..769cde2 100644 --- a/docs/getting_started.md +++ b/docs/getting_started.md @@ -11,7 +11,7 @@ First, install **StoryCraftr** using [pipx](https://pypa.github.io/pipx/), a too To install **StoryCraftr**, run the following command: ```bash -pipx install git+https://github.com/raestrada/storycraftr.git@v0.7.1-alpha3 +pipx install git+https://github.com/raestrada/storycraftr.git@v0.7.2-alpha3 ``` ### Important: Before running the `storycraftr` command diff --git a/docs/index.html b/docs/index.html index 8abdd5a..ba49441 100644 --- a/docs/index.html +++ b/docs/index.html @@ -431,7 +431,7 @@

Welcome to StoryCraftr 📚✨

usable but may still have bugs: pipx install - git+https://github.com/raestrada/storycraftr.git@v0.7.1-alpha3 diff --git a/poetry.lock b/poetry.lock index 5048c40..8ca53b3 100644 --- a/poetry.lock +++ b/poetry.lock @@ -574,7 +574,7 @@ files = [ parso = ">=0.8.3,<0.9.0" [package.extras] -docs = ["Jinja2 (==2.11.3)", "MarkupSafe (==1.1.1)", "Pygments (==2.8.1)", "alabaster (==0.7.12)", "babel (==2.9.1)", "chardet (==4.0.0)", "commonmark (==0.8.1)", "docutils (==0.17.1)", "future (==0.18.2)", "idna (==2.10)", "imagesize (==1.2.0)", "mock (==1.0.1)", "packaging (==20.9)", "pyparsing (==2.4.7)", "pytz (==2021.1)", "readthedocs-sphinx-ext (==2.1.4)", "recommonmark (==0.5.0)", "requests (==2.25.1)", "six (==1.15.0)", "snowballstemmer (==2.1.0)", "sphinx (==1.8.5)", "sphinx-rtd-theme (==0.4.3)", "sphinxcontrib-serializinghtml (==1.1.4)", "sphinxcontrib-websupport (==1.2.4)", "urllib3 (==1.26.4)"] +docs = ["Jinja2 (==2.11.3)", "MarkupSafe (==1.1.1)", "Pygments (==2.8.1)", "alabaster (==0.7.22)", "babel (==2.9.1)", "chardet (==4.0.0)", "commonmark (==0.8.1)", "docutils (==0.17.1)", "future (==0.18.2)", "idna (==2.10)", "imagesize (==1.2.0)", "mock (==1.0.1)", "packaging (==20.9)", "pyparsing (==2.4.7)", "pytz (==2021.1)", "readthedocs-sphinx-ext (==2.1.4)", "recommonmark (==0.5.0)", "requests (==2.25.1)", "six (==1.15.0)", "snowballstemmer (==2.1.0)", "sphinx (==1.8.5)", "sphinx-rtd-theme (==0.4.3)", "sphinxcontrib-serializinghtml (==1.1.4)", "sphinxcontrib-websupport (==1.2.4)", "urllib3 (==1.26.4)"] qa = ["flake8 (==5.0.4)", "mypy (==0.971)", "types-setuptools (==67.2.0.1)"] testing = ["Django", "attrs", "colorama", "docopt", "pytest (<7.0.0)"] @@ -1402,7 +1402,7 @@ files = [ ] [package.dependencies] -alabaster = ">=0.7.14" +alabaster = ">=0.7.24" babel = ">=2.13" colorama = {version = ">=0.4.6", markers = "sys_platform == \"win32\""} docutils = ">=0.20,<0.22" @@ -1423,7 +1423,7 @@ tomli = {version = ">=2", markers = "python_version < \"3.11\""} [package.extras] docs = ["sphinxcontrib-websupport"] lint = ["flake8 (>=6.0)", "mypy (==1.11.1)", "pyright (==1.1.384)", "pytest (>=6.0)", "ruff (==0.6.9)", "sphinx-lint (>=0.9)", "tomli (>=2)", "types-Pillow (==10.2.0.20240822)", "types-Pygments (==2.18.0.20240506)", "types-colorama (==0.4.15.20240311)", "types-defusedxml (==0.7.0.20240218)", "types-docutils (==0.21.0.20241005)", "types-requests (==2.32.0.20240914)", "types-urllib3 (==1.26.25.14)"] -test = ["cython (>=3.0)", "defusedxml (>=0.7.1)", "pytest (>=8.0)", "setuptools (>=70.0)", "typing_extensions (>=4.9)"] +test = ["cython (>=3.0)", "defusedxml (>=0.7.2)", "pytest (>=8.0)", "setuptools (>=70.0)", "typing_extensions (>=4.9)"] [[package]] name = "sphinx-click" @@ -1517,7 +1517,7 @@ files = [ [package.extras] lint = ["mypy", "ruff (==0.5.5)", "types-docutils"] standalone = ["Sphinx (>=5)"] -test = ["defusedxml (>=0.7.1)", "pytest"] +test = ["defusedxml (>=0.7.2)", "pytest"] [[package]] name = "sphinxcontrib-serializinghtml" diff --git a/pyproject.toml b/pyproject.toml index facef4f..4096799 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "storycraftr" -version = "0.7.1-alpha3" +version = "0.7.2-alpha3" description = "A CLI tool for writing books using OpenAI." authors = ["Tu nombre "] license = "MIT" diff --git a/storycraftr/agent/agents.py b/storycraftr/agent/agents.py index cacf6bf..67eeefb 100644 --- a/storycraftr/agent/agents.py +++ b/storycraftr/agent/agents.py @@ -325,13 +325,29 @@ def process_chapters( file_suffix (str): Suffix for the output file. **prompt_kwargs: Additional arguments for the prompt template. """ + # Directories to process chapters_dir = os.path.join(book_path, "chapters") - if not os.path.exists(chapters_dir): - raise FileNotFoundError( - f"The chapter directory '{chapters_dir}' does not exist." - ) + outline_dir = os.path.join(book_path, "outline") + worldbuilding_dir = os.path.join(book_path, "worldbuilding") + + # Check if directories exist + for dir_path in [chapters_dir, outline_dir, worldbuilding_dir]: + if not os.path.exists(dir_path): + raise FileNotFoundError(f"The directory '{dir_path}' does not exist.") + + # Files to exclude + excluded_files = ["cover.md", "back-cover.md"] + + # Get Markdown files from each directory, excluding the unwanted files + files_to_process = [] + for dir_path in [chapters_dir, outline_dir, worldbuilding_dir]: + files = [ + f + for f in os.listdir(dir_path) + if f.endswith(".md") and f not in excluded_files + ] + files_to_process.extend([os.path.join(dir_path, f) for f in files]) - files_to_process = [f for f in os.listdir(chapters_dir) if f.endswith(".md")] if not files_to_process: raise FileNotFoundError( "No Markdown (.md) files were found in the chapter directory."