Skip to content

Commit 0566ebc

Browse files
Start implementing auto git commands
1 parent 7feb1ac commit 0566ebc

File tree

5 files changed

+128
-38
lines changed

5 files changed

+128
-38
lines changed

.github/workflows/ci.yml

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ name: CI
33
on:
44
push:
55
branches:
6-
- master
6+
- master
77
pull_request:
88
types: [opened, reopened, synchronize]
99

1010
env:
11-
UV_VERSION: "0.5.4"
12-
DEFAULT_PYTHON_VERSION: "3.13"
11+
UV_VERSION: 0.5.4
12+
DEFAULT_PYTHON_VERSION: '3.13'
1313

1414
concurrency:
1515
group: ${{ github.workflow }}-${{ github.ref }}
@@ -21,43 +21,44 @@ jobs:
2121
runs-on: ubuntu-latest
2222

2323
steps:
24-
- name: Check out the repo
25-
uses: actions/checkout@v4
24+
- name: Check out the repo
25+
uses: actions/checkout@v4
2626

27-
- name: Install uv version ${{ env.UV_VERSION }}
28-
uses: astral-sh/setup-uv@v3
29-
with:
30-
version: ${{ env.UV_VERSION }}
31-
enable-cache: true
27+
- name: Install uv version ${{ env.UV_VERSION }}
28+
uses: astral-sh/setup-uv@v3
29+
with:
30+
version: ${{ env.UV_VERSION }}
31+
enable-cache: true
3232

33-
- name: Install python ${{ env.DEFAULT_PYTHON_VERSION }} using uv
34-
run: uv python install ${{ env.DEFAULT_PYTHON_VERSION }}
33+
- name: Install python ${{ env.DEFAULT_PYTHON_VERSION }} using uv
34+
run: uv python install ${{ env.DEFAULT_PYTHON_VERSION }}
3535

36-
- name: Install dependencies
37-
run: uv sync -p ${{ env.DEFAULT_PYTHON_VERSION }} --frozen
36+
- name: Install dependencies
37+
run: uv sync -p ${{ env.DEFAULT_PYTHON_VERSION }} --frozen
3838

39-
- name: Run pre-commit
40-
run: uv run -p ${{ env.DEFAULT_PYTHON_VERSION }} --no-sync pre-commit run --all-files --color always --show-diff-on-failure
39+
- name: Run pre-commit
40+
run: uv run -p ${{ env.DEFAULT_PYTHON_VERSION }} --no-sync pre-commit run --all-files
41+
--color always --show-diff-on-failure
4142

4243
type-checking:
4344
name: type-checking
4445
runs-on: ubuntu-latest
4546

4647
steps:
47-
- name: Check out the repo
48-
uses: actions/checkout@v4
48+
- name: Check out the repo
49+
uses: actions/checkout@v4
4950

50-
- name: Install uv version ${{ env.UV_VERSION }}
51-
uses: astral-sh/setup-uv@v3
52-
with:
53-
version: ${{ env.UV_VERSION }}
54-
enable-cache: true
51+
- name: Install uv version ${{ env.UV_VERSION }}
52+
uses: astral-sh/setup-uv@v3
53+
with:
54+
version: ${{ env.UV_VERSION }}
55+
enable-cache: true
5556

56-
- name: Install python ${{ env.DEFAULT_PYTHON_VERSION }} using uv
57-
run: uv python install ${{ env.DEFAULT_PYTHON_VERSION }}
57+
- name: Install python ${{ env.DEFAULT_PYTHON_VERSION }} using uv
58+
run: uv python install ${{ env.DEFAULT_PYTHON_VERSION }}
5859

59-
- name: Install dependencies
60-
run: uv sync -p ${{ env.DEFAULT_PYTHON_VERSION }} --frozen
60+
- name: Install dependencies
61+
run: uv sync -p ${{ env.DEFAULT_PYTHON_VERSION }} --frozen
6162

62-
- name: Run pyright
63-
run: uv run -p ${{ env.DEFAULT_PYTHON_VERSION }} --no-sync pyright
63+
- name: Run pyright
64+
run: uv run -p ${{ env.DEFAULT_PYTHON_VERSION }} --no-sync pyright

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Creates PRs for dependency updates in python projects.
1919
- [x] Use get_dependency
2020
- [ ] Implement CLI
2121
- [x] Create changes to files
22+
- [ ] Handle uv better (not group)
2223
- [ ] Create pull request
2324
- [ ] Add tests
2425
- [ ] Documentation

src/upgrade_dependencies/dependency.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,15 @@ def loc(self) -> str:
8686
"""
8787
raise NotImplementedError
8888

89+
@property
90+
def short_name(self) -> str:
91+
"""_summary_.
92+
93+
Returns:
94+
_description_
95+
"""
96+
raise NotImplementedError
97+
8998
def __repr__(self) -> str:
9099
"""_summary_.
91100
@@ -159,6 +168,15 @@ def loc(self) -> str:
159168
else:
160169
return f" ({self.group})"
161170

