kbasic 0.1.33__tar.gz → 0.1.35__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.35
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.35"
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
  # !==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==!==
@@ -77,6 +83,7 @@ class File:
77
83
  self.parent = Folder(parentpath)
78
84
  self.grandparent = self.parent.parent
79
85
  self.greatgrandparent = self.parent.parent.parent
86
+ self.lines = []
80
87
  def __repr__(self) -> str: return self.path
81
88
  def __str__(self) -> str: return "\n".join(self.lines)
82
89
  def __add__(self, other):
@@ -115,6 +122,17 @@ class File:
115
122
  with open(self.path, 'w+') as file:
116
123
  if not file.writable: raise PermissionError(f"attempted to save unwritable file: {self.path}")
117
124
  file.writelines("\n".join(self.lines))
125
+ class Log(File):
126
+ def __init__(self, path: str | Self, verbose: bool = False, fmt: Callable[str] = default_log_formater):
127
+ File.__init__(self, path, verbose=verbose)
128
+ self.fmt = fmt
129
+ def __call__(self, msg: Array[str]|str, *args, **kwds):
130
+ match msg:
131
+ case str(): output = [self.fmt(msg, *args, **kwds)]
132
+ case _ if type(msg) in Array.types: output = [self.fmt(m, *args, **kwds) for m in msg]
133
+ if self.verbose: print(output)
134
+ self.lines += output
135
+ self.save(interactive=False)
118
136
  class TOML(File):
119
137
  def __init__(self, path: str, verbose: bool = False):
120
138
  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