diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 329fbd3..0e74c38 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,69 +1,120 @@ -# Contribution Guide +# Contributing Guide -Thanks for considering a contribution to this project. Whether you're fixing bugs, adding features, or updating documentation, your effort is appreciated. +Hello and welcome! 🚀 -## For New Contributors +Thank you for considering a contribution to this project. Your effort, whether it's fixing bugs, adding features, or improving documentation, is deeply valued. -If this is your first time, welcome! The codebase is documented to help you get started. +## First Time Contributing? -## Test Environment - -Ensure you run tests in the provided [notebook](playground.ipynb) to validate your changes without causing regressions. +If you're new here, fret not. The codebase is well-documented, guiding you step-by-step. ## Contribution Workflow 1. **Fork the Repository** - Click the fork button to create your personal copy. + Start by forking the repository to your account. -2. **Clone the Repository** +2. **Clone Your Fork** - `git clone https://github.com/mohamed-chs/chatgpt-history-export-to-md.git` + ```bash + git clone https://github.com/YOUR_USERNAME/chatgpt-history-export-to-md.git + ``` 3. **Create a New Branch** - Navigate to your directory and create a branch: + Navigate to the cloned directory and initiate a new branch: + + ```bash + cd chatgpt-history-export-to-md + git checkout -b your-branch-name + ``` + +## Setting Up Your Development Environment + +1. **Set Up a Virtual Environment with `venv`** + + It's advisable to use a virtual environment for an isolated setup: + + ```bash + python -m venv .venv + source .venv/bin/activate # On Windows, use `.venv\Scripts\activate` + ``` + +2. **Install Development Dependencies** + + With your virtual environment activated: + + ```bash + pip install -r requirements-dev.txt + ``` + +3. **Development Workflow** + + - **Format the code**: + + ```bash + ruff format . + ``` + + - **Lint the code**: + + ```bash + ruff check . + ``` + + - **Type checks**: - `git checkout -b branch-name` + ```bash + mypy --install-types + mypy . + ``` -4. **Make Your Changes** + - **Run tests**: - Update the code or documentation as needed. + ```bash + python -m pytest + ``` -5. **Commit Your Changes** +4. **Additional testing** - `git commit -m "Brief description of changes"` + You can also check [notebook](playground.ipynb) to see how the output looks. -6. **Push to Your Fork** +## Committing and Pushing Changes - `git push origin branch-name` +1. **Commit Your Changes** -7. **Create a Pull Request** + ```bash + git commit -m "Descriptive message about your changes" + ``` - Navigate to the repository and submit a PR. Attach any relevant images or demos to facilitate the review process. +2. **Push Your Branch** -## Suggestions + ```bash + git push origin your-branch-name + ``` -Check the `Issues` tab for bugs, enhancements, or first-timer tasks. If you have a new idea or improvement, feel free to open an issue. +3. **Open a Pull Request (PR)** -The [Project Todo](TODO.md) and [JavaScript Todo](js/how_to_use.md#still-working-on) also offer areas needing attention. + Navigate to the main repository and initiate a PR. Including demos or screenshots will enrich the review process. -See also a rough internal dependency graph of the project [here](assets/deps_graph.png) (the graph is not complete, but it gives a general idea of the project's structure). Generated using : +**Note**: Before pushing your changes, ensure that you reset the `user_config.json` file to its original state. (unless you want to add or change the default values) -```bash -pydeps cli.py -o assets/deps_graph.png -T png --noshow --reverse --rankdir BT --exclude-exact models views controllers -``` +## Seeking Contribution Ideas? -## Documentation +- Peruse the `Issues` tab for open bugs or feature suggestions. +- Explore the [Project Todo](TODO.md) and [JavaScript Todo](js/how_to_use.md#still-working-on). +- Get a project overview from [here](assets/deps_graph.png). Generated using : -Refer to the in-code comments and docstrings for understanding and clarity. + ```bash + pydeps cli.py -o assets/deps_graph.png -T png --noshow --reverse --rankdir BT --exclude-exact models views controllers utils + ``` -## Code of Conduct +## Documentation Insights -Maintain a respectful and professional demeanor. Constructive collaboration is key. +Engage with the codebase; in-code comments and docstrings offer ample context. -## Final Note +## In Closing -Each contribution, irrespective of its scale, is valuable. Dive in and make a difference! +Every contribution, big or small, enriches the project. We eagerly await your additions! -Looking forward to your pull request. +Catch you in the PRs! 🚀 diff --git a/README.md b/README.md index 2a9f816..fe304da 100644 --- a/README.md +++ b/README.md @@ -130,6 +130,8 @@ See [contributing guide](CONTRIBUTING.md) ## Notes +This project requires Python 3.8.7 or higher if on Windows. See [known issue](https://github.com/prompt-toolkit/python-prompt-toolkit/issues/1023#issue-534396318) + This is just a small thing I coded to help me see my convos in beautiful markdown, in [Obsidian](https://obsidian.md/) (my go-to note-taking app). I wasn't a fan of the clunky, and sometimes paid, browser extensions. diff --git a/cli.py b/cli.py index 6047439..a426a96 100644 --- a/cli.py +++ b/cli.py @@ -2,7 +2,6 @@ from __future__ import annotations -import sys from pathlib import Path from shutil import rmtree from typing import TYPE_CHECKING, Any @@ -21,15 +20,6 @@ if TYPE_CHECKING: from models.conversation_set import ConversationSet -if sys.version_info < (3, 10): - print( - "Python 3.10 or higher is required to run this program.\n" - "Please download the latest version of Python at :\n" - "https://www.python.org/downloads/ 🔗, and try again.\n" - "Exiting...", - ) - sys.exit(1) - def main() -> None: """Run the program.""" @@ -125,7 +115,7 @@ def main() -> None: ) save_configs(user_configs=configs_dict) - print("(Settings ⚙️ have been updated and saved to 'config.json')\n") + print("(Settings ⚙️ have been updated and saved to 'user_config.json')\n") print( "ALL DONE 🎉🎉🎉 !\n\n" diff --git a/controllers/configuration.py b/controllers/configuration.py index ebfca58..bcadca7 100644 --- a/controllers/configuration.py +++ b/controllers/configuration.py @@ -15,7 +15,7 @@ from .file_system import get_most_recently_downloaded_zip -CONFIG_PATH = Path("config.json") +CONFIG_PATH = Path("user_config.json") DEFAULT_OUTPUT_FOLDER: Path = Path.home() / "Documents" / "ChatGPT Data" diff --git a/controllers/file_system.py b/controllers/file_system.py index e69e3ac..e42c3b3 100644 --- a/controllers/file_system.py +++ b/controllers/file_system.py @@ -148,13 +148,12 @@ def save_wordcloud_from_conversation_set( **kwargs: Any, ) -> None: """Create a wordcloud and saves it to the folder.""" - match time_period[1]: - case "week": - file_name: str = f"{time_period[0].strftime('%Y week %W')}.png" - case "month": - file_name = f"{time_period[0].strftime('%Y %B')}.png" - case "year": - file_name = f"{time_period[0].strftime('%Y')}.png" + if time_period[1] == "week": + file_name: str = f"{time_period[0].strftime('%Y week %W')}.png" + elif time_period[1] == "month": + file_name = f"{time_period[0].strftime('%Y %B')}.png" + elif time_period[1] == "year": + file_name = f"{time_period[0].strftime('%Y')}.png" wordcloud_from_conversation_set(conv_set=conv_set, **kwargs).to_file( filename=dir_path / file_name, diff --git a/models/message.py b/models/message.py index bcefb18..697171f 100644 --- a/models/message.py +++ b/models/message.py @@ -33,17 +33,17 @@ def author_role(self) -> Literal["user", "assistant", "system", "tool"]: def author_header(self) -> str: """Get the title header of the message based on the configs.""" author_config: dict[str, Any] = self.configuration.get("author_headers", {}) - match self.author_role(): - case "user": - return author_config.get("user", "# User") - case "assistant": - return author_config.get("assistant", "# Assistant") - case "system": - return author_config.get("system", "### System") - case "tool": - return author_config.get("tool", "### Tool output") - case _: - return "### unknown-message-author" + + if self.author_role() == "user": + return author_config.get("user", "# User") + if self.author_role() == "assistant": + return author_config.get("assistant", "# Assistant") + if self.author_role() == "system": + return author_config.get("system", "### System") + if self.author_role() == "tool": + return author_config.get("tool", "### Tool output") + + return "### unknown-message-author" def content_text(self) -> str: """Get the text content of the message.""" diff --git a/pyproject.toml b/pyproject.toml index 33a7e55..68b8e76 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,9 +1,13 @@ [tool.ruff] select = ["ALL"] -ignore = ["ANN101"] # missing-type-self +ignore = [ + "ANN101", # missing-type-self + "TD002", # missing-todo-author + "TD003", # missing-todo-link +] [tool.ruff.per-file-ignores] -"cli.py" = ["T201"] # print statement -"setup.py" = ["T201"] # print statement +"cli.py" = ["T201"] # print +"setup.py" = ["T201"] # print "tests/*" = ["S101"] # assert diff --git a/setup.py b/setup.py index f17d949..652aade 100644 --- a/setup.py +++ b/setup.py @@ -28,15 +28,6 @@ def pip_install_requirements() -> None: if __name__ == "__main__": - if sys.version_info < (3, 10): - print( - "Python 3.10 or higher is required to run this program.\n" - "Please download the latest version of Python at :\n" - "https://www.python.org/downloads/ 🔗, and try again.\n" - "Exiting...", - ) - sys.exit(1) - print("Creating virtual environment...\n") create_virtual_environment() print("Installing requirements... (This may take a minute..)\n") @@ -45,12 +36,12 @@ def pip_install_requirements() -> None: print( "\nSetup completed successfully!\n" "\nTo activate the virtual environment, " - "use the following command based on your platform:", + "use the following command based on your platform:\n", ) if sys.platform == "win32": print( - "\nFor Command Prompt:\n.venv\\Scripts\\activate.bat\n" - "\nFor PowerShell:\n.venv\\Scripts\\Activate.ps1\n", + "\nFor Command Prompt:\n\t.venv\\Scripts\\activate.bat\n" + "\nFor PowerShell:\n\t.venv\\Scripts\\Activate.ps1\n", ) else: - print("\nsource .venv/bin/activate\n") + print("\n\tsource .venv/bin/activate\n") diff --git a/config.json b/user_config.json similarity index 100% rename from config.json rename to user_config.json