Skip to content

Commit 4ddf370

Browse files
Add packaging as a dependency, update README, remove project_path from CLI
1 parent 0bfdcff commit 4ddf370

File tree

6 files changed

+91
-63
lines changed

6 files changed

+91
-63
lines changed

README.md

Lines changed: 54 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,59 @@
33
CLI tool to check for dependency updates in your python project. Automatically creates
44
GitHub pull requests for dependencies you wish to update!
55

6+
## Usage
7+
8+
If you have `uv` installed, you can install `upgrade-dependencies` with
9+
10+
```
11+
uv tool install upgrade-dependencies
12+
```
13+
14+
You can then navigate to your project directory and execute:
15+
16+
```
17+
uvx upgrade-dependencies [OPTIONS] [COMMAND]
18+
```
19+
20+
### Requirements
21+
22+
All python requirements are installed by default. To successfully use the `update`
23+
command the following executables must be installed into your shell:
24+
25+
- `git`
26+
- `gh`, i.e. GitHub CLI - ensure you have already run `gh auth login` and added
27+
appropriate permissions
28+
29+
### GitHub API Rate Limit
30+
31+
The GitHub API is used to fetch data for GitHub actions and `pre-commit` repos.
32+
Unauthenticated users have a rate limit of 60 requests per hour, whereas authenticated
33+
users have a rate limit of 5,000 requests per hour. You can use a GitHub personal access
34+
token to utilise this higher rate limit by setting the `GH_PAT` environment variable:
35+
36+
```
37+
export GH_PAT=github_pat_xxx
38+
```
39+
640
## Limitations
741

