Skip to content

Commit

Permalink
Merge pull request #8 from 5n00py/fix/python-venv
Browse files Browse the repository at this point in the history
refactor(readme & setup): Improve README details and add Python venv …
  • Loading branch information
5n00py authored Dec 14, 2023
2 parents c54423c + 2b8ebbd commit 4522b47
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 53 deletions.
129 changes: 77 additions & 52 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ environments.

- [Prerequisites](#prerequisites)
- [Installation](#installation)
- [Manual Installation](#manual-installation)
- [Using the Setup Script](#using-the-setup-script)
- [Quick Setup with One-Liner](#quick-setup-with-one-liner)
- [Using the Setup Script](#using-the-setup-script)
- [Manual Installation](#manual-installation)
- [Configuration](#configuration)
- [Commit Message Style](#commit-message-style)
- [GPT Model Configuration](#gpt-model-configuration)
Expand All @@ -41,14 +41,84 @@ environments.

## Prerequisites

- Python 3.7 or higher
- An OpenAI API key, see: [Where do I find my Secret API Key?](https://help.openai.com/en/articles/4936850-where-do-i-find-my-secret-api-key)
- Git installed on your system
- Staged changes in the current repo to be commited
- `tmp_commit_msg.txt` has to be configured as commit template (see below)
Before you begin with SmartCommit, ensure you have the following prerequisites
set up:

- **Python 3.7 or higher**: This is the core language used for accessing the
OpenAI API. To check your current Python version, use `python3 --version`.
Python 3.11 is recommended for the best compatibility and performance. You
can download it from the [Python Download
Site](https://www.python.org/downloads/) or use your operating system's
package manager for installation.

- **Python venv**: This module is crucial for creating an isolated Python
environment, which is necessary for the proper functioning of SmartCommit.
It's usually included with Python 3.7 and later. To verify if it's installed,
run `python3 -m venv --help`. If you're using a Debian-based system and it's
not installed, you can install it with `sudo apt install python3.x-venv`,
replacing x with your Python 3 version number. For other systems, please
consult the relevant documentation or package manager.

- **OpenAI API Key**: Essential for accessing the OpenAI API functionalities.
You can obtain your API key following [Where do I find my Secret API
Key?](https://help.openai.com/en/articles/4936850-where-do-i-find-my-secret-api-key)

- **Git**: Make sure Git is installed on your system, as SmartCommit integrates with
it for version control. If you need to install or update Git, visit [Git's
official site](https://git-scm.com/downloads) or consult your package manager.

- **Staged Changes in Your Repository**: `gc-smart` is designed to generate
commit messages based on the changes staged in your Git repository. Ensure
you have changes staged for commit before using the script.

## Installation

### Quick Setup with One-Liner

For a quick setup you can use a one-liner that clones the repository into
`~/.local/share/SmartCommit` and then runs the setup script. Make sure you have
Python 3.7 or higher and venv installed and run:

```bash bash <(curl -sL
https://raw.githubusercontent.com/5n00py/SmartCommit/main/setup/setup_quick_wget.sh)
```

Upon completion don't forget to restart or source your shell configuration as
described under 6. in the Manuall Installation section above.

### Using the Setup Script

For an automated setup process after cloning, you can use the
[setup_sc.sh](setup/setup_sc.sh) script located in the `setup` directory. This
will set up the Python environment, install necessary dependencies, configure
the OpenAI API key and update the shell's configuration.

**Note:** If the `OPENAI_API_KEY` environment variable is not already set, the
script will prompt you to enter an OpenAI API key. You will need to paste the
key at the prompt, so make sure you have it ready, see also
[Where do I find my API key?](https://help.openai.com/en/articles/4936850-where-do-i-find-my-api-key).

1. Clone the Repository as described in the first step of the Manual
Installation.

2. Navigate to the setup directory, make the script executable and run it:

```bash
cd SmartCommit/setup && chmod +x setup_sc.sh && ./setup_sc.sh
```

The script will perform several actions:
- Create and set up a virtual environment for Python
- Check if Python version is 3.7 or higher
- Install requiret python libraries in the venv
- Prompt for adding an `OPENAI_API_KEY` and adding it to `.bashrc` or
`.zshrc` if they exist.
- Add `gc-smart` script to the shell's PATH environment variable.
- Make the necessary scripts executable.

3. Restart or source your shell configuration as descripted under 6. in the
Manual Installation above.

### Manual Installation

1. Clone this repository to your local machine using git:
Expand Down Expand Up @@ -145,51 +215,6 @@ environments.
source ~/.zshrc
```
### Using the Setup Script
For a more automated setup process, you can use the
[setup_sc.sh](setup/setup_sc.sh) script located in the `setup` directory. This
will set up the Python environment, install necessary dependencies, configure
the OpenAI API key and update the shell's configuration.

**Note:** If the `OPENAI_API_KEY` environment variable is not already set, the
script will prompt you to enter an OpenAI API key. You will need to paste the
key at the prompt, so make sure you have it ready, see also
[Where do I find my API key?](https://help.openai.com/en/articles/4936850-where-do-i-find-my-api-key).

1. Clone the Repository as described in the first step of the Manual
Installation.

2. Navigate to the setup directory, make the script executable and run it:

```bash
cd SmartCommit/setup && chmod +x setup_sc.sh && ./setup_sc.sh
```

The script will perform several actions:
- Create and set up a virtual environment for Python
- Check if Python version is 3.7 or higher
- Install requiret python libraries in the venv
- Prompt for adding an `OPENAI_API_KEY` and adding it to `.bashrc` or
`.zshrc` if they exist.
- Add `gc-smart` script to the shell's PATH environment variable.
- Make the necessary scripts executable.
3. Restart or source your shell configuration as descripted under 6. in the
Manual Installation above.
### Quick Setup with One-Liner
For an even swifter setup you can use a one-liner that clones the repository
into `~/.local/share/SmartCommit` and then runs the setup script:
```bash
bash <(curl -sL https://raw.githubusercontent.com/5n00py/SmartCommit/main/setup/setup_quick_wget.sh)
```
Upon completion don't forget to restart or source your shell configuration as
described under 6. in the Manuall Installation section above.

## Configuration
The `gpt-commit-prompter` used in `gc-smart` allows configuration through the
Expand Down
26 changes: 25 additions & 1 deletion setup/setup_sc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,31 @@ minimum_version="3.7"
if printf '%s\n' "$python_version" "$minimum_version" | sort -V | head -n 1 | grep -q "$minimum_version"; then
echo "Python version is $python_version, which is acceptable."
else
echo "Python 3.7 or higher is required. Please upgrade your Python."
echo "Python 3.7 or higher is required."
echo "To install Python 3.11, you can typically use the following commands:"
echo "sudo apt-get update"
echo "sudo apt-get install python3.11"
echo "If you're not using a Debian-based system, please check your"
echo "distribution's package manager or visit the Python website for"
echo "installation instructions."
echo "After installing Python 3.11, please rerun this setup script:"
echo "$GCS_ROOT/setup/setup_sc.sh"
exit 1
fi

# Check if Python venv is installed
if ! python3 -m venv --help > /dev/null 2>&1; then
echo "The Python venv module is not installed."
echo "Please install the Python venv module for your Python version."
echo "For Python 3.x, you can typically install it using:"
echo "sudo apt-get install python3.x-venv"
echo "Replace 'x' with your Python 3 version number."
echo "If you're not using a Debian-based system, please check your"
echo "distribution's package manager or visit the Python website for"
echo "installation instructions."
echo "After installing the venv module, please restart this setup script:"
echo "$GCS_ROOT/setup/setup_sc.sh"

exit 1
fi

Expand Down

0 comments on commit 4522b47

Please sign in to comment.