kbasic 0.1.33__tar.gz → 0.1.34__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.3
2
2
  Name: kbasic
3
- Version: 0.1.33
3
+ Version: 0.1.34
4
4
  Summary: Keyan's basic utility functions.
5
5
  Author: Keyan Gootkin
6
6
  Author-email: Keyan Gootkin <keyangootkin@gmail.com>
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "kbasic"
3
- version = "0.1.33"
3
+ version = "0.1.34"
4
4
  description = "Keyan's basic utility functions."
5
5
  readme = "README.md"
6
6
  authors = [
@@ -3,8 +3,11 @@
3
3
  # !==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==
4
4
  #pysim imports
5
5
  from kbasic.user_input import yesno
6
+ from kbasic.typing import Array, Number
6
7
  #nonpysim imports
7
- from typing import Self, Optional
8
+ from time import time
9
+ from datetime import datetime
10
+ from typing import Self, Optional, Callable
8
11
  from numpy import ndarray
9
12
  from glob import glob
10
13
  from shutil import copy, move, copytree, rmtree
@@ -49,7 +52,10 @@ def could_be_path(path: str) -> bool:
49
52
  bool: True if the first two members of the path are valid else False.
50
53
  """
51
54
  return isdir('/'.join(path.split('/')[:2]))
52
-
55
+ def default_log_formater(msg: str) -> str:
56
+ return f"{str(datetime.now())}: {msg}"
57
+ def delta_log_formater(msg: str, start_time: Number) -> str:
58
+ return f"Δt: {(time()-start_time)*1e6:.1f} μs | {msg}"
53
59
  # !==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==
54
60
  # >-|===|> Classes <|===|-<
55
61
  # !==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==
@@ -115,6 +121,14 @@ class File:
115
121
  with open(self.path, 'w+') as file:
116
122
  if not file.writable: raise PermissionError(f"attempted to save unwritable file: {self.path}")
117
123
  file.writelines("\n".join(self.lines))
124
+ class Log(File):
125
+ def __init__(self, path: str | Self, verbose: bool = False, fmt: Callable[str] = default_log_formater):
126
+ File.__init__(self, path, verbose=verbose)
127
+ self.fmt = fmt
128
+ def __call__(self, msg: Array[str]|str, *args, **kwds):
129
+ match msg:
130
+ case str(): self.lines.append(self.fmt(msg, *args, **kwds))
131
+ case _ if type(msg) in Array.types: self.lines += [self.fmt(m, *args, **kwds) for m in msg]
118
132
  class TOML(File):
119
133
  def __init__(self, path: str, verbose: bool = False):
120
134
  File.__init__(self, path, verbose=verbose)
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