dycw-utilities 0.175.26__py3-none-any.whl → 0.175.28__py3-none-any.whl

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.3
2
2
  Name: dycw-utilities
3
- Version: 0.175.26
3
+ Version: 0.175.28
4
4
  Summary: Miscellaneous Python utilities
5
5
  Author: Derek Wan
6
6
  Author-email: Derek Wan <d.wan@icloud.com>
@@ -1,4 +1,4 @@
1
- utilities/__init__.py,sha256=HrK7xYXnuNa7NvyOEq-oZ72p1jL1hr7f0vITbrb-rNA,61
1
+ utilities/__init__.py,sha256=k4kaN7LN6ZF6oNv47GuGm1AaLmVrNa8LJBL_8oBnlMY,61
2
2
  utilities/altair.py,sha256=TLfRFbG9HwG7SLXoJ-v0r-t49ZaGgTQZD82cpjVi4vs,9085
3
3
  utilities/asyncio.py,sha256=aJySVxBY0gqsIYnoNmH7-1r8djKuf4vSsU69VCD08t8,16772
4
4
  utilities/atomicwrites.py,sha256=tPo6r-Rypd9u99u66B9z86YBPpnLrlHtwox_8Z7T34Y,5790
@@ -80,7 +80,7 @@ utilities/sqlalchemy.py,sha256=HQYpd7LFxdTF5WYVWYtCJeEBI71EJm7ytvCGyAH9B-U,37163
80
80
  utilities/sqlalchemy_polars.py,sha256=JCGhB37raSR7fqeWV5dTsciRTMVzIdVT9YSqKT0piT0,13370
81
81
  utilities/statsmodels.py,sha256=koyiBHvpMcSiBfh99wFUfSggLNx7cuAw3rwyfAhoKpQ,3410
82
82
  utilities/string.py,sha256=shmBK87zZwzGyixuNuXCiUbqzfeZ9xlrFwz6JTaRvDk,582
83
- utilities/subprocess.py,sha256=uZ2HR9hJOnqhrS-uwfZZuERxO_pSLfHZZbMFfms7lQA,46604
83
+ utilities/subprocess.py,sha256=f-bVgM-8dGYuqmfegp7y9JtU1WP3FX4AaU2munpeD-U,52304
84
84
  utilities/tempfile.py,sha256=a3_M1QyxGZql_VcGkBOQBeWbbkItjgkfIpVyzU1UAic,3843
85
85
  utilities/testbook.py,sha256=j1KmaVbrX9VrbeMgtPh5gk55myAsn3dyRUn7jGbPbRk,1294
86
86
  utilities/text.py,sha256=7SvwcSR2l_5cOrm1samGnR4C-ZI6qyFLHLzSpO1zeHQ,13958
@@ -97,7 +97,7 @@ utilities/warnings.py,sha256=un1LvHv70PU-LLv8RxPVmugTzDJkkGXRMZTE2-fTQHw,1771
97
97
  utilities/whenever.py,sha256=F4ek0-OBWxHYrZdmoZt76N2RnNyKY5KrEHt7rqO4AQE,60183
98
98
  utilities/zipfile.py,sha256=24lQc9ATcJxHXBPc_tBDiJk48pWyRrlxO2fIsFxU0A8,699
99
99
  utilities/zoneinfo.py,sha256=tdIScrTB2-B-LH0ukb1HUXKooLknOfJNwHk10MuMYvA,3619
100
- dycw_utilities-0.175.26.dist-info/WHEEL,sha256=RRVLqVugUmFOqBedBFAmA4bsgFcROUBiSUKlERi0Hcg,79
101
- dycw_utilities-0.175.26.dist-info/entry_points.txt,sha256=cOGtKeJI0KXLSV7MJ8Dhc2G8jPgDcBDm53MVNJU4ycI,136
102
- dycw_utilities-0.175.26.dist-info/METADATA,sha256=Yokzuv-jy8hF_tHUIxoSZTc9_Z17cDJwlorBmc9gSE4,1443
103
- dycw_utilities-0.175.26.dist-info/RECORD,,
100
+ dycw_utilities-0.175.28.dist-info/WHEEL,sha256=RRVLqVugUmFOqBedBFAmA4bsgFcROUBiSUKlERi0Hcg,79
101
+ dycw_utilities-0.175.28.dist-info/entry_points.txt,sha256=cOGtKeJI0KXLSV7MJ8Dhc2G8jPgDcBDm53MVNJU4ycI,136
102
+ dycw_utilities-0.175.28.dist-info/METADATA,sha256=k8PYEVjHbdSwrVP6nAsY8ptu8MEenozvTPprPs3Pgwk,1443
103
+ dycw_utilities-0.175.28.dist-info/RECORD,,
utilities/__init__.py CHANGED
@@ -1,3 +1,3 @@
1
1
  from __future__ import annotations
