Skip to content

Commit 0bfdcff

Browse files
Add warning about uncomitted changes, run uv lock
1 parent b10dfaa commit 0bfdcff

File tree

3 files changed

+35
-12
lines changed

3 files changed

+35
-12
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# upgrade-dependencies
22

3-
Creates PRs for dependency updates in python projects.
3+
CLI tool to check for dependency updates in your python project. Automatically creates
4+
GitHub pull requests for dependencies you wish to update!
45

56
## Limitations
67

@@ -22,5 +23,5 @@ Creates PRs for dependency updates in python projects.
2223
- [x] Create changes to files
2324
- [ ] Handle uv better (not group)
2425
- [x] Create pull request
25-
- [ ] Add tests
2626
- [ ] Documentation
27+
- [ ] Add tests

src/upgrade_dependencies/main.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -372,15 +372,26 @@ def update(
372372
progress.update(task, description="Updating dependency...")
373373
files_before = get_git_status()
374374

375+
# warning if there are changed files
376+
if len(files_before) > 0:
377+
msg = ":warning-emoji: [italic]There are uncomitted changes in your current"
378+
msg += " branch. upgrade-dependencies will only commit files that were"
379+
msg += " unmodified prior to running [bold]update[/bold][/italic]."
380+
rprint(msg)
381+
375382
# update dependency
376383
project.update_dependency(dependency=dep, version=version)
377384

385+
# run uv.lock, don't worry if it doesn't work (i.e. uv not installed)
386+
run_shell_command(["uv", "lock"], suppress_errors=True)
387+
378388
# get status of files after changes
379389
files_after = get_git_status()
380390

381391
# get only the files that were changed
382392
changed_files = [f for f in files_after if f not in files_before]
383393

394+
# git add the changed files
384395
run_shell_command(["git", "add", *changed_files])
385396

386397
# commit the changes
@@ -396,7 +407,7 @@ def update(
396407

397408
run_shell_command(["git", "commit", "-m", commit_message])
398409

399-
# push the branch
410+
# push the branch to GitHub
400411
progress.update(task, description="Pushing changes to GitHub...")
401412
run_shell_command(["git", "push", "origin", branch_name])
402413

@@ -437,7 +448,7 @@ def update(
437448
# re-checkout master
438449
run_shell_command(["git", "checkout", "master"])
439450

440-
rprint(f"✅Dependency updated! View the pull request at {pr.stdout}")
451+
rprint(f"✅ {dep.package_name} updated! View the pull request at {pr.stdout}")
441452

442453

443454
def main():

src/upgrade_dependencies/utils.py

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -250,21 +250,32 @@ def update_pre_commit(
250250
yaml.dump(data, temp_f) # pyright: ignore
251251

252252

253-
def run_shell_command(shell_args: list[str]) -> Any:
253+
def run_shell_command(
254+
shell_args: list[str],
255+
suppress_errors: bool = False,
256+
) -> Any:
254257
"""_summary_.
255258
256259
Args:
257260
shell_args: _description_
261+
suppress_errors: _description_
258262
259263
Returns:
260264
_description_
261265
"""
262-
try:
263-
res = subprocess.run(shell_args, check=True, capture_output=True, text=True) # noqa: S603
264-
except subprocess.CalledProcessError as e:
265-
msg = f"Command failed with return code {e.returncode}.\n"
266-
msg += f"Error output: {e.stderr}"
267-
raise RuntimeError(msg) from e
266+
if suppress_errors:
267+
res = subprocess.run( # noqa: S603
268+
shell_args,
269+
stdout=subprocess.DEVNULL,
270+
stderr=subprocess.DEVNULL,
271+
)
272+
else:
273+
try:
274+
res = subprocess.run(shell_args, check=True, capture_output=True, text=True) # noqa: S603
275+
except subprocess.CalledProcessError as e:
276+
msg = f"Command failed with return code {e.returncode}.\n"
277+
msg += f"Error output: {e.stderr}"
278+
raise RuntimeError(msg) from e
268279

269280
return res
270281

@@ -283,7 +294,7 @@ def get_git_status() -> list[str]:
283294
for line in result.stdout.strip().split("\n"):
284295
status, file_path = line.split(maxsplit=1) # status and file name
285296

286-
if status in ["M", "A", "D"]: # Modified, Added, or Deleted
297+
if status in ["M", "A", "D"]: # modified, added, or deleted
287298
changed_files.append(file_path)
288299

289300
return changed_files

0 commit comments

Comments
 (0)