stdl 0.8.0__tar.gz → 0.8.1__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: stdl
3
- Version: 0.8.0
3
+ Version: 0.8.1
4
4
  Summary: Extended Python Standard Library
5
5
  Keywords: stdl,standard-library,python-utilities,filesystem,list-utils,ansi-colors,color-formats,terminal-links,lazy-import,text-processing
6
6
  Author: Žiga Ivanšek
@@ -34,7 +34,7 @@ Requires-Dist: pre-commit>=4.6.0 ; extra == 'dev'
34
34
  Requires-Dist: pyrefly>=1.0.0 ; extra == 'dev'
35
35
  Requires-Dist: codespell>=2.4.2 ; extra == 'dev'
36
36
  Requires-Dist: pydantic>=2 ; extra == 'dev'
37
- Requires-Dist: rattle-lint>=3.0.0 ; extra == 'dev'
37
+ Requires-Dist: rattle-lint>=3.4.0 ; extra == 'dev'
38
38
  Requires-Dist: tqdm>=4.67.1 ; extra == 'full'
39
39
  Requires-Dist: anyio>=4.0.0 ; extra == 'test'
40
40
  Requires-Dist: pytest>=9.0.3 ; extra == 'test'
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "stdl"
3
- version = "0.8.0"
3
+ version = "0.8.1"
4
4
  description = "Extended Python Standard Library"
5
5
  license = "MIT"
6
6
  license-files = ["LICENSE"]
@@ -57,7 +57,7 @@ dev = [
57
57
  "pyrefly>=1.0.0",
58
58
  "codespell>=2.4.2",
59
59
  "pydantic>=2",
60
- "rattle-lint>=3.0.0",
60
+ "rattle-lint>=3.4.0",
61
61
  ]
