pyupcheck 0.3.0__tar.gz → 0.3.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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pyupcheck
3
- Version: 0.3.0
3
+ Version: 0.3.2
4
4
  Summary: Check if upgrading a Python dependency will break your code
5
5
  Author: AgbaDev
6
6
  License-Expression: MIT
@@ -1,3 +1,3 @@
1
1
  """depshift - Check if upgrading a Python dependency will break your code."""
2
2
 
3
- __version__ = "0.3.0"
3
+ __version__ = "0.3.2"
@@ -2,6 +2,7 @@
2
2
 
3
3
  import json as _json
4
4
  import os
5
+ import re
5
6
  import sys
6
7
  from datetime import datetime
7
8
  from typing import List, Optional
@@ -18,6 +19,7 @@ from depshift.changelog import (
18
19
  get_changes_between,
19
20
  get_current_version,
20
21
  get_available_versions,
22
+ get_pypi_info,
21
23
  )
22
24
  from depshift.analyzer import analyze
23
25
  from depshift.deps import discover_dependencies
@@ -39,8 +41,41 @@ def get_installed_version(package: str) -> Optional[str]:
39
41
  return None
40
42
 
41
43
 
44
+ def _filter_by_since(changes, since_str: str, package: str):
45
+ """Filter changelog entries to only those introduced after since_str (YYYY-MM-DD)."""
46
+ try:
47
+ since_dt = datetime.strptime(since_str, "%Y-%m-%d")
48
+ except ValueError:
49
+ return changes # bad date format, return unfiltered
50
+
51
+ try:
52
+ info = get_pypi_info(package)
53
+ releases = info.get("releases", {})
54
+ except Exception:
55
+ return changes # can't fetch, return unfiltered
56
+
57
+ def version_date(ver: str) -> Optional[datetime]:
58
+ for f in releases.get(ver, []):
59
+ upload = f.get("upload_time")
60
+ if upload:
61
+ try:
62
+ return datetime.strptime(upload[:10], "%Y-%m-%d")
63
+ except Exception:
64
+ pass
65
+ return None
66
+
67
+ filtered = []
68
+ for c in changes:
69
+ vd = version_date(c.version)
70
+ if vd is None:
71
+ continue # unknown date — exclude when filtering by date
72
+ if vd >= since_dt:
73
+ filtered.append(c)
74
+ return filtered
75
+
76
+
42
77
  def _run_single_check(package: str, target_version: Optional[str], directory: str,
43
- github_token: Optional[str], cfg, quiet: bool,
78
+ github_token: Optional[str], cfg, suppress_errors: bool = False,
44
79
  since: Optional[str] = None) -> Optional[dict]:
45
80
  installed = get_installed_version(package)
46
81
 
