pyupcheck 0.3.0__tar.gz → 0.3.3__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.3
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.3"
@@ -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
 
@@ -205,6 +218,13 @@ def main(ctx):
205
218
  show_if_first_run(console)
206
219
 
207
220
 
221
+ @main.command("banner")
222
+ def show_banner():
223
+ """Show the pyupcheck banner."""
224
+ from depshift.welcome import BANNER
225
+ console.print(BANNER)
226
+
227
+
208
228
  # ── check ─────────────────────────────────────────────────────────────────────
209
229
 
210
230
  @main.command()
@@ -219,7 +239,7 @@ def main(ctx):
219
239
  @click.option("--exclude", "-e", multiple=True)
220
240
  @click.option("--no-cache", is_flag=True)
221
241
  @click.option("--quiet", "-q", is_flag=True)
222
- @click.option("--since", default=None, metavar="YYYY-MM-DD", help="Only show changes since this date")
242
+ @click.option("--since", default=None, metavar="YYYY-MM-DD", help="Only show changes introduced since this date")
223
243
  def check(package, target_version, directory, github_token, fmt, output, fail_on,
224
244
  min_severity, exclude, no_cache, quiet, since):
225
245
  """Check if upgrading PACKAGE to TARGET_VERSION will break your code."""
@@ -234,7 +254,8 @@ def check(package, target_version, directory, github_token, fmt, output, fail_on
234
254
  cache_mod.disable_cache()
235
255
 
236
256
  with console.status(f"Checking [bold]{package}[/]..."):
237
- result = _run_single_check(package, target_version, directory, github_token, cfg, quiet, since=since)
257
+ result = _run_single_check(package, target_version, directory, github_token,
258
+ cfg, suppress_errors=quiet, since=since)
238
259
 
239
260
  if result is None:
240
261
  sys.exit(2)
@@ -278,6 +299,7 @@ def check_all(directory, github_token, fmt, output, fail_on, min_severity, exclu
278
299
  if not quiet:
279
300
  console.print(f"Found [bold]{len(deps)}[/] dependencies to check\n")
280
301
 
302
+ # collect all results with progress bar, then print
281
303
  results = []
282
304
  with Progress(
283
305
  SpinnerColumn(),
@@ -291,32 +313,35 @@ def check_all(directory, github_token, fmt, output, fail_on, min_severity, exclu
291
313
  task = progress.add_task("Checking dependencies...", total=len(deps))
292
314
  for dep in deps:
293
315
  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)
316
+ r = _run_single_check(dep.name, None, directory, github_token, cfg,
317
+ suppress_errors=True, since=since)
295
318
  if r:
296
319
  results.append(r)
297
- if fmt == "terminal" and not quiet:
298
- progress.stop()
299
- _print_terminal_result(r, quiet)
300
- progress.start()
301
320
  progress.advance(task)
302
321
 
303
- if fmt != "terminal":
322
+ # print results after progress bar closes cleanly
323
+ if fmt == "terminal":
324
+ for r in results:
325
+ _print_terminal_result(r, quiet)
326
+
327
+ total_breaking = sum(r["breaking_count"] for r in results)
328
+ total_deprecated = sum(r["deprecated_count"] for r in results)
329
+ if not quiet:
330
+ console.print()
331
+ if total_breaking:
332
+ console.print(Panel(
333
+ f"[red bold]{total_breaking} breaking[/] | [yellow]{total_deprecated} deprecated[/] across {len(results)} packages",
334
+ border_style="red"))
335
+ elif total_deprecated:
336
+ console.print(Panel(f"[yellow]{total_deprecated} deprecated[/] across {len(results)} packages",
337
+ border_style="yellow"))
338
+ else:
339
+ console.print(Panel(f"[green]All {len(results)} packages safe to upgrade[/]",
340
+ border_style="green"))
341
+ if output:
342
+ _emit(results, "md", output, quiet)
343
+ else:
304
344
  _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
345
 
321
346
  sys.exit(1 if _should_fail(results, cfg.fail_on) else 0)
322
347
 
@@ -358,28 +383,28 @@ def fix(directory, dry_run, no_cache):
358
383
  task = progress.add_task("Scanning...", total=len(deps))
359
384
  for dep in deps:
360
385
  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:
386
+
387
+ if not dep.pinned_version:
365
388
  progress.advance(task)
366
389
  continue
367
390
 
368
- if not installed or not dep.pinned_version:
391
+ pinned = dep.pinned_version
392
+ try:
393
+ latest = get_current_version(dep.name)
394
+ except Exception:
369
395
  progress.advance(task)
370
396
  continue
371
397
 
372
398
  try:
373
- if Version(installed) >= Version(latest):
399
+ if Version(pinned) >= Version(latest):
374
400
  progress.advance(task)
375
401
  continue
376
402
  except InvalidVersion:
377
403
  progress.advance(task)
378
404
  continue
379
405
 
380
- # check if upgrade is safe
381
406
  try:
382
- changes = get_changes_between(dep.name, installed, latest)
407
+ changes = get_changes_between(dep.name, pinned, latest)
383
408
  except Exception:
384
409
  changes = []
385
410
 
@@ -390,17 +415,18 @@ def fix(directory, dry_run, no_cache):
390
415
  if not breaking:
391
416
  updates.append({
392
417
  "name": dep.name,
393
- "old": dep.pinned_version,
418
+ "old": pinned,
394
419
  "new": latest,
395
420
  "source": dep.source,
396
421
  })
397
422
  progress.advance(task)
398
423
 
399
424
  if not updates:
400
- console.print("[green]Nothing to update.[/] All pinned versions are already at latest safe version.")
425
+ console.print("[green]Nothing to update.[/] All pinned deps are at the latest safe version.")
401
426
  return
402
427
 
403
- console.print(f"\n{'[dim]DRY RUN - no files written[/]' if dry_run else ''}")
428
+ if dry_run:
429
+ console.print("[dim]DRY RUN - no files written[/]\n")
404
430
  console.print(f"[bold]{len(updates)}[/] safe update(s):\n")
405
431
  for u in updates:
406
432
  console.print(f" [cyan]{u['name']}[/] {u['old']} -> [green]{u['new']}[/] [dim]({u['source']})[/]")
@@ -408,13 +434,11 @@ def fix(directory, dry_run, no_cache):
408
434
  if dry_run:
409
435
  return
410
436
 
411
- # apply rewrites
412
437
  for req_path in req_files:
413
438
  try:
414
439
  with open(req_path, "r", encoding="utf-8") as f:
415
440
  content = f.read()
416
441
  for u in updates:
417
- import re
418
442
  content = re.sub(
419
443
  rf"(?i)({re.escape(u['name'])}\s*==\s*){re.escape(u['old'])}",
420
444
  rf"\g<1>{u['new']}",
@@ -500,7 +524,7 @@ def ci_setup(ci_type, directory):
500
524
  path = os.path.join(directory, ".pre-commit-config.yaml")
501
525
  if os.path.exists(path):
502
526
  console.print(f"[yellow]Already exists:[/] {os.path.relpath(path)} (not modified)")
503
- console.print(" Add this manually to your existing config:")
527
+ console.print("Add this to your existing config:")
504
528
  console.print(_PRE_COMMIT)
505
529
  else:
506
530
  with open(path, "w", encoding="utf-8") as f:
@@ -535,6 +559,7 @@ def outdated(directory, no_cache):
535
559
  table.add_column("Status")
536
560
 
537
561
  outdated_count = 0
562
+ rows = []
538
563
  with Progress(SpinnerColumn(), TextColumn("{task.description}"), console=console, transient=True) as progress:
539
564
  task = progress.add_task("Checking versions...", total=len(deps))
540
565
  for dep in deps:
@@ -546,7 +571,7 @@ def outdated(directory, no_cache):
546
571
  progress.advance(task)
547
572
  continue
548
573
  if not installed:
549
- table.add_row(dep.name, "-", latest, "[dim]not installed[/]")
574
+ rows.append((dep.name, "-", latest, "[dim]not installed[/]"))
550
575
  progress.advance(task)
551
576
  continue
552
577
  try:
@@ -554,12 +579,14 @@ def outdated(directory, no_cache):
554
579
  outdated_count += 1
555
580
  major_bump = Version(installed).major < Version(latest).major
556
581
  status = "[red]major bump[/]" if major_bump else "[yellow]update available[/]"
557
- table.add_row(dep.name, installed, latest, status)
582
+ rows.append((dep.name, installed, latest, status))
558
583
  except InvalidVersion:
559
584
  pass
560
585
  progress.advance(task)
561
586
 
562
587
  if outdated_count:
588
+ for row in rows:
589
+ table.add_row(*row)
563
590
  console.print(table)
564
591
  console.print(f"\n[bold]{outdated_count}[/] outdated. Run [bold]pyupcheck check-all[/] to see if upgrades are safe.")
565
592
  else:
@@ -587,6 +614,9 @@ def diff(package, from_version, to_version, github_token, no_cache, since):
587
614
  console.print(f"[red]Error:[/] {e}")
588
615
  sys.exit(2)
589
616
 
617
+ if since and changes:
618
+ changes = _filter_by_since(changes, since, package)
619
+
590
620
  if not changes:
591
621
  console.print(f"[green]No breaking/deprecated changes found[/] between {from_version} and {to_version}.")
592
622
  return
@@ -625,7 +655,10 @@ def scan(package, directory, exclude):
625
655
  table.add_column("Code", style="dim")
626
656
 
627
657
  for u in usages:
628
- rel_path = os.path.relpath(u.file)
658
+ try:
659
+ rel_path = os.path.relpath(u.file)
660
+ except ValueError:
661
+ rel_path = u.file
629
662
  table.add_row(rel_path, str(u.line), u.usage_type, u.attr_chain, u.code[:70])
630
663
 
631
664
  console.print(table)
@@ -709,7 +742,7 @@ Remove-Item Env:_PYUPCHECK_COMPLETE
709
742
  """,
710
743
  }
711
744
  print(scripts[shell])
712
- console.print(f"\n[dim]Pipe this to your shell config and restart your terminal.[/]", err=True)
745
+ console.print("\n[dim]Pipe this to your shell config and restart your terminal.[/]")
713
746
 
714
747
 
715
748
  if __name__ == "__main__":
@@ -1,11 +1,11 @@
1
1
  """Show a welcome banner on first run."""
2
2
 
3
- import os
4
3
  from pathlib import Path
4
+ from depshift import __version__
5
5
 
6
6
  MARKER = Path.home() / ".cache" / "pyupcheck" / ".welcomed"
7
7
 
8
- BANNER = """
8
+ BANNER = f"""
9
9
  [bold cyan] ██████╗ ██╗ ██╗██╗ ██╗██████╗ ██████╗██╗ ██╗███████╗ ██████╗██╗ ██╗[/]
10
10
  [bold cyan]██╔══██╗╚██╗ ██╔╝██║ ██║██╔══██╗██╔════╝██║ ██║██╔════╝██╔════╝██║ ██╔╝[/]
11
11
  [bold cyan]██████╔╝ ╚████╔╝ ██║ ██║██████╔╝██║ ███████║█████╗ ██║ █████╔╝ [/]
@@ -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]{__version__}[/]
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.3"
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.3
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