8-
- Currently only supports a single specifier.
9-
- File structure is fixed
10-
- GH actions must only use major version
11-
- Recommend to have a clean git before running (or at least no changes to pyproject etc.)
12-
13-
## TODO
14-
15-
- [x] Async data retrieval
16-
- [x] Get dependencies from github actions
17-
- [x] Get uv dependency from github actions
18-
- [x] Get dependencies from pre-commit
19-
- [x] Github auth & async
20-
- [x] Create dependency abstract class
21-
- [x] Use get_dependency
22-
- [x] Implement CLI
23-
- [x] Create changes to files
24-
- [ ] Handle uv better (not group)
25-
- [x] Create pull request
26-
- [ ] Documentation
27-
- [ ] Add tests
42+
- Currently only supports a single specifier, e.g. `numpy~=2.0.2`, not `numpy>=2,<2.1`
43+
- The project file structure is fixed and assumed, see
44+
[Project File Structure](#project-file-structure).
45+
- GH actions must only use major version, e.g. `actions/checkout@v4` not
46+
47+
- It is recommended to have a clean git before running `update` (a warning will be
48+
printed to the terminal if this is not the case).
49+
50+
## Project File Structure
51+
52+
The following project file structure is assumed:
53+
54+
```
55+
project
56+
├── .github
57+
│ └── workflows
58+
│ └── *.yml
59+
├── .pre-commit-config.yml
60+
└── pyproject.toml
61+
```

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,14 @@ authors = [
1010
requires-python = ">=3.13"
1111
dependencies = [
1212
"httpx~=0.27.2",
13+
"packaging~=24.2",
1314
"ruamel-yaml~=0.18.6",
1415
"tomlkit~=0.13.2",
1516
"typer~=0.13.1",
1617
]
1718

1819
[project.scripts]
19-
up-deps = "upgrade_dependencies.main:main"
20+
upgrade-dependencies = "upgrade_dependencies.main:main"
2021

2122
[dependency-groups]
2223
dev = [

src/upgrade_dependencies/main.py

Lines changed: 16 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,9 @@
2424

2525

2626
@app.command()
27-
def list_dependencies(project_path: str = ""):
28-
"""Checks whether a dependency needs updating.
29-
30-
Args:
31-
project_path: Path to the project. Defaults to the current working directory.
32-
"""
33-
project = Project(
34-
project_path=project_path,
35-
gh_pat=GH_PAT,
36-
)
27+
def list_dependencies():
28+
"""Checks whether a dependency needs updating."""
29+
project = Project(gh_pat=GH_PAT)
3730

3831
# base dependencies
3932
title = Text("Base Dependencies", style="bold")
@@ -126,20 +119,13 @@ def list_dependencies(project_path: str = ""):
126119

127120

128121
@app.command()
129-
def check_dependency(
130-
dependency: str,
131-
project_path: str = "",
132-
):
122+
def check_dependency(dependency: str):
133123
"""Checks whether a dependency needs updating.
134124
135125
Args:
136126
dependency: Name of the dependency to check.
137-
project_path: Path to the project. Defaults to the current working directory.
138127
"""
139-
project = Project(
140-
project_path=project_path,
141-
gh_pat=GH_PAT,
142-
)
128+
project = Project(gh_pat=GH_PAT)
143129

144130
try:
145131
dep = project.get_dependency(name=dependency)
@@ -170,7 +156,6 @@ def check_dependency(
170156

171157
@app.command()
172158
def needs_updating(
173-
project_path: str = "",
174159
base: bool = True,
175160
optional_deps: bool = True,
176161
group_deps: bool = True,
@@ -180,7 +165,6 @@ def needs_updating(
180165
"""List the dependencies that need updating.
181166
182167
Args:
183-
project_path: Path to the project. Defaults to the current working directory.
184168
base: If set to True, includes the base dependencies. Defaults to True.
185169
optional_deps: If set to True, includes the optional dependencies. Defaults to
186170
True.
@@ -191,10 +175,7 @@ def needs_updating(
191175
True.
192176
"""
193177
# create project object
194-
project = Project(
195-
project_path=project_path,
196-
gh_pat=GH_PAT,
197-
)
178+
project = Project(gh_pat=GH_PAT)
198179

199180
# fetch relevant data
200181
if base or optional_deps or group_deps:
@@ -244,7 +225,6 @@ def needs_updating(
244225

245226
@app.command()
246227
def latest_versions(
247-
project_path: str = "",
248228
base: bool = True,
249229
optional_deps: bool = True,
250230
group_deps: bool = True,
@@ -254,7 +234,6 @@ def latest_versions(
254234
"""List the dependencies that aren't pinned to the latest version.
255235
256236
Args:
257-
project_path: Path to the project. Defaults to the current working directory.
258237
base: If set to True, includes the base dependencies. Defaults to True.
259238
optional_deps: If set to True, includes the optional dependencies. Defaults to
260239
True.
@@ -265,10 +244,7 @@ def latest_versions(
265244
True.
266245
"""
267246
# create project object
268-
project = Project(
269-
project_path=project_path,
270-
gh_pat=GH_PAT,
271-
)
247+
project = Project(gh_pat=GH_PAT)
272248

273249
# fetch relevant data
274250
if base or optional_deps or group_deps:
@@ -320,7 +296,7 @@ def latest_versions(
320296
def update(
321297
dependency: str,
322298
version: str | None = None,
323-
project_path: str = "",
299+
target_branch: str = "master",
324300
):
325301
"""_summary_.
326302
@@ -329,18 +305,15 @@ def update(
329305
Args:
330306
dependency: _description_
331307
version: _description_
332-
project_path: _description_
308+
target_branch: _description_
333309
"""
334310
with Progress(
335311
SpinnerColumn(),
336312
TextColumn("[progress.description]{task.description}"),
337313
transient=True,
338314
) as progress:
339315
task = progress.add_task("Creating project...")
340-
project = Project(
341-
project_path=project_path,
342-
gh_pat=GH_PAT,
343-
)
316+
project = Project(gh_pat=GH_PAT)
344317

345318
# search for dependency and save old version
346319
try:
@@ -435,7 +408,7 @@ def update(
435408
"-a",
436409
"@me",
437410
"--base",
438-
"master",
411+
target_branch,
439412
"--body",
440413
pr_body,
441414
"--label",
@@ -445,10 +418,12 @@ def update(
445418
],
446419
)
447420

448-
# re-checkout master
449-
run_shell_command(["git", "checkout", "master"])
421+
# re-checkout master branch
422+
run_shell_command(["git", "checkout", target_branch])
450423

451-
rprint(f"✅ {dep.package_name} updated! View the pull request at {pr.stdout}")
424+
msg = f"✅ [bold]{dep.package_name}[/bold] updated! View the pull request at"
425+
msg += f" {pr.stdout}"
426+
rprint(msg)
452427

453428

454429
def main():

src/upgrade_dependencies/project.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class Project:
2323

2424
def __init__(
2525
self,
26-
project_path: str,
26+
project_path: str = "",
2727
gh_pat: str | None = None,
2828
) -> None:
2929
"""_summary_.

todo.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# TODO
2+
3+
- [x] Async data retrieval
4+
- [x] Get dependencies from github actions
5+
- [x] Get uv dependency from github actions
6+
- [x] Get dependencies from pre-commit
7+
- [x] Github auth & async
8+
- [x] Create dependency abstract class
9+
- [x] Use get_dependency
10+
- [x] Implement CLI
11+
- [x] Create changes to files
12+
- [ ] Handle uv better (not group)
13+
- [x] Create pull request
14+
- [ ] Add format yml files
15+
- [ ] Documentation
16+
- [ ] Add tests

uv.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)