adiumentum 0.1.0__py3-none-any.whl → 0.1.1__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.
adiumentum/__init__.py CHANGED
@@ -3,9 +3,9 @@ from .comparison import equal_within, nearly_equal
3
3
  from .exceptions import CustomValidationError
4
4
  from .file_modification_time import (
5
5
  first_newer,
6
- get_time_created,
7
- get_time_modified,
6
+ time_created,
8
7
  time_created_readable,
8
+ time_modified,
9
9
  time_modified_readable,
10
10
  )
11
11
  from .frozendict import FrozenDefaultDict
@@ -50,7 +50,7 @@ from .string import (
50
50
  indent_lines,
51
51
  parse_sequence,
52
52
  )
53
- from .timestamping import insert_timestamp
53
+ from .timestamping import insert_timestamp, make_timestamp
54
54
  from .typing_utils import (
55
55
  areinstances,
56
56
  call_fallback_if_none,
@@ -80,8 +80,6 @@ __all__ = [
80
80
  "first_newer",
81
81
  "flexsplit",
82
82
  "fold_dictionaries",
83
- "get_time_created",
84
- "get_time_modified",
85
83
  "helper",
86
84
  "identity",
87
85
  "ihash",
@@ -92,6 +90,7 @@ __all__ = [
92
90
  "list_full",
93
91
  "lmap",
94
92
  "log_perf",
93
+ "make_timestamp",
95
94
  "mutates",
96
95
  "mutates_and_returns_instance",
97
96
  "mutates_instance",
@@ -105,7 +104,9 @@ __all__ = [
105
104
  "smap",
106
105
  "step_data",
107
106
  "step_transition",
107
+ "time_created",
108
108
  "time_created_readable",
109
+ "time_modified",
109
110
  "time_modified_readable",
110
111
  "tmap",
111
112
  "validator",
@@ -1,24 +1,32 @@
1
1
  import os
2
- import time
2
+ from datetime import datetime
3
3
  from pathlib import Path
4
4
 
5
5
 
6
- def get_time_created(path: Path | str) -> float:
7
- return os.path.getctime(path)
6
+ def time_created(path: Path | str) -> float:
7
+ return Path(path).stat().st_ctime
8
8
 
9
9
 
10
- def time_created_readable(path: Path | str) -> str:
11
- time_created: time.struct_time = time.strptime(time.ctime(get_time_created(path)))
12
- return time.strftime("%Y-%m-%d %H:%M:%S", time_created)
10
+ def format_time(raw_time: float, places: int = 3) -> str:
11
+ dt = datetime.fromtimestamp(raw_time)
12
+ if places > 0:
13
+ idx: int | None = min(0, int(places) - 6) or None
14
+ return dt.strftime("%Y-%m-%d_%H:%M:%S.%f")[:idx]
15
+ return dt.strftime("%Y-%m-%d_%H:%M:%S")
13
16
 
14
17
 
15
- def get_time_modified(path: Path | str) -> float:
16
- return os.path.getmtime(path)
18
+ def time_created_readable(path: Path | str, places: int = 3) -> str:
19
+ # time_created: time.struct_time = time.strptime(time.ctime(time_created(path)))
20
+ return format_time(time_created(path), places=places)
17
21
 
18
22
 
19
- def time_modified_readable(path: Path | str) -> str:
20
- time_modified: time.struct_time = time.strptime(time.ctime(get_time_modified(path)))
21
- return time.strftime("%Y-%m-%d %H:%M:%S", time_modified)
23
+ def time_modified(path: Path | str) -> float:
24
+ return Path(path).stat().st_mtime
25
+
26
+
27
+ def time_modified_readable(path: Path | str, places: int = 3) -> str:
28
+ # time_modified: time.struct_time = time.strptime(time.ctime(time_modified(path)))
29
+ return format_time(time_modified(path), places=places)
22
30
 
23
31
 
24
32
  def first_newer(file1: str | Path, file2: str | Path | tuple[Path, ...] | tuple[str, ...]) -> bool:
adiumentum/frozendict.py CHANGED
@@ -1,12 +1,12 @@
1
1
  from collections import defaultdict
2
2
  from collections.abc import Callable
3
- from typing import Generic, TypeVar, cast
3
+ from typing import TypeVar, cast
4
4
 
5
5
  T = TypeVar("T")
6
6
  K = TypeVar("K")
7
7
 
8
8
 
9
- class FrozenDefaultDict(defaultdict[K, T], Generic[K, T]):
9
+ class FrozenDefaultDict[K, T](defaultdict[K, T]):
10
10
  def __init__(self, default_factory: Callable[[], T], dictionary: dict[K, T]):
11
11
  super().__init__(default_factory, dictionary)
12
12
 
adiumentum/functional.py CHANGED
@@ -33,11 +33,11 @@ def dmap(callable_: Callable[[TPre], TPost], dictionary: dict[TPre, TPre]) -> di
33
33
  return {callable_(k): callable_(v) for k, v in dictionary.items()}
34
34
 
35
35
 
36
- def identity(x: T) -> T:
36
+ def identity[T](x: T) -> T:
37
37
  return x
38
38
 
39
39
 
40
- def fold_dictionaries(dicts: Iterable[dict[K, T]]) -> dict[K, T]:
40
+ def fold_dictionaries[K, T](dicts: Iterable[dict[K, T]]) -> dict[K, T]:
41
41
  def _or(dict1: dict[K, T], dict2: dict[K, T]) -> dict[K, T]:
42
42
  return dict1 | dict2
43
43
 
@@ -2,11 +2,19 @@ from datetime import datetime
2
2
  from pathlib import Path
3
3
 
4
4
 
5
+ def make_timestamp(places: int = 3) -> str:
6
+ dt = datetime.now()
7
+ if places > 0:
8
+ idx: int | None = min(0, int(places) - 6) or None
9
+ return dt.strftime("%Y-%m-%d_%H:%M:%S.%f")[:idx]
10
+ return dt.strftime("%Y-%m-%d_%H:%M:%S")
11
+
12
+
5
13
  def insert_timestamp(p: Path | str) -> Path:
6
14
  new_path = str(p)
7
15
 
8
16
  if "." in new_path:
9
17
  base, suffix = new_path.rsplit(".", 1)
10
- return Path(f"{base}__{datetime.now():%Y-%m-%d_%H:%M:%S}.{suffix}")
18
+ return Path(f"{base}__{make_timestamp()}.{suffix}")
11
19
 
12
- return Path(f"{new_path}__{datetime.now():%Y-%m-%d_%H:%M:%S}")
20
+ return Path(f"{new_path}__{make_timestamp()}")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: adiumentum
3
- Version: 0.1.0
3
+ Version: 0.1.1
4
4
  Summary:
5
5
  Author: Isaac Riley
6
6
  Author-email: Isaac Riley <yelircaasi@proton.me>
@@ -1,19 +1,19 @@
1
- adiumentum/__init__.py,sha256=5bd4edf50fe42ca697d5de8a1188f6b78c346663b91ad2b23cb350f81e1e5f20,2180
1
+ adiumentum/__init__.py,sha256=29e81d7caff8f52f2ad0c0017a8f4384da3846d882729d52a2b464b7f450f40c,2202
2
2
  adiumentum/color.py,sha256=dfdebfecf0cdcf32794103fff75bb2e20dd0ae3514d1d051b1af95e6560f6790,1673
3
3
  adiumentum/comparison.py,sha256=5d3045dbe9364c52c88ae52be29a6739d280f2f1789fa7813ccda0c05f1e1bad,204
4
4
  adiumentum/converters.py,sha256=ae64583d622aa3f9e242fcba479ffb2fa5ec0bcbdf237e6bfc7f980f69914221,48
5
5
  adiumentum/elementary_types.py,sha256=e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855,0
6
6
  adiumentum/exceptions.py,sha256=b6851f704e236f8970998060317b68ead953f20e496b990ccd11eb740e5a01e3,49
7
- adiumentum/file_modification_time.py,sha256=0c36086590f6c2e9790d7ed144fc7f5eac93794f3a7dd9a61647b81ccf37fae9,912
8
- adiumentum/frozendict.py,sha256=1a7c8a1d8b8c1791040a30f2dfcbda820c6076f6b5a9e23719ec6ec13d7b9bee,960
9
- adiumentum/functional.py,sha256=58d3bbbd2085bcd20b97c0aba59af7ac8d4331836b328a843b2f97256d7e9182,1311
7
+ adiumentum/file_modification_time.py,sha256=898b8e8c794954ac9133b2c6959f4d6b142a11e98f01a3aab89efdf097e4d2e3,1236
8
+ adiumentum/frozendict.py,sha256=b575059bd5fdaecb7b5f33f86e87342b31656b5526e0948a060adf1cf93dcb0c,942
9
+ adiumentum/functional.py,sha256=a30cd3312f4dc65f26dd058bae24a86ba158d96ceac11a4f69e5f50f9db70711,1320
10
10
  adiumentum/io.py,sha256=8e00e9cb11d0d3bdd3d56b0ffbaecf0064d00866670a899426a59601a765eee8,929
11
11
  adiumentum/markers.py,sha256=be50f8f45ff885d92429370efc3409962cb03b6c9cbf5d462bf58ab226e26a1f,3198
12
12
  adiumentum/numerical.py,sha256=adad3335e7220c8bf9666ce8c79f01ca4f1a0933316bb8e6fbfc0440293fbbed,704
13
13
  adiumentum/performance_logging.py,sha256=bd0c42337fb5c77921700e5487d366ea103e8cd25825138962bfb44c1b54773b,1471
14
14
  adiumentum/string.py,sha256=bf43e7b023bdcf02b61004d093c93e69a69cf5e274f940c6086ff3c36df2d8f6,4557
15
- adiumentum/timestamping.py,sha256=6e7c6bd0e88c9e2cb68489687eb853476ba5a351db4ee2d6698f34113e3b5017,340
15
+ adiumentum/timestamping.py,sha256=87729ac9dd7dac614fbb7bb1995e321bd860202a4c2f435e044f4af23dd545a0,556
16
16
  adiumentum/typing_utils.py,sha256=36c90fb08da12c88aacce9c6b14d79e9da3db8aec5d52655179f6aaf676250b7,554
17
- adiumentum-0.1.0.dist-info/WHEEL,sha256=ab6157bc637547491fb4567cd7ddf26b04d63382916ca16c29a5c8e94c9c9ef7,79
18
- adiumentum-0.1.0.dist-info/METADATA,sha256=2a7b36433ead718b35bf50a2493f071d3643518e5bec67a964d6f65e16e6efd8,9669
19
- adiumentum-0.1.0.dist-info/RECORD,,
17
+ adiumentum-0.1.1.dist-info/WHEEL,sha256=ab6157bc637547491fb4567cd7ddf26b04d63382916ca16c29a5c8e94c9c9ef7,79
18
+ adiumentum-0.1.1.dist-info/METADATA,sha256=96c693565cff7e788a680de47e9a04c486bd550b31dc30413ab4ce8b149b4fa1,9669
19
+ adiumentum-0.1.1.dist-info/RECORD,,