171+
@property
172+
def short_name(self) -> str:
173+
"""_summary_.
174+
175+
Returns:
176+
_description_
177+
"""
178+
return self.package_name
179+
162180

163181
class GitHubDependency(Dependency):
164182
"""_summary_."""
@@ -255,3 +273,12 @@ def loc(self) -> str:
255273
_description_
256274
"""
257275
return " (gha)" if self.action else " (pre-commit)"
276+
277+
@property
278+
def short_name(self) -> str:
279+
"""_summary_.
280+
281+
Returns:
282+
_description_
283+
"""
284+
return self.repo

src/upgrade_dependencies/main.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,68 @@ def latest_versions(
312312
rprint(Panel(text, title=title, title_align="left"))
313313

314314

315+
@app.command()
316+
def update(
317+
dependency: str,
318+
version: str | None = None,
319+
project_path: str = "",
320+
):
321+
"""_summary_.
322+
323+
Args:
324+
dependency: _description_
325+
version: _description_
326+
project_path: _description_
327+
"""
328+
project = Project(
329+
project_path=project_path,
330+
gh_pat=GH_PAT,
331+
)
332+
333+
try:
334+
dep = project.get_dependency(name=dependency)
335+
old_ver = str(sorted(dep.specifier, key=str)[0].version)
336+
except RuntimeError as e:
337+
rprint(f"Cannot find {dependency} in {project.name}.")
338+
raise typer.Exit(code=1) from e
339+
340+
asyncio.run(dep.save_data())
341+
342+
# get version
343+
if version is None:
344+
version = str(dep.get_latest_version())
345+
346+
# # create new branch
347+
# if isinstance(dep, GitHubDependency) and dep.action:
348+
# v = Version(version)
349+
# branch_name = f"dependency/{dep.short_name}-v{v.major}"
350+
# else:
351+
# branch_name = f"dependency/{dep.short_name}-{version}"
352+
353+
# subprocess.run(['git', 'checkout', '-b', branch_name])
354+
355+
# update dependency
356+
project.update_dependency(dependency=dep, version=version)
357+
358+
# # stage changes - TODO: get files that are changed
359+
# subprocess.run(['git', 'add', '.github/'])
360+
361+
# # commit the changes
362+
# if isinstance(dep, GitHubDependency) and dep.action:
363+
# old_v = Version(old_ver)
364+
# v = Version(version)
365+
# commit_message = f"Bump {dep.package_name} from v{old_v.major} to v{v.major}"
366+
# else:
367+
# commit_message = f"Bump {dep.package_name} from {old_ver} to {version}"
368+
369+
# subprocess.run(['git', 'commit', '-m', commit_message])
370+
371+
# # push the branch
372+
# subprocess.run(['git', 'push', 'origin', branch_name])
373+
374+
# TODO: create pull request
375+
376+
315377
def main():
316378
"""_summary_."""
317379
app()

src/upgrade_dependencies/project.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -356,18 +356,14 @@ def github_dependency_data_async(self) -> None:
356356
def update_dependency(
357357
self,
358358
dependency: Dependency,
359-
version: str | None = None,
359+
version: str,
360360
) -> None:
361361
"""_summary_.
362362
363363
Args:
364364
dependency: _description_
365-
version: _description_. Defaults to None.
365+
version: _description_
366366
"""
367-
# get version
368-
if version is None:
369-
version = str(dependency.get_latest_version())
370-
371367
# update pypi dependencies
372368
if isinstance(dependency, PyPIDependency):
373369
# handle special case uv, lives in github actions
@@ -410,8 +406,8 @@ def update_dependency(
410406
raise RuntimeError(msg)
411407

412408
# write new pyproject.toml file
413-
temp_ppt = ppt_file_path.with_suffix(".temp")
414-
with temp_ppt.open("w") as temp_f:
409+
# temp_ppt = ppt_file_path.with_suffix(".temp")
410+
with Path(ppt_file_path).open("w") as temp_f:
415411
tomlkit.dump(data=ppt, fp=temp_f) # pyright: ignore
416412
# github dependencies
417413
elif isinstance(dependency, GitHubDependency):
@@ -432,11 +428,14 @@ def update_dependency(
432428
# get pre-commit path
433429
pre_commit_path = Path(self.project_path) / ".pre-commit-config.yaml"
434430

431+
# ensure x.x.x for version
432+
v = Version(version)
433+
435434
# update dependency
436435
utils.update_pre_commit(
437436
file_path=pre_commit_path,
438437
dependency=dependency,
439-
new_version=version,
438+
new_version=f"{v.major}.{v.minor}.{v.micro}",
440439
)
441440

442441
def get_dependency(

0 commit comments

Comments
 (0)