dycw-utilities 0.175.34__py3-none-any.whl → 0.175.35__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.34
3
+ Version: 0.175.35
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=mL4P-Ukiy8UcfSj8x_ckAI3_hnXE8m5ck5YhALwBabM,61
1
+ utilities/__init__.py,sha256=AelOFthRG2sB_q5f7Mg4FXkK3h46AYrjFZpEQAj-MeU,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=mdEnkFjCbMz9VVwjw3AfXnWDi5AIfz3M_Vy85IjCNZY,53523
83
+ utilities/subprocess.py,sha256=4IAEpK0z5OUQ3hsCJFZgkF2TW-osdrBJODaEhMAuQ_Q,53751
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.34.dist-info/WHEEL,sha256=RRVLqVugUmFOqBedBFAmA4bsgFcROUBiSUKlERi0Hcg,79
101
- dycw_utilities-0.175.34.dist-info/entry_points.txt,sha256=cOGtKeJI0KXLSV7MJ8Dhc2G8jPgDcBDm53MVNJU4ycI,136
102
- dycw_utilities-0.175.34.dist-info/METADATA,sha256=-obfKB86Pl-Bbb8dtSMilaGoUNqGNACDimr7OecLJGc,1443
103
- dycw_utilities-0.175.34.dist-info/RECORD,,
100
+ dycw_utilities-0.175.35.dist-info/WHEEL,sha256=RRVLqVugUmFOqBedBFAmA4bsgFcROUBiSUKlERi0Hcg,79
101
+ dycw_utilities-0.175.35.dist-info/entry_points.txt,sha256=cOGtKeJI0KXLSV7MJ8Dhc2G8jPgDcBDm53MVNJU4ycI,136
102
+ dycw_utilities-0.175.35.dist-info/METADATA,sha256=0AriytahaylEXcflepQ0HIJCKwcFjx-pv_EFtSbyXDQ,1443
103
+ dycw_utilities-0.175.35.dist-info/RECORD,,
utilities/__init__.py CHANGED
@@ -1,3 +1,3 @@
1
1
  from __future__ import annotations
2
2
 
3
- __version__ = "0.175.34"
3
+ __version__ = "0.175.35"
utilities/subprocess.py CHANGED
@@ -192,36 +192,46 @@ def chown(
192
192
  /,
193
193
  *,
194
194
  sudo: bool = False,
195
+ recursive: bool = False,
195
196
  user: str | int | None = None,
196
197
  group: str | int | None = None,
197
198
  ) -> None:
198
199
  """Change file owner and/or group."""
199
200
  if sudo: # pragma: no cover
200
- match user, group:
201
- case None, None:
202
- ...
203
- case str() | int() | None, str() | int() | None:
204
- run(*sudo_cmd(*chown_cmd(path, user=user, group=group)))
205
- case never:
206
- assert_never(never)
201
+ if (user is not None) or (group is not None):
202
+ args = sudo_cmd(
203
+ *chown_cmd(path, recursive=recursive, user=user, group=group)
204
+ )
205
+ run(*args)
207
206
  else:
208
- match user, group:
209
- case None, None:
210
- ...
211
- case str() | int(), None:
212
- shutil.chown(path, user, group)
213
- case None, str() | int():
214
- shutil.chown(path, user, group)
215
- case str() | int(), str() | int():
216
- shutil.chown(path, user, group)
217
- case never:
218
- assert_never(never)
207
+ path = Path(path)
208
+ paths = list(path.rglob("**/*")) if recursive else [path]
209
+ for p in paths:
210
+ match user, group:
211
+ case None, None:
212
+ ...
213
+ case str() | int(), None:
214
+ shutil.chown(p, user, group)
215
+ case None, str() | int():
216
+ shutil.chown(p, user, group)
217
+ case str() | int(), str() | int():
218
+ shutil.chown(p, user, group)
219
+ case never:
220
+ assert_never(never)
219
221
 
220
222
 
221
223
  def chown_cmd(
222
- path: PathLike, /, *, user: str | int | None = None, group: str | int | None = None
224
+ path: PathLike,
225
+ /,
226
+ *,
227
+ recursive: bool = False,
228
+ user: str | int | None = None,
229
+ group: str | int | None = None,
223
230
  ) -> list[str]:
224
231
  """Command to use 'chown' to change file owner and/or group."""
232
+ args: list[str] = ["chown"]
233
+ if recursive:
234
+ args.append("-R")
225
235
  match user, group:
226
236
  case None, None:
227
237
  raise ChownCmdError
@@ -233,7 +243,7 @@ def chown_cmd(
233
243
  ownership = f"{user}:{group}"
234
244
  case never:
235
245
  assert_never(never)
236
- return ["chown", ownership, str(path)]
246
+ return [*args, ownership, str(path)]
237
247
 
238
248
 
239
249
  @dataclass(kw_only=True, slots=True)