gpt-pr 0.2.1__tar.gz → 0.7.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of gpt-pr might be problematic. Click here for more details.

gpt_pr-0.7.2/PKG-INFO ADDED
@@ -0,0 +1,285 @@
1
+ Metadata-Version: 2.4
2
+ Name: gpt-pr
3
+ Version: 0.7.2
4
+ Summary: Automate your GitHub workflow with GPT-PR: an OpenAI powered library for streamlined PR generation.
5
+ Author: alissonperez
6
+ Author-email: 756802+alissonperez@users.noreply.github.com
7
+ Requires-Python: >=3.10,<4.0
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: Programming Language :: Python :: 3.10
10
+ Classifier: Programming Language :: Python :: 3.11
11
+ Classifier: Programming Language :: Python :: 3.12
12
+ Classifier: Programming Language :: Python :: 3.13
13
+ Classifier: Programming Language :: Python :: 3.14
14
+ Requires-Dist: fire (>=0.7.1,<0.8.0)
15
+ Requires-Dist: gitpython (>=3.1.45,<4.0.0)
16
+ Requires-Dist: inquirerpy (>=0.3.4,<0.4.0)
17
+ Requires-Dist: prompt-toolkit (>=3.0.52,<4.0.0)
18
+ Requires-Dist: pydantic-ai (>=1.14.0,<2.0.0)
19
+ Requires-Dist: pygithub (>=2.8.1,<3.0.0)
20
+ Requires-Dist: requests (>=2.32.5,<3.0.0)
21
+ Requires-Dist: tiktoken (>=0.12.0,<0.13.0)
22
+ Description-Content-Type: text/markdown
23
+
24
+ # GPT-PR
25
+
26
+ GPT-PR is an open-source command-line tool designed to streamline your GitHub workflow for opening PRs. Leveraging OpenAI's ChatGPT API, it automatically opens a GitHub Pull Request with a predefined description and title directly from your current project directory.
27
+
28
+ [![asciicast](https://asciinema.org/a/u0PwZlNjAGZcdXPPrjf84wj2A.svg)](https://asciinema.org/a/u0PwZlNjAGZcdXPPrjf84wj2A)
29
+
30
+ ## Quick Start
31
+
32
+ For a more detailed explanation, see [Installation](#installation) and [Configuration](#configuration).
33
+
34
+ ### 1. Installation
35
+
36
+ ```bash
37
+ pip install -U gpt-pr
38
+ ```
39
+
40
+ If you don't have the `pip` command available, follow [these instructions](https://pip.pypa.io/en/stable/installation/) to install it on different platforms.
41
+
42
+ ### 2. Fill OpenAI API Key
43
+
44
+ 1. Go to [OpenAI API Keys](https://platform.openai.com/api-keys) and generate a new key.
45
+ 2. Run the following command to fill your key in GPT-PR (it will be stored in `~/.gpt-pr.ini`):
46
+
47
+ ```bash
48
+ gpt-pr-config set openai_api_key MY-API-KEY-VALUE
49
+ ```
50
+
51
+ ### 3. Generate a GitHub GH Token to Open PRs
52
+
53
+ 1. Go to [GitHub Settings](https://github.com/settings/tokens), choose `Generate new token (classic)`, and select all permissions under `repo` (full control of private repositories).
54
+ 2. Run the following command to fill your GH token (it will also be stored in `~/.gpt-pr.ini`):
55
+
56
+ ```bash
57
+ gpt-pr-config set gh_token MY-GH-TOKEN-VALUE
58
+ ```
59
+
60
+ ### 4. Ready to NEVER WRITE A PR AGAIN
61
+
62
+ 1. Make your changes, commit them, and push to origin (important!).
63
+ 2. Run the following command in your project directory:
64
+
65
+ ```bash
66
+ gpt-pr
67
+ ```
68
+
69
+ 3. Answer the questions. At the end, you'll receive the URL of a freshly opened PR.
70
+
71
+ ## Contributing and Feedback
72
+
73
+ We welcome your contributions and feedback to help improve GPT-PR! Here’s how you can get involved:
74
+
75
+ ### Open Issues
76
+
77
+ - **Feature Requests**: Have an idea for a new feature? We’d love to hear it! Open an issue to request new features or enhancements.
78
+ - **Bug Reports**: Encountered a bug? Let us know by opening an issue with detailed information so we can fix it.
79
+ - **General Feedback**: Any other suggestions or feedback? Feel free to share your thoughts.
80
+
81
+ To open an issue, go to the [Issues](https://github.com/your-repo/gpt-pr/issues) section of our GitHub repository. Your contributions are very welcome and highly appreciated!
82
+
83
+ More details about it at our [CONTRIBUTING](./CONTRIBUTING.md) guide.
84
+
85
+ ## Table of Contents
86
+
87
+ - [Features](#features)
88
+ - [Prerequisites](#prerequisites)
89
+ - [Installation](#installation)
90
+ - [Configuration](#configuration)
91
+ - [Usage](#usage)
92
+ - [How to Contribute](#how-to-contribute)
93
+ - [Roadmap](#roadmap)
94
+
95
+ ## Features
96
+
97
+ - Analyzes the diff changes of the current branch against the `main` branch.
98
+ - Provides an option to exclude certain file changes from PR generation (for instance, you can ignore a `package.lock` file with 5k lines changed).
99
+ - Incorporates commit messages into the process.
100
+
101
+ ## Prerequisites
102
+
103
+ Before getting started, make sure you have the following installed:
104
+
105
+ - Python 3.9 or higher
106
+ - [Poetry](https://python-poetry.org/)
107
+
108
+ ## Installation
109
+
110
+ You can install and use GPT-PR in one of two ways. Choose the option that best suits your needs.
111
+
112
+ ### Option 1: Using `pip install` (Recommended)
113
+
114
+ 1. Install OR Update the package:
115
+
116
+ ```bash
117
+ pip install -U gpt-pr
118
+ ```
119
+
120
+ 2. Setup API keys for GitHub and OpenAI, take a look at [Configuration](#configuration).
121
+
122
+ 3. Inside the Git repository you are working on, ensure you have pushed your branch to origin, then run:
123
+
124
+ ```bash
125
+ gpt-pr --help
126
+ ```
127
+
128
+ ### Option 2: Cloning the code (NOT recommended)
129
+
130
+ 1. Clone the repository:
131
+
132
+ ```bash
133
+ git clone https://github.com/alissonperez/gpt-pr.git
134
+ ```
135
+
136
+ 2. Navigate to the project directory and install dependencies:
137
+
138
+ ```bash
139
+ cd gpt-pr
140
+ poetry install
141
+ ```
142
+
143
+ After setting up API keys ([Configuration](#configuration)), you can use GPT-PR within any git project directory. Suppose you've cloned **this project** to `~/workplace/gpt-pr`, here's how you can use it:
144
+
145
+ ```bash
146
+ poetry run python gpt_pr/main.py --help
147
+ ```
148
+
149
+ ## Configuration
150
+
151
+ ### See all configs available
152
+
153
+ To print all default configs and what is being used, just run:
154
+
155
+ ```bash
156
+ gpt-pr-config print
157
+ ```
158
+
159
+ ### Setting up GitHub Token (`GH_TOKEN`)
160
+
161
+ GPT-PR tool will look for a `GH_TOKEN` in current shell env var OR in gpt-pr config file (at `~/.gpt-pr.ini`).
162
+
163
+ To authenticate with GitHub, generate and export a GitHub Personal Access Token:
164
+
165
+ 1. Navigate to [GitHub's Personal Access Token page](https://github.com/settings/tokens).
166
+ 2. Click "Generate new token."
167
+ 3. Provide a description and select the required permissions `repo` for the token.
168
+ 4. Click "Generate token" at the bottom of the page.
169
+ 5. Copy the generated token.
170
+ 6. Set `gh_token` config running (supposing your gh token is `ghp_4Mb1QEr9gY5e8Lk3tN1KjPzX7W9z2V4HtJ2b`):
171
+
172
+ ```bash
173
+ gpt-pr-config set gh_token ghp_4Mb1QEr9gY5e8Lk3tN1KjPzX7W9z2V4HtJ2b
174
+ ```
175
+
176
+ Or just export it as an environment variable in your shell initializer:
177
+
178
+ ```bash
179
+ export GH_TOKEN=your_generated_token_here
180
+ ```
181
+
182
+ ### Setting up OpenAI API Key (`OPENAI_API_KEY`)
183
+
184
+ GPT-PR tool will look for a `OPENAI_API_KEY` env var in current shell OR in gpt-pr config file (at `~/.gpt-pr.ini`).
185
+
186
+ This project needs to interact with the ChatGPT API to generate the pull request description. So, you need to generate and export an OpenAI API Key:
187
+
188
+ 1. Navigate to [OpenAI's API Key page](https://platform.openai.com/signup).
189
+ 2. If you don't have an account, sign up and log in.
190
+ 3. Go to the API Keys section and click "Create new key."
191
+ 4. Provide a description and click "Create."
192
+ 5. Copy the generated API key.
193
+ 6. Set `openai_api_key` config running (supposing your openai_api_key is `QEr9gY5e8Lk3tN1KjPzX7W9z2V4Ht`):
194
+
195
+ ```bash
196
+ gpt-pr-config set openai_api_key QEr9gY5e8Lk3tN1KjPzX7W9z2V4Ht
197
+ ```
198
+
199
+ Or just export it as an environment variable in your shell initializer:
200
+
201
+ ```bash
202
+ export OPENAI_API_KEY=your_generated_api_key_here
203
+ ```
204
+
205
+ ### Setting Max Input LLM Tokens
206
+
207
+ You can adjust the maximum number of input tokens allowed when calling the LLM model by modifying the corresponding setting.
208
+
209
+ For example, to change the maximum to 20,000 tokens, use the following command:
210
+
211
+ ```bash
212
+ gpt-pr-config set input_max_tokens 20000
213
+ ```
214
+
215
+ ### Change OpenAI model
216
+
217
+ To change OpenAI model, just run:
218
+
219
+ ```bash
220
+ gpt-pr-config set openai_model gpt-4o-mini
221
+ ```
222
+
223
+ > Obs.: `gpt-4o-mini` already is the default model of the project
224
+
225
+ To see a full list of available models, access [OpenAI Models Documentation](https://platform.openai.com/docs/models)
226
+
227
+ ### GPT-PR Library Signature in PRs
228
+
229
+ To help other developers recognize and understand the use of the GPT-PR library in generating pull requests, we have included an optional signature feature. By default, this feature is enabled and appends the text "Generated by GPT-PR" at the end of each pull request. This transparency fosters better collaboration and awareness among team members about the tools being utilized in the development process.
230
+
231
+ If you prefer to disable this feature, simply run the following command:
232
+
233
+ ```bash
234
+ gpt-pr-config set add_tool_signature false
235
+ ```
236
+
237
+ ### Reset config
238
+
239
+ To reset any config to default value, just run:
240
+
241
+ ```bash
242
+ gpt-pr-config reset config_name
243
+ ```
244
+
245
+ Example:
246
+
247
+ ```bash
248
+ gpt-pr-config reset openai_model
249
+ ```
250
+
251
+ ## Usage
252
+
253
+ ### Generating Github Pull Requests
254
+
255
+ To create a Pull request from your current branch commits to merge with `main` branch, just run:
256
+
257
+ ```
258
+ gpt-pr
259
+ ```
260
+
261
+ If you would like to compare with other base branch that is not `main`, just use `-b` param:
262
+
263
+ ```
264
+ gpt-pr -b my-other-branch
265
+ ```
266
+
267
+ ### Usage help
268
+
269
+ To show help commands:
270
+
271
+ ```
272
+ gpt-pr -h
273
+ ```
274
+
275
+ Output:
276
+ ![image](https://github.com/alissonperez/gpt-pr/assets/756802/cc6c0ca4-5759-44ce-ad35-e4e7305b3875)
277
+
278
+ ## Roadmap
279
+
280
+ - [x] Improve execution method, possibly through a shell script or at least an alias in bash rc files.
281
+ - Change to use with pip installation and console_scripts entry point.
282
+ - [x] Fetch GitHub PR templates from the current project.
283
+ - [ ] Add configuration to set which LLM and model should be used (OpenAI GPT, Mistral, etc...)
284
+ - [ ] Add unit tests.
285
+
gpt_pr-0.7.2/README.md ADDED
@@ -0,0 +1,261 @@
1
+ # GPT-PR
2
+
3
+ GPT-PR is an open-source command-line tool designed to streamline your GitHub workflow for opening PRs. Leveraging OpenAI's ChatGPT API, it automatically opens a GitHub Pull Request with a predefined description and title directly from your current project directory.
4
+
5
+ [![asciicast](https://asciinema.org/a/u0PwZlNjAGZcdXPPrjf84wj2A.svg)](https://asciinema.org/a/u0PwZlNjAGZcdXPPrjf84wj2A)
6
+
7
+ ## Quick Start
8
+
9
+ For a more detailed explanation, see [Installation](#installation) and [Configuration](#configuration).
10
+
11
+ ### 1. Installation
12
+
13
+ ```bash
14
+ pip install -U gpt-pr
15
+ ```
16
+
17
+ If you don't have the `pip` command available, follow [these instructions](https://pip.pypa.io/en/stable/installation/) to install it on different platforms.
18
+
19
+ ### 2. Fill OpenAI API Key
20
+
21
+ 1. Go to [OpenAI API Keys](https://platform.openai.com/api-keys) and generate a new key.
22
+ 2. Run the following command to fill your key in GPT-PR (it will be stored in `~/.gpt-pr.ini`):
23
+
24
+ ```bash
25
+ gpt-pr-config set openai_api_key MY-API-KEY-VALUE
26
+ ```
27
+
28
+ ### 3. Generate a GitHub GH Token to Open PRs
29
+
30
+ 1. Go to [GitHub Settings](https://github.com/settings/tokens), choose `Generate new token (classic)`, and select all permissions under `repo` (full control of private repositories).
31
+ 2. Run the following command to fill your GH token (it will also be stored in `~/.gpt-pr.ini`):
32
+
33
+ ```bash
34
+ gpt-pr-config set gh_token MY-GH-TOKEN-VALUE
35
+ ```
36
+
37
+ ### 4. Ready to NEVER WRITE A PR AGAIN
38
+
39
+ 1. Make your changes, commit them, and push to origin (important!).
40
+ 2. Run the following command in your project directory:
41
+
42
+ ```bash
43
+ gpt-pr
44
+ ```
45
+
46
+ 3. Answer the questions. At the end, you'll receive the URL of a freshly opened PR.
47
+
48
+ ## Contributing and Feedback
49
+
50
+ We welcome your contributions and feedback to help improve GPT-PR! Here’s how you can get involved:
51
+
52
+ ### Open Issues
53
+
54
+ - **Feature Requests**: Have an idea for a new feature? We’d love to hear it! Open an issue to request new features or enhancements.
55
+ - **Bug Reports**: Encountered a bug? Let us know by opening an issue with detailed information so we can fix it.
56
+ - **General Feedback**: Any other suggestions or feedback? Feel free to share your thoughts.
57
+
58
+ To open an issue, go to the [Issues](https://github.com/your-repo/gpt-pr/issues) section of our GitHub repository. Your contributions are very welcome and highly appreciated!
59
+
60
+ More details about it at our [CONTRIBUTING](./CONTRIBUTING.md) guide.
61
+
62
+ ## Table of Contents
63
+
64
+ - [Features](#features)
65
+ - [Prerequisites](#prerequisites)
66
+ - [Installation](#installation)
67
+ - [Configuration](#configuration)
68
+ - [Usage](#usage)
69
+ - [How to Contribute](#how-to-contribute)
70
+ - [Roadmap](#roadmap)
71
+
72
+ ## Features
73
+
74
+ - Analyzes the diff changes of the current branch against the `main` branch.
75
+ - Provides an option to exclude certain file changes from PR generation (for instance, you can ignore a `package.lock` file with 5k lines changed).
76
+ - Incorporates commit messages into the process.
77
+
78
+ ## Prerequisites
79
+
80
+ Before getting started, make sure you have the following installed:
81
+
82
+ - Python 3.9 or higher
83
+ - [Poetry](https://python-poetry.org/)
84
+
85
+ ## Installation
86
+
87
+ You can install and use GPT-PR in one of two ways. Choose the option that best suits your needs.
88
+
89
+ ### Option 1: Using `pip install` (Recommended)
90
+
91
+ 1. Install OR Update the package:
92
+
93
+ ```bash
94
+ pip install -U gpt-pr
95
+ ```
96
+
97
+ 2. Setup API keys for GitHub and OpenAI, take a look at [Configuration](#configuration).
98
+
99
+ 3. Inside the Git repository you are working on, ensure you have pushed your branch to origin, then run:
100
+
101
+ ```bash
102
+ gpt-pr --help
103
+ ```
104
+
105
+ ### Option 2: Cloning the code (NOT recommended)
106
+
107
+ 1. Clone the repository:
108
+
109
+ ```bash
110
+ git clone https://github.com/alissonperez/gpt-pr.git
111
+ ```
112
+
113
+ 2. Navigate to the project directory and install dependencies:
114
+
115
+ ```bash
116
+ cd gpt-pr
117
+ poetry install
118
+ ```
119
+
120
+ After setting up API keys ([Configuration](#configuration)), you can use GPT-PR within any git project directory. Suppose you've cloned **this project** to `~/workplace/gpt-pr`, here's how you can use it:
121
+
122
+ ```bash
123
+ poetry run python gpt_pr/main.py --help
124
+ ```
125
+
126
+ ## Configuration
127
+
128
+ ### See all configs available
129
+
130
+ To print all default configs and what is being used, just run:
131
+
132
+ ```bash
133
+ gpt-pr-config print
134
+ ```
135
+
136
+ ### Setting up GitHub Token (`GH_TOKEN`)
137
+
138
+ GPT-PR tool will look for a `GH_TOKEN` in current shell env var OR in gpt-pr config file (at `~/.gpt-pr.ini`).
139
+
140
+ To authenticate with GitHub, generate and export a GitHub Personal Access Token:
141
+
142
+ 1. Navigate to [GitHub's Personal Access Token page](https://github.com/settings/tokens).
143
+ 2. Click "Generate new token."
144
+ 3. Provide a description and select the required permissions `repo` for the token.
145
+ 4. Click "Generate token" at the bottom of the page.
146
+ 5. Copy the generated token.
147
+ 6. Set `gh_token` config running (supposing your gh token is `ghp_4Mb1QEr9gY5e8Lk3tN1KjPzX7W9z2V4HtJ2b`):
148
+
149
+ ```bash
150
+ gpt-pr-config set gh_token ghp_4Mb1QEr9gY5e8Lk3tN1KjPzX7W9z2V4HtJ2b
151
+ ```
152
+
153
+ Or just export it as an environment variable in your shell initializer:
154
+
155
+ ```bash
156
+ export GH_TOKEN=your_generated_token_here
157
+ ```
158
+
159
+ ### Setting up OpenAI API Key (`OPENAI_API_KEY`)
160
+
161
+ GPT-PR tool will look for a `OPENAI_API_KEY` env var in current shell OR in gpt-pr config file (at `~/.gpt-pr.ini`).
162
+
163
+ This project needs to interact with the ChatGPT API to generate the pull request description. So, you need to generate and export an OpenAI API Key:
164
+
165
+ 1. Navigate to [OpenAI's API Key page](https://platform.openai.com/signup).
166
+ 2. If you don't have an account, sign up and log in.
167
+ 3. Go to the API Keys section and click "Create new key."
168
+ 4. Provide a description and click "Create."
169
+ 5. Copy the generated API key.
170
+ 6. Set `openai_api_key` config running (supposing your openai_api_key is `QEr9gY5e8Lk3tN1KjPzX7W9z2V4Ht`):
171
+
172
+ ```bash
173
+ gpt-pr-config set openai_api_key QEr9gY5e8Lk3tN1KjPzX7W9z2V4Ht
174
+ ```
175
+
176
+ Or just export it as an environment variable in your shell initializer:
177
+
178
+ ```bash
179
+ export OPENAI_API_KEY=your_generated_api_key_here
180
+ ```
181
+
182
+ ### Setting Max Input LLM Tokens
183
+
184
+ You can adjust the maximum number of input tokens allowed when calling the LLM model by modifying the corresponding setting.
185
+
186
+ For example, to change the maximum to 20,000 tokens, use the following command:
187
+
188
+ ```bash
189
+ gpt-pr-config set input_max_tokens 20000
190
+ ```
191
+
192
+ ### Change OpenAI model
193
+
194
+ To change OpenAI model, just run:
195
+
196
+ ```bash
197
+ gpt-pr-config set openai_model gpt-4o-mini
198
+ ```
199
+
200
+ > Obs.: `gpt-4o-mini` already is the default model of the project
201
+
202
+ To see a full list of available models, access [OpenAI Models Documentation](https://platform.openai.com/docs/models)
203
+
204
+ ### GPT-PR Library Signature in PRs
205
+
206
+ To help other developers recognize and understand the use of the GPT-PR library in generating pull requests, we have included an optional signature feature. By default, this feature is enabled and appends the text "Generated by GPT-PR" at the end of each pull request. This transparency fosters better collaboration and awareness among team members about the tools being utilized in the development process.
207
+
208
+ If you prefer to disable this feature, simply run the following command:
209
+
210
+ ```bash
211
+ gpt-pr-config set add_tool_signature false
212
+ ```
213
+
214
+ ### Reset config
215
+
216
+ To reset any config to default value, just run:
217
+
218
+ ```bash
219
+ gpt-pr-config reset config_name
220
+ ```
221
+
222
+ Example:
223
+
224
+ ```bash
225
+ gpt-pr-config reset openai_model
226
+ ```
227
+
228
+ ## Usage
229
+
230
+ ### Generating Github Pull Requests
231
+
232
+ To create a Pull request from your current branch commits to merge with `main` branch, just run:
233
+
234
+ ```
235
+ gpt-pr
236
+ ```
237
+
238
+ If you would like to compare with other base branch that is not `main`, just use `-b` param:
239
+
240
+ ```
241
+ gpt-pr -b my-other-branch
242
+ ```
243
+
244
+ ### Usage help
245
+
246
+ To show help commands:
247
+
248
+ ```
249
+ gpt-pr -h
250
+ ```
251
+
252
+ Output:
253
+ ![image](https://github.com/alissonperez/gpt-pr/assets/756802/cc6c0ca4-5759-44ce-ad35-e4e7305b3875)
254
+
255
+ ## Roadmap
256
+
257
+ - [x] Improve execution method, possibly through a shell script or at least an alias in bash rc files.
258
+ - Change to use with pip installation and console_scripts entry point.
259
+ - [x] Fetch GitHub PR templates from the current project.
260
+ - [ ] Add configuration to set which LLM and model should be used (OpenAI GPT, Mistral, etc...)
261
+ - [ ] Add unit tests.
@@ -0,0 +1,3 @@
1
+ from importlib.metadata import version
2
+
3
+ __version__ = version(__name__)
@@ -0,0 +1,93 @@
1
+ import requests
2
+ import os
3
+ import json
4
+ import tempfile
5
+ from gpt_pr import __version__
6
+ from datetime import datetime, timedelta
7
+
8
+ from gpt_pr import consolecolor as cc
9
+
10
+
11
+ PACKAGE_NAME = "gpt-pr"
12
+ CACHE_FILE = os.path.join(os.path.expanduser("~"), ".gpt_pr_update_cache.json")
13
+ CACHE_DURATION = timedelta(days=1)
14
+
15
+
16
+ def cache_daily_version(func):
17
+ def wrapper(*args, **kwargs):
18
+ cache = load_cache()
19
+ last_checked = cache.get("last_checked")
20
+
21
+ if last_checked:
22
+ last_checked = datetime.fromisoformat(last_checked)
23
+
24
+ if datetime.now() - last_checked < CACHE_DURATION:
25
+ # Use cached version info
26
+ latest_version = cache.get("latest_version")
27
+ if latest_version:
28
+ return latest_version
29
+
30
+ latest_version = func(*args, **kwargs)
31
+ cache = {
32
+ "last_checked": datetime.now().isoformat(),
33
+ "latest_version": latest_version,
34
+ }
35
+ save_cache(cache)
36
+
37
+ return latest_version
38
+
39
+ return wrapper
40
+
41
+
42
+ def get_cache_file_path():
43
+ temp_dir = tempfile.gettempdir()
44
+ return os.path.join(temp_dir, f"{PACKAGE_NAME}_update_cache.json")
45
+
46
+
47
+ @cache_daily_version
48
+ def get_latest_version():
49
+ url = f"https://pypi.org/pypi/{PACKAGE_NAME}/json"
50
+
51
+ try:
52
+ response = requests.get(url)
53
+ response.raise_for_status()
54
+ data = response.json()
55
+ return data["info"]["version"]
56
+ except requests.exceptions.RequestException as e:
57
+ print(f"Error fetching latest version info: {e}")
58
+ return None
59
+
60
+
61
+ def load_cache():
62
+ cache_file = get_cache_file_path()
63
+ if os.path.exists(cache_file):
64
+ with open(cache_file, "r") as file:
65
+ return json.load(file)
66
+
67
+ return {}
68
+
69
+
70
+ def save_cache(data):
71
+ cache_file = get_cache_file_path()
72
+ with open(cache_file, "w") as file:
73
+ file.write(json.dumps(data))
74
+
75
+
76
+ def check_for_updates():
77
+ latest_version = get_latest_version()
78
+
79
+ if latest_version and latest_version != __version__:
80
+ print("")
81
+ print(
82
+ cc.yellow(
83
+ f"A new version of {PACKAGE_NAME} is available ({latest_version}). "
84
+ f"You are using version {__version__}. Please update by running"
85
+ ),
86
+ cc.green(f"pip install --upgrade {PACKAGE_NAME}."),
87
+ )
88
+ print("")
89
+
90
+
91
+ if __name__ == "__main__":
92
+ check_for_updates()
93
+ # Your CLI code here