62
62
  test = [
63
63
  "anyio>=4.0.0",
@@ -296,5 +296,5 @@ dev = [
296
296
  "pre-commit>=4.6.0",
297
297
  "pyrefly>=1.0.0",
298
298
  "codespell>=2.4.2",
299
- "rattle-lint>=3.0.0",
299
+ "rattle-lint>=3.4.0",
300
300
  ]
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "stdl"
3
- version = "0.8.0"
3
+ version = "0.8.1"
4
4
  description = "Extended Python Standard Library"
5
5
  authors = [{ name = "Žiga Ivanšek", email = "ziga.ivansek@gmail.com" }]
6
6
  license = "MIT"
@@ -56,7 +56,7 @@ dev = [
56
56
  "pyrefly>=1.0.0",
57
57
  "codespell>=2.4.2",
58
58
  "pydantic>=2",
59
- "rattle-lint>=3.0.0",
59
+ "rattle-lint>=3.4.0",
60
60
  ]
61
61
 
62
62
  test = ["anyio>=4.0.0", "pytest>=9.0.3", "coverage>=7.14.1", "pydantic>=2"]
@@ -267,4 +267,4 @@ default-groups = ["test"]
267
267
 
268
268
  [dependency-groups]
269
269
  test = ["anyio>=4.0.0", "pytest>=9.0.3", "coverage>=7.14.1", "pydantic>=2"]
270
- dev = [{include-group = "test"}, "ruff==0.16.10", "pre-commit>=4.6.0", "pyrefly>=1.0.0", "codespell>=2.4.2", "rattle-lint>=3.0.0"]
270
+ dev = [{include-group = "test"}, "ruff==0.16.10", "pre-commit>=4.6.0", "pyrefly>=1.0.0", "codespell>=2.4.2", "rattle-lint>=3.4.0"]
@@ -3,16 +3,22 @@ import time
3
3
  import warnings
4
4
  from collections.abc import Generator
5
5
  from dataclasses import dataclass
6
- from datetime import date, datetime, timedelta, timezone, tzinfo
6
+ from datetime import UTC, date, datetime, timedelta, timezone, tzinfo
7
+
8
+
9
+ def parse_datetime_str(timestr: str) -> datetime:
10
+ """Parse a date/time string with `dateutil.parser.parse`."""
11
+ with warnings.catch_warnings():
12
+ warnings.filterwarnings(
13
+ "ignore",
14
+ message=r"datetime\.datetime\.utcfromtimestamp\(\) is deprecated.*",
15
+ category=DeprecationWarning,
16
+ module=r"dateutil\.tz\.tz",
17
+ )
18
+ from dateutil.parser import parse
19
+
20
+ return parse(timestr)
7
21
 
8
- with warnings.catch_warnings():
9
- warnings.filterwarnings(
10
- "ignore",
11
- message=r"datetime\.datetime\.utcfromtimestamp\(\) is deprecated.*",
12
- category=DeprecationWarning,
13
- module=r"dateutil\.tz\.tz",
14
- )
15
- from dateutil.parser import parse as parse_datetime_str
16
22
 
17
23
  local_timezone: tzinfo | None = datetime.now().astimezone().tzinfo
18
24
  DATE_FMT_CHARS = frozenset("Ymd")
@@ -141,12 +147,12 @@ def datetime_fmt(
141
147
  ```
142
148
  """
143
149
  if d is None:
144
- d = datetime.fromtimestamp(time.time(), tz=timezone.utc if utc else None)
150
+ d = datetime.fromtimestamp(time.time(), tz=UTC if utc else None)
145
151
 
146
152
  elif isinstance(d, str):
147
153
  d = parse_datetime_str(d)
148
154
  elif isinstance(d, (float, int)):
149
- d = datetime.fromtimestamp(d, tz=timezone.utc if utc else None)
155
+ d = datetime.fromtimestamp(d, tz=UTC if utc else None)
150
156
  elif isinstance(d, datetime):
151
157
  pass
152
158
  else:
@@ -180,11 +186,11 @@ def time_fmt(
180
186
  str: Formatted time.
181
187
  """
182
188
  if t is None:
183
- tm = datetime.fromtimestamp(time.time(), tz=timezone.utc if utc else None)
189
+ tm = datetime.fromtimestamp(time.time(), tz=UTC if utc else None)
184
190
  elif isinstance(t, datetime):
185
191
  tm = t.time()
186
192
  elif isinstance(t, (int, float)):
187
- tm = datetime.fromtimestamp(t, tz=timezone.utc if utc else None)
193
+ tm = datetime.fromtimestamp(t, tz=UTC if utc else None)
188
194
  else:
189
195
  raise TypeError(type(t))
190
196
  ts = tm.strftime(f"%H{sep}%M{sep}%S")
@@ -227,9 +233,9 @@ def date_fmt(
227
233
  ```
228
234
  """
229
235
  if d is None:
230
- d = datetime.fromtimestamp(time.time(), tz=timezone.utc).astimezone().date()
236
+ d = datetime.fromtimestamp(time.time(), tz=UTC).astimezone().date()
231
237
  elif isinstance(d, (float, int)):
232
- d = datetime.fromtimestamp(d, tz=timezone.utc).astimezone().date()
238
+ d = datetime.fromtimestamp(d, tz=UTC).astimezone().date()
233
239
  elif isinstance(d, datetime):
234
240
  d = d.date()
235
241
  elif isinstance(d, date):
@@ -42,10 +42,6 @@ from typing import (
42
42
  TypeVar,
43
43
  overload,
44
44
  )
45
- from urllib.request import pathname2url
46
-
47
- import toml
48
- import yaml
49
45
 
50
46
  from stdl import st
51
47
 
@@ -819,6 +815,8 @@ def yaml_load(
819
815
  Returns:
820
816
  dict | list[dict]: The YAML data loaded from the file.
821
817
  """
818
+ import yaml
819
+
822
820
  with open(path, encoding=encoding) as f:
823
821
  return yaml.safe_load(f)
824
822
 
@@ -839,6 +837,8 @@ def yaml_dump(data: YamlValue, path: str | PathLike, encoding: str = "utf-8") ->
839
837
  path (Pathlike): path to the output file
840
838
  encoding (str): encoding of the output file. Default: 'utf-8'
841
839
  """
840
+ import yaml
841
+
842
842
  with open(path, "w", encoding=encoding) as f:
843
843
  yaml.safe_dump(data, f)
844
844
 
@@ -849,6 +849,8 @@ async def yaml_dump_async(data: YamlValue, path: str | PathLike, encoding: str =
849
849
 
850
850
 
851
851
  def toml_load(path: str | PathLike, encoding: str = "utf-8") -> dict[str, Any]:
852
+ import toml
853
+
852
854
  with open(path, encoding=encoding) as f:
853
855
  return toml.load(f)
854
856
 
@@ -859,6 +861,8 @@ async def toml_load_async(path: str | PathLike, encoding: str = "utf-8") -> dict
859
861
 
860
862
 
861
863
  def toml_dump(data: dict[str, Any], path: str | PathLike, encoding: str = "utf-8") -> None:
864
+ import toml
865
+
862
866
  with open(path, "w", encoding=encoding) as f:
863
867
  toml.dump(data, f)
864
868
 
@@ -1729,6 +1733,8 @@ class PathBase(PathLike):
1729
1733
  if not self.is_absolute:
1730
1734
  raise ValueError("relative path can't be expressed as a file URI")
1731
1735
 
1736
+ from urllib.request import pathname2url
1737
+
1732
1738
  return "file://" + pathname2url(os.path.abspath(self.path))
1733
1739
 
1734
1740
  def match(self, pattern: str) -> bool:
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes