dycw-utilities 0.175.16__py3-none-any.whl → 0.175.18__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.16
3
+ Version: 0.175.18
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=T7O3-BYhuabAFjqxaQs9o5WOToPVSLS3TN_UrDKm1-o,61
1
+ utilities/__init__.py,sha256=psCN55v4h2RM9fNitaqX4CE9cRd60bDV0qAa6_nnbEw,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,8 +80,8 @@ 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=nFPIXVzXomI_Oby8PYF9HNWrsWtcSsCtgFnj_22QYlI,43753
84
- utilities/tempfile.py,sha256=QyvIdfV4r4YZ0NeNYsg0tCijThLKa7Z32u5Kxy6ZsGo,3619
83
+ utilities/subprocess.py,sha256=ySVxt8V5WcEsrsy6cdqiK4kb15wGfkQxpxePJM_NCe0,43843
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
87
87
  utilities/threading.py,sha256=GvBOp4CyhHfN90wGXZuA2VKe9fGzMaEa7oCl4f3nnPU,1009
@@ -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.16.dist-info/WHEEL,sha256=RRVLqVugUmFOqBedBFAmA4bsgFcROUBiSUKlERi0Hcg,79
101
- dycw_utilities-0.175.16.dist-info/entry_points.txt,sha256=cOGtKeJI0KXLSV7MJ8Dhc2G8jPgDcBDm53MVNJU4ycI,136
102
- dycw_utilities-0.175.16.dist-info/METADATA,sha256=I6NeFafea7kKkUKz82clljp9LupC0JkQ0AgxoPvke34,1443
103
- dycw_utilities-0.175.16.dist-info/RECORD,,
100
+ dycw_utilities-0.175.18.dist-info/WHEEL,sha256=RRVLqVugUmFOqBedBFAmA4bsgFcROUBiSUKlERi0Hcg,79
101
+ dycw_utilities-0.175.18.dist-info/entry_points.txt,sha256=cOGtKeJI0KXLSV7MJ8Dhc2G8jPgDcBDm53MVNJU4ycI,136
102
+ dycw_utilities-0.175.18.dist-info/METADATA,sha256=NfSdn67Xz5devAMMKWOQknDOuGRphL-0POujF8Vv8FM,1443
103
+ dycw_utilities-0.175.18.dist-info/RECORD,,
utilities/__init__.py CHANGED
@@ -1,3 +1,3 @@
1
1
  from __future__ import annotations
2
2
 
3
- __version__ = "0.175.16"
3
+ __version__ = "0.175.18"
utilities/subprocess.py CHANGED
@@ -632,6 +632,7 @@ def _rsync_many_prepare(
632
632
  case never:
633
633
  assert_never(never)
634
634
  cmds: list[list[str]] = [
635
+ maybe_sudo_cmd(*rm_cmd(dest), sudo=sudo),
635
636
  maybe_sudo_cmd(*mkdir_cmd(dest, parent=True), sudo=sudo),
636
637
  maybe_sudo_cmd(*cp_cmd(temp_dest / name, dest), sudo=sudo),
637
638
  ]
@@ -1260,6 +1261,7 @@ def tee(
1260
1261
  path: PathLike, text: str, /, *, sudo: bool = False, append: bool = False
1261
1262
  ) -> None:
1262
1263
  """Use 'tee' to duplicate standard input."""
1264
+ mkdir(path, sudo=sudo, parent=True)
1263
1265
  if sudo: # pragma: no cover
1264
1266
  run(*sudo_cmd(*tee_cmd(path, append=append)), input=text)
1265
1267
  else:
utilities/tempfile.py CHANGED
@@ -73,23 +73,44 @@ class _TemporaryDirectoryNoResourceWarning(tempfile.TemporaryDirectory):
73
73
  @contextmanager
74
74
  def TemporaryFile( # noqa: N802
75
75
  *,
76
+ dir: PathLike | None = None, # noqa: A002
76
77
  suffix: str | None = None,
77
78
  prefix: str | None = None,
78
- dir: PathLike | None = None, # noqa: A002
79
79
  ignore_cleanup_errors: bool = False,
80
80
  delete: bool = True,
81
81
  name: str | None = None,
82
82
  text: str | None = None,
83
83
  ) -> Iterator[Path]:
84
84
  """Yield a temporary file."""
85
- with _temporary_file_inner(
86
- suffix=suffix,
87
- prefix=prefix,
88
- dir=dir,
89
- ignore_cleanup_errors=ignore_cleanup_errors,
90
- delete=delete,
91
- name=name,
92
- ) as temp:
85
+ if dir is None:
86
+ with (
87
+ TemporaryDirectory(
88
+ suffix=suffix,
89
+ prefix=prefix,
90
+ dir=dir,
91
+ ignore_cleanup_errors=ignore_cleanup_errors,
92
+ delete=delete,
93
+ ) as temp_dir,
94
+ _temporary_file_outer(
95
+ temp_dir, delete=delete, name=name, text=text
96
+ ) as temp,
97
+ ):
98
+ yield temp
99
+ else:
100
+ with _temporary_file_outer(dir, delete=delete, name=name, text=text) as temp:
101
+ yield temp
102
+
103
+
104
+ @contextmanager
105
+ def _temporary_file_outer(
106
+ path: PathLike,
107
+ /,
108
+ *,
109
+ delete: bool = True,
110
+ name: str | None = None,
111
+ text: str | None = None,
112
+ ) -> Iterator[Path]:
113
+ with _temporary_file_inner(path, delete=delete, name=name) as temp:
93
114
  if text is not None:
94
115
  _ = temp.write_text(text)
95
116
  yield temp
@@ -97,29 +118,17 @@ def TemporaryFile( # noqa: N802
97
118
 
98
119
  @contextmanager
99
120
  def _temporary_file_inner(
100
- *,
101
- suffix: str | None = None,
102
- prefix: str | None = None,
103
- dir: PathLike | None = None, # noqa: A002
104
- ignore_cleanup_errors: bool = False,
105
- delete: bool = True,
106
- name: str | None = None,
121
+ path: PathLike, /, *, delete: bool = True, name: str | None = None
107
122
  ) -> Iterator[Path]:
108
- with TemporaryDirectory(
109
- suffix=suffix,
110
- prefix=prefix,
111
- dir=dir,
112
- ignore_cleanup_errors=ignore_cleanup_errors,
113
- delete=delete,
114
- ) as temp_dir:
115
- temp_file = _NamedTemporaryFile( # noqa: SIM115
116
- dir=temp_dir, delete=delete, delete_on_close=False
117
- )
118
- if name is None:
119
- yield temp_dir / temp_file.name
120
- else:
121
- _ = move(temp_dir / temp_file.name, temp_dir / name)
122
- yield temp_dir / name
123
+ path = Path(path)
124
+ temp = _NamedTemporaryFile( # noqa: SIM115
125
+ dir=path, delete=delete, delete_on_close=False
126
+ )
127
+ if name is None:
128
+ yield path / temp.name
129
+ else:
130
+ _ = move(path / temp.name, path / name)
131
+ yield path / name
123
132
 
124
133
 
125
134
  ##