@@ -48,7 +83,7 @@ def _run_single_check(package: str, target_version: Optional[str], directory: st
48
83
  try:
49
84
  target_version = get_current_version(package)
50
85
  except Exception as e:
51
- if not quiet:
86
+ if not suppress_errors:
52
87
  console.print(f"[red]{package}:[/] not found on PyPI ({e})")
53
88
  return None
54
89
 
@@ -75,33 +110,8 @@ def _run_single_check(package: str, target_version: Optional[str], directory: st
75
110
  except Exception:
76
111
  changes = []
77
112
 
78
- # --since filter
79
113
  if since and changes:
80
- try:
81
- since_dt = datetime.strptime(since, "%Y-%m-%d")
82
- from packaging.version import Version, InvalidVersion
83
- from depshift.changelog import get_pypi_info
84
- try:
85
- info = get_pypi_info(package)
86
- releases = info.get("releases", {})
87
- def version_date(ver: str) -> Optional[datetime]:
88
- files = releases.get(ver, [])
89
- for f in files:
90
- upload = f.get("upload_time")
91
- if upload:
92
- try:
93
- return datetime.strptime(upload[:10], "%Y-%m-%d")
94
- except Exception:
95
- pass
96
- return None
97
- changes = [
98
- c for c in changes
99
- if (version_date(c.version) or since_dt) >= since_dt
100
- ]
101
- except Exception:
102
- pass
103
- except ValueError:
104
- pass
114
+ changes = _filter_by_since(changes, since, package)
105
115
 
106
116
  risks, safe = analyze(usages, changes, package)
107
117
 
@@ -190,7 +200,10 @@ def _print_terminal_result(r: dict, quiet: bool):
190
200
  for risk in r["risks"]:
191
201
  color = {"breaking": "red", "deprecated": "yellow", "warning": "blue"}[risk["severity"]]
192
202
  mark = {"breaking": "x", "deprecated": "!", "warning": "?"}[risk["severity"]]
193
- rel = os.path.relpath(risk["file"])
203
+ try:
204
+ rel = os.path.relpath(risk["file"])
205
+ except ValueError:
206
+ rel = risk["file"]
194
207
  console.print(f" [{color}]{mark}[/] [bold]{rel}:{risk['line']}[/] {risk['code']}")
195
208
  console.print(f" [dim]{risk['change_description']}[/]")
196
209
 
@@ -219,7 +232,7 @@ def main(ctx):
219
232
  @click.option("--exclude", "-e", multiple=True)
220
233
  @click.option("--no-cache", is_flag=True)
221
234
  @click.option("--quiet", "-q", is_flag=True)
222
- @click.option("--since", default=None, metavar="YYYY-MM-DD", help="Only show changes since this date")
235
+ @click.option("--since", default=None, metavar="YYYY-MM-DD", help="Only show changes introduced since this date")
223
236
  def check(package, target_version, directory, github_token, fmt, output, fail_on,
224
237
  min_severity, exclude, no_cache, quiet, since):
225
238
  """Check if upgrading PACKAGE to TARGET_VERSION will break your code."""
@@ -234,7 +247,8 @@ def check(package, target_version, directory, github_token, fmt, output, fail_on
234
247
  cache_mod.disable_cache()
235
248
 
236
249
  with console.status(f"Checking [bold]{package}[/]..."):
237
- result = _run_single_check(package, target_version, directory, github_token, cfg, quiet, since=since)
250
+ result = _run_single_check(package, target_version, directory, github_token,
251
+ cfg, suppress_errors=quiet, since=since)
238
252
 
239
253
  if result is None:
240
254
  sys.exit(2)
@@ -278,6 +292,7 @@ def check_all(directory, github_token, fmt, output, fail_on, min_severity, exclu
278
292
  if not quiet:
279
293
  console.print(f"Found [bold]{len(deps)}[/] dependencies to check\n")
280
294
 
295
+ # collect all results with progress bar, then print
281
296
  results = []
282
297
  with Progress(
283
298
  SpinnerColumn(),
@@ -291,32 +306,35 @@ def check_all(directory, github_token, fmt, output, fail_on, min_severity, exclu
291
306
  task = progress.add_task("Checking dependencies...", total=len(deps))
292
307
  for dep in deps:
293
308
  progress.update(task, description=f"Checking [bold]{dep.name}[/]...")
294
- r = _run_single_check(dep.name, None, directory, github_token, cfg, quiet=True, since=since)
309
+ r = _run_single_check(dep.name, None, directory, github_token, cfg,
310
+ suppress_errors=True, since=since)
295
311
  if r:
296
312
  results.append(r)
297
- if fmt == "terminal" and not quiet:
298
- progress.stop()
299
- _print_terminal_result(r, quiet)
300
- progress.start()
301
313
  progress.advance(task)
302
314
 
303
- if fmt != "terminal":
315
+ # print results after progress bar closes cleanly
316
+ if fmt == "terminal":
317
+ for r in results:
318
+ _print_terminal_result(r, quiet)
319
+
320
+ total_breaking = sum(r["breaking_count"] for r in results)
321
+ total_deprecated = sum(r["deprecated_count"] for r in results)
322
+ if not quiet:
323
+ console.print()
324
+ if total_breaking:
325
+ console.print(Panel(
326
+ f"[red bold]{total_breaking} breaking[/] | [yellow]{total_deprecated} deprecated[/] across {len(results)} packages",
327
+ border_style="red"))
328
+ elif total_deprecated:
329
+ console.print(Panel(f"[yellow]{total_deprecated} deprecated[/] across {len(results)} packages",
330
+ border_style="yellow"))
331
+ else:
332
+ console.print(Panel(f"[green]All {len(results)} packages safe to upgrade[/]",
333
+ border_style="green"))
334
+ if output:
335
+ _emit(results, "md", output, quiet)
336
+ else:
304
337
  _emit(results, fmt, output, quiet)
305
- elif output:
306
- _emit(results, "md", output, quiet)
307
-
308
- total_breaking = sum(r["breaking_count"] for r in results)
309
- total_deprecated = sum(r["deprecated_count"] for r in results)
310
- if fmt == "terminal" and not quiet:
311
- console.print()
312
- if total_breaking:
313
- console.print(Panel(
314
- f"[red bold]{total_breaking} breaking[/] | [yellow]{total_deprecated} deprecated[/] across {len(results)} packages",
315
- border_style="red"))
316
- elif total_deprecated:
317
- console.print(Panel(f"[yellow]{total_deprecated} deprecated[/] across {len(results)} packages", border_style="yellow"))
318
- else:
319
- console.print(Panel(f"[green]All {len(results)} packages safe to upgrade[/]", border_style="green"))
320
338
 
321
339
  sys.exit(1 if _should_fail(results, cfg.fail_on) else 0)
322
340
 
@@ -358,28 +376,28 @@ def fix(directory, dry_run, no_cache):
358
376
  task = progress.add_task("Scanning...", total=len(deps))
359
377
  for dep in deps:
360
378
  progress.update(task, description=f"Checking [bold]{dep.name}[/]...")
361
- installed = get_installed_version(dep.name)
362
- try:
363
- latest = get_current_version(dep.name)
364
- except Exception:
379
+
380
+ if not dep.pinned_version:
365
381
  progress.advance(task)
366
382
  continue
367
383
 
368
- if not installed or not dep.pinned_version:
384
+ pinned = dep.pinned_version
385
+ try:
386
+ latest = get_current_version(dep.name)
387
+ except Exception:
369
388
  progress.advance(task)
370
389
  continue
371
390
 
372
391
  try:
373
- if Version(installed) >= Version(latest):
392
+ if Version(pinned) >= Version(latest):
374
393
  progress.advance(task)
375
394
  continue
376
395
  except InvalidVersion:
377
396
  progress.advance(task)
378
397
  continue
379
398
 
380
- # check if upgrade is safe
381
399
  try:
382
- changes = get_changes_between(dep.name, installed, latest)
400
+ changes = get_changes_between(dep.name, pinned, latest)
383
401
  except Exception:
384
402
  changes = []
385
403
 
@@ -390,17 +408,18 @@ def fix(directory, dry_run, no_cache):
390
408
  if not breaking:
391
409
  updates.append({
392
410
  "name": dep.name,
393
- "old": dep.pinned_version,
411
+ "old": pinned,
394
412
  "new": latest,
395
413
  "source": dep.source,
396
414
  })
397
415
  progress.advance(task)
398
416
 
399
417
  if not updates:
400
- console.print("[green]Nothing to update.[/] All pinned versions are already at latest safe version.")
418
+ console.print("[green]Nothing to update.[/] All pinned deps are at the latest safe version.")
401
419
  return
402
420
 
403
- console.print(f"\n{'[dim]DRY RUN - no files written[/]' if dry_run else ''}")
421
+ if dry_run:
422
+ console.print("[dim]DRY RUN - no files written[/]\n")
404
423
  console.print(f"[bold]{len(updates)}[/] safe update(s):\n")
405
424
  for u in updates:
406
425
  console.print(f" [cyan]{u['name']}[/] {u['old']} -> [green]{u['new']}[/] [dim]({u['source']})[/]")
@@ -408,13 +427,11 @@ def fix(directory, dry_run, no_cache):
408
427
  if dry_run:
409
428
  return
410
429
 
411
- # apply rewrites
412
430
  for req_path in req_files:
413
431
  try:
414
432
  with open(req_path, "r", encoding="utf-8") as f:
415
433
  content = f.read()
416
434
  for u in updates:
417
- import re
418
435
  content = re.sub(
419
436
  rf"(?i)({re.escape(u['name'])}\s*==\s*){re.escape(u['old'])}",
420
437
  rf"\g<1>{u['new']}",
@@ -500,7 +517,7 @@ def ci_setup(ci_type, directory):
500
517
  path = os.path.join(directory, ".pre-commit-config.yaml")
501
518
  if os.path.exists(path):
502
519
  console.print(f"[yellow]Already exists:[/] {os.path.relpath(path)} (not modified)")
503
- console.print(" Add this manually to your existing config:")
520
+ console.print("Add this to your existing config:")
504
521
  console.print(_PRE_COMMIT)
505
522
  else:
506
523
  with open(path, "w", encoding="utf-8") as f:
@@ -535,6 +552,7 @@ def outdated(directory, no_cache):
535
552
  table.add_column("Status")
536
553
 
537
554
  outdated_count = 0
555
+ rows = []
538
556
  with Progress(SpinnerColumn(), TextColumn("{task.description}"), console=console, transient=True) as progress:
539
557
  task = progress.add_task("Checking versions...", total=len(deps))
540
558
  for dep in deps:
@@ -546,7 +564,7 @@ def outdated(directory, no_cache):
546
564
  progress.advance(task)
547
565
  continue
548
566
  if not installed:
549
- table.add_row(dep.name, "-", latest, "[dim]not installed[/]")
567
+ rows.append((dep.name, "-", latest, "[dim]not installed[/]"))
550
568
  progress.advance(task)
551
569
  continue
552
570
  try:
@@ -554,12 +572,14 @@ def outdated(directory, no_cache):
554
572
  outdated_count += 1
555
573
  major_bump = Version(installed).major < Version(latest).major
556
574
  status = "[red]major bump[/]" if major_bump else "[yellow]update available[/]"
557
- table.add_row(dep.name, installed, latest, status)
575
+ rows.append((dep.name, installed, latest, status))
558
576
  except InvalidVersion:
559
577
  pass
560
578
  progress.advance(task)
561
579
 
562
580
  if outdated_count:
581
+ for row in rows:
582
+ table.add_row(*row)
563
583
  console.print(table)
564
584
  console.print(f"\n[bold]{outdated_count}[/] outdated. Run [bold]pyupcheck check-all[/] to see if upgrades are safe.")
565
585
  else:
@@ -587,6 +607,9 @@ def diff(package, from_version, to_version, github_token, no_cache, since):
587
607
  console.print(f"[red]Error:[/] {e}")
588
608
  sys.exit(2)
589
609
 
610
+ if since and changes:
611
+ changes = _filter_by_since(changes, since, package)
612
+
590
613
  if not changes:
591
614
  console.print(f"[green]No breaking/deprecated changes found[/] between {from_version} and {to_version}.")
592
615
  return
@@ -625,7 +648,10 @@ def scan(package, directory, exclude):
625
648
  table.add_column("Code", style="dim")
626
649
 
627
650
  for u in usages:
628
- rel_path = os.path.relpath(u.file)
651
+ try:
652
+ rel_path = os.path.relpath(u.file)
653
+ except ValueError:
654
+ rel_path = u.file
629
655
  table.add_row(rel_path, str(u.line), u.usage_type, u.attr_chain, u.code[:70])
630
656
 
631
657
  console.print(table)
@@ -709,7 +735,7 @@ Remove-Item Env:_PYUPCHECK_COMPLETE
709
735
  """,
710
736
  }
711
737
  print(scripts[shell])
712
- console.print(f"\n[dim]Pipe this to your shell config and restart your terminal.[/]", err=True)
738
+ console.print("\n[dim]Pipe this to your shell config and restart your terminal.[/]")
713
739
 
714
740
 
715
741
  if __name__ == "__main__":
@@ -15,7 +15,7 @@ BANNER = """
15
15
 
16
16
  [bold white] Know if a dependency upgrade will break your code before you run it.[/]
17
17
 
18
- [dim]Version[/] [green]0.3.0[/]
18
+ [dim]Version[/] [green]0.3.2[/]
19
19
  [dim]PyPI[/] [blue]https://pypi.org/project/pyupcheck[/]
20
20
  [dim]GitHub[/] [blue]https://github.com/Astronomox/pyupcheck-Astronomox[/]
21
21
  [dim]Author[/] [cyan]AgbaDev (Astronomox)[/]
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "pyupcheck"
7
- version = "0.3.0"
7
+ version = "0.3.2"
8
8
  description = "Check if upgrading a Python dependency will break your code"
9
9
  readme = "README.md"
10
10
  license = "MIT"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pyupcheck
3
- Version: 0.3.0
3
+ Version: 0.3.2
4
4
  Summary: Check if upgrading a Python dependency will break your code
5
5
  Author: AgbaDev
6
6
  License-Expression: MIT
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes