Skip to content

Commit

Permalink
~
Browse files Browse the repository at this point in the history
  • Loading branch information
mohamed-chs committed Oct 20, 2023
1 parent 806f014 commit dac5d9e
Show file tree
Hide file tree
Showing 9 changed files with 117 additions and 80 deletions.
119 changes: 85 additions & 34 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -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! 🚀
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
12 changes: 1 addition & 11 deletions cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

from __future__ import annotations

import sys
from pathlib import Path
from shutil import rmtree
from typing import TYPE_CHECKING, Any
Expand All @@ -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."""
Expand Down Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion controllers/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"


Expand Down
13 changes: 6 additions & 7 deletions controllers/file_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
22 changes: 11 additions & 11 deletions models/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down
10 changes: 7 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -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
17 changes: 4 additions & 13 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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")
File renamed without changes.

0 comments on commit dac5d9e

Please sign in to comment.