2
2
 
3
- __version__ = "0.175.26"
3
+ __version__ = "0.175.28"
utilities/subprocess.py CHANGED
@@ -295,6 +295,185 @@ def cp_cmd(src: PathLike, dest: PathLike, /) -> list[str]:
295
295
  ##
296
296
 
297
297
 
298
+ @overload
299
+ def curl(
300
+ url: str,
301
+ /,
302
+ *,
303
+ fail: bool = True,
304
+ location: bool = True,
305
+ output: PathLike | None = None,
306
+ show_error: bool = True,
307
+ silent: bool = True,
308
+ sudo: bool = False,
309
+ print: bool = False,
310
+ print_stdout: bool = False,
311
+ print_stderr: bool = False,
312
+ return_: Literal[True],
313
+ return_stdout: Literal[False] = False,
314
+ return_stderr: Literal[False] = False,
315
+ retry: Retry | None = None,
316
+ retry_skip: Callable[[int, str, str], bool] | None = None,
317
+ logger: LoggerLike | None = None,
318
+ ) -> str: ...
319
+ @overload
320
+ def curl(
321
+ url: str,
322
+ /,
323
+ *,
324
+ fail: bool = True,
325
+ location: bool = True,
326
+ output: PathLike | None = None,
327
+ show_error: bool = True,
328
+ silent: bool = True,
329
+ sudo: bool = False,
330
+ print: bool = False,
331
+ print_stdout: bool = False,
332
+ print_stderr: bool = False,
333
+ return_: Literal[False] = False,
334
+ return_stdout: Literal[True],
335
+ return_stderr: Literal[False] = False,
336
+ retry: Retry | None = None,
337
+ retry_skip: Callable[[int, str, str], bool] | None = None,
338
+ logger: LoggerLike | None = None,
339
+ ) -> str: ...
340
+ @overload
341
+ def curl(
342
+ url: str,
343
+ /,
344
+ *,
345
+ fail: bool = True,
346
+ location: bool = True,
347
+ output: PathLike | None = None,
348
+ show_error: bool = True,
349
+ silent: bool = True,
350
+ sudo: bool = False,
351
+ print: bool = False,
352
+ print_stdout: bool = False,
353
+ print_stderr: bool = False,
354
+ return_: Literal[False] = False,
355
+ return_stdout: Literal[False] = False,
356
+ return_stderr: Literal[True],
357
+ retry: Retry | None = None,
358
+ retry_skip: Callable[[int, str, str], bool] | None = None,
359
+ logger: LoggerLike | None = None,
360
+ ) -> str: ...
361
+ @overload
362
+ def curl(
363
+ url: str,
364
+ /,
365
+ *,
366
+ fail: bool = True,
367
+ location: bool = True,
368
+ output: PathLike | None = None,
369
+ show_error: bool = True,
370
+ silent: bool = True,
371
+ sudo: bool = False,
372
+ print: bool = False,
373
+ print_stdout: bool = False,
374
+ print_stderr: bool = False,
375
+ return_: Literal[False] = False,
376
+ return_stdout: Literal[False] = False,
377
+ return_stderr: Literal[False] = False,
378
+ retry: Retry | None = None,
379
+ retry_skip: Callable[[int, str, str], bool] | None = None,
380
+ logger: LoggerLike | None = None,
381
+ ) -> None: ...
382
+ @overload
383
+ def curl(
384
+ url: str,
385
+ /,
386
+ *,
387
+ fail: bool = True,
388
+ location: bool = True,
389
+ output: PathLike | None = None,
390
+ show_error: bool = True,
391
+ silent: bool = True,
392
+ sudo: bool = False,
393
+ print: bool = False,
394
+ print_stdout: bool = False,
395
+ print_stderr: bool = False,
396
+ return_: bool = False,
397
+ return_stdout: bool = False,
398
+ return_stderr: bool = False,
399
+ retry: Retry | None = None,
400
+ retry_skip: Callable[[int, str, str], bool] | None = None,
401
+ logger: LoggerLike | None = None,
402
+ ) -> str | None: ...
403
+ def curl(
404
+ url: str,
405
+ /,
406
+ *,
407
+ fail: bool = True,
408
+ location: bool = True,
409
+ output: PathLike | None = None,
410
+ show_error: bool = True,
411
+ silent: bool = True,
412
+ sudo: bool = False,
413
+ print: bool = False, # noqa: A002
414
+ print_stdout: bool = False,
415
+ print_stderr: bool = False,
416
+ return_: bool = False,
417
+ return_stdout: bool = False,
418
+ return_stderr: bool = False,
419
+ retry: Retry | None = None,
420
+ retry_skip: Callable[[int, str, str], bool] | None = None,
421
+ logger: LoggerLike | None = None,
422
+ ) -> str | None:
423
+ """Transfer a URL."""
424
+ args = maybe_sudo_cmd(
425
+ *curl_cmd( # skipif-ci
426
+ url,
427
+ fail=fail,
428
+ location=location,
429
+ output=output,
430
+ show_error=show_error,
431
+ silent=silent,
432
+ ),
433
+ sudo=sudo,
434
+ )
435
+ return run( # skipif-ci
436
+ *args,
437
+ print=print,
438
+ print_stdout=print_stdout,
439
+ print_stderr=print_stderr,
440
+ return_=return_,
441
+ return_stdout=return_stdout,
442
+ return_stderr=return_stderr,
443
+ retry=retry,
444
+ retry_skip=retry_skip,
445
+ logger=logger,
446
+ )
447
+
448
+
449
+ def curl_cmd(
450
+ url: str,
451
+ /,
452
+ *,
453
+ fail: bool = True,
454
+ location: bool = True,
455
+ output: PathLike | None = None,
456
+ show_error: bool = True,
457
+ silent: bool = True,
458
+ ) -> list[str]:
459
+ """Command to use 'curl' to transfer a URL."""
460
+ args: list[str] = ["curl"]
461
+ if fail:
462
+ args.append("--fail")
463
+ if location:
464
+ args.append("--location")
465
+ if output is not None:
466
+ args.extend(["--create-dirs", "--output", str(output)])
467
+ if show_error:
468
+ args.append("--show-error")
469
+ if silent:
470
+ args.append("--silent")
471
+ return [*args, url]
472
+
473
+
474
+ ##
475
+
476
+
298
477
  def echo_cmd(text: str, /) -> list[str]:
299
478
  """Command to use 'echo' to write arguments to the standard output."""
300
479
  return ["echo", text]
@@ -363,6 +542,53 @@ def git_clone_cmd(url: str, path: PathLike, /) -> list[str]:
363
542
  ##
364
543
 
365
544
 
545
+ def install(
546
+ path: PathLike,
547
+ /,
548
+ *,
549
+ directory: bool = False,
550
+ mode: PermissionsLike | None = None,
551
+ owner: str | int | None = None,
552
+ group: str | int | None = None,
553
+ sudo: bool = False,
554
+ ) -> None:
555
+ """Install a binary."""
556
+ args = maybe_sudo_cmd(
557
+ *install_cmd(path, directory=directory, mode=mode, owner=owner, group=group),
558
+ sudo=sudo,
559
+ )
560
+ run(*args)
561
+
562
+
563
+ def install_cmd(
564
+ path: PathLike,
565
+ /,
566
+ *,
567
+ directory: bool = False,
568
+ mode: PermissionsLike | None = None,
569
+ owner: str | int | None = None,
570
+ group: str | int | None = None,
571
+ ) -> list[str]:
572
+ """Command to use 'install' to install a binary."""
573
+ args: list[str] = ["install"]
574
+ if directory:
575
+ args.append("-d")
576
+ if mode is not None:
577
+ args.extend(["-m", str(ensure_perms(mode))])
578
+ if owner is not None:
579
+ args.extend(["-o", str(owner)])
580
+ if group is not None:
581
+ args.extend(["-g", str(group)])
582
+ if directory:
583
+ args.append(str(path))
584
+ else:
585
+ args.extend(["/dev/null", str(path)])
586
+ return args
587
+
588
+
589
+ ##
590
+
591
+
366
592
  def maybe_parent(path: PathLike, /, *, parent: bool = False) -> Path:
367
593
  """Get the parent of a path, if required."""
368
594
  path = Path(path)
@@ -1642,6 +1868,8 @@ __all__ = [
1642
1868
  "copy_text",
1643
1869
  "cp",
1644
1870
  "cp_cmd",
1871
+ "curl",
1872
+ "curl_cmd",
1645
1873
  "echo_cmd",
1646
1874
  "env_cmds",
1647
1875
  "expand_path",
@@ -1650,6 +1878,8 @@ __all__ = [
1650
1878
  "git_checkout_cmd",
1651
1879
  "git_clone",
1652
1880
  "git_clone_cmd",
1881
+ "install",
1882
+ "install_cmd",
1653
1883
  "maybe_parent",
1654
1884
  "maybe_sudo_cmd",
1655
1885
  "mkdir",