stdl 0.5.2__tar.gz → 0.5.3__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,9 +1,10 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: stdl
3
- Version: 0.5.2
3
+ Version: 0.5.3
4
4
  Summary: Extended Python Standard Library
5
5
  Author-email: Žiga Ivanšek <ziga.ivansek@gmail.com>
6
6
  Project-URL: Repository, https://github.com/zigai/stdl
7
+ Project-URL: Documentation, https://stdl.readthedocs.io
7
8
  Keywords: python utilites,filesystem,string manipulation,logging configuration,list utils,standard library,ANSI colors,terminal output
8
9
  Classifier: Intended Audience :: Developers
9
10
  Classifier: License :: OSI Approved :: MIT License
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "stdl"
3
- version = "0.5.2"
3
+ version = "0.5.3"
4
4
  description = "Extended Python Standard Library"
5
5
  authors = [{ name = "Žiga Ivanšek", email = "ziga.ivansek@gmail.com" }]
6
6
  license = { file = "LICENSE.txt" }
@@ -52,6 +52,7 @@ dev = [
52
52
 
53
53
  [project.urls]
54
54
  Repository = "https://github.com/zigai/stdl"
55
+ Documentation = "https://stdl.readthedocs.io"
55
56
 
56
57
  [tool.black]
57
58
  line-length = 100
@@ -45,7 +45,7 @@ class Timer:
45
45
  Returns:
46
46
  TimerStop: The stop data
47
47
  """
48
- t = time.time()
48
+ t = time.perf_counter()
49
49
  elapsed_total = t - self.start
50
50
  since_last = t - self.stops[-1].at if self.stops else 0
51
51
  if not self.ms:
@@ -78,7 +78,7 @@ class Timer:
78
78
 
79
79
  def reset(self) -> None:
80
80
  """Reset the timer."""
81
- self.start = time.time()
81
+ self.start = time.perf_counter()
82
82
  self.stops: list[TimerStop] = [
83
83
  TimerStop(
84
84
  total=timedelta(seconds=0),
@@ -114,17 +114,18 @@ def datetime_fmt(
114
114
  Returns:
115
115
  str: Formated date and time.
116
116
 
117
- Examples:
118
- --------
119
- >>> fmt_datetime()
120
- '2022-11-22 22:40:04' # current date and time
121
- >>> fmt_datetime(0)
122
- "1970-01-01 00:00:00"
123
- >>> fmt_datetime(0, fmt="dmY", dsep="/")
124
- "01/01/1970 00:00:00"
117
+ Example:
118
+ ```python
119
+ >>> fmt_datetime()
120
+ '2022-11-22 22:40:04' # current date and time
121
+ >>> fmt_datetime(0)
122
+ "1970-01-01 00:00:00"
123
+ >>> fmt_datetime(0, fmt="dmY", dsep="/")
124
+ "01/01/1970 00:00:00"
125
+ ```
125
126
  """
126
127
  if d is None:
127
- d = datetime.fromtimestamp(time.time(), **{"tz": timezone.utc} if utc else {})
128
+ d = datetime.fromtimestamp(time.perf_counter(), **{"tz": timezone.utc} if utc else {})
128
129
 
129
130
  elif isinstance(d, str):
130
131
  d = parse_datetime_str(d)
@@ -161,7 +162,7 @@ def time_fmt(
161
162
  str: Formated time.
162
163
  """
163
164
  if t is None:
164
- tm = datetime.fromtimestamp(time.time(), **{"tz": timezone.utc} if utc else {})
165
+ tm = datetime.fromtimestamp(time.perf_counter(), **{"tz": timezone.utc} if utc else {})
165
166
  elif isinstance(t, datetime):
166
167
  tm = t.time()
167
168
  elif isinstance(t, (int, float)):
@@ -194,19 +195,20 @@ def date_fmt(
194
195
  Returns:
195
196
  str: Formated date.
196
197
 
197
- Examples
198
- --------
199
- >>> fmt_date(date(2022,11,22))
200
- '2022-11-22'
201
- >>> fmt_date(date(2022,11,22), sep="/")
202
- '2022/11/22'
203
- >>> fmt_date(date(2022,11,22), sep="/", fmt="dmY")
204
- '22/11/2022'
205
- >>> fmt_date()
206
- '2022-11-22'
198
+ Example:
199
+ ```python
200
+ >>> fmt_date(date(2022,11,22))
201
+ '2022-11-22'
202
+ >>> fmt_date(date(2022,11,22), sep="/")
203
+ '2022/11/22'
204
+ >>> fmt_date(date(2022,11,22), sep="/", fmt="dmY")
205
+ '22/11/2022'
206
+ >>> fmt_date()
207
+ '2022-11-22'
208
+ ```
207
209
  """
208
210
  if d is None:
209
- d = date.fromtimestamp(time.time())
211
+ d = date.fromtimestamp(time.perf_counter())
210
212
  elif isinstance(d, (float, int)):
211
213
  d = date.fromtimestamp(d)
212
214
  elif isinstance(d, datetime):
@@ -222,12 +224,13 @@ def date_range(start: date, end: date) -> T.Generator[date, None, None]:
222
224
  """
223
225
  Returns a generator for dates between ``start`` and ``end``
224
226
 
225
- Examples
226
- --------
227
- >>> for i in date_range(date(2022,11,19), date(2022,11,22)): print(i)
228
- 2022-11-19
229
- 2022-11-20
230
- 2022-11-21
227
+ Example:
228
+ ```python
229
+ >>> for i in date_range(date(2022,11,19), date(2022,11,22)): print(i)
230
+ 2022-11-19
231
+ 2022-11-20
232
+ 2022-11-21
233
+ ```
231
234
  """
232
235
  for n in range(int((end - start).days)):
233
236
  yield start + timedelta(n)
@@ -873,6 +873,29 @@ def ensure_paths_exist(*args: str | PathLike | Iterable[str | PathLike]) -> None
873
873
  check_path(i)
874
874
 
875
875
 
876
+ def ensure_paths_dont_exist(*args: str | PathLike | Iterable[str | PathLike]) -> None:
877
+ """
878
+ Ensures that the specified paths don't exist.
879
+
880
+ Args:
881
+ *args : one or more strings representing the paths to check. Can also include an Iterable of paths.
882
+
883
+ Raises:
884
+ FileNotFoundError : if one of the provided paths exists.
885
+ """
886
+
887
+ def check_path(path: str | PathLike):
888
+ if os.path.exists(os.fspath(path)):
889
+ raise FileExistsError(f"Path already exists: {path}")
890
+
891
+ for path in args:
892
+ if isinstance(path, (str, bytes, PathLike)):
893
+ check_path(path)
894
+ elif isinstance(path, Iterable):
895
+ for i in path:
896
+ check_path(i)
897
+
898
+
876
899
  class CompletedCommand(subprocess.CompletedProcess):
877
900
  def __init__(
878
901
  self,
@@ -22,13 +22,13 @@ class LoguruFormatter:
22
22
 
23
23
  def format(self, record: dict) -> str:
24
24
  """
25
- Example usage:
26
- ```python
27
- >>> import sys
28
- >>> from loguru import logger
29
- >>> logger.remove()
30
- >>> logger.add(sys.stdout, level="DEBUG", format=loguru_formater)
31
- ```
25
+ Example:
26
+ ```python
27
+ >>> import sys
28
+ >>> from loguru import logger
29
+ >>> logger.remove()
30
+ >>> logger.add(sys.stdout, level="DEBUG", format=loguru_formater)
31
+ ```
32
32
  """
33
33
  extras = ""
34
34
  if len(record["extra"]):
@@ -203,8 +203,10 @@ def terminal_link(
203
203
  Returns a hyperlink that can be used in terminals.
204
204
 
205
205
  NOTE:
206
- Hyperlinks are not supported in all terminals. For more information visit
207
- <https://github.com/Alhadis/OSC8-Adoption/> and
206
+ Hyperlinks are not supported in all terminals.
207
+ For more information visit
208
+ <https://github.com/Alhadis/OSC8-Adoption/>
209
+ and
208
210
  <https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda>
209
211
 
210
212
  Args:
@@ -234,7 +236,7 @@ def remove(s: str, chars: str | set, replace_with: str = "") -> str:
234
236
 
235
237
  Args:
236
238
  s (str): Input string.
237
- chrs (str | set): Characters to remove
239
+ chars (str | set): Characters to remove
238
240
  replace_with (str, optional): If provided, replace the characters with this value.
239
241
 
240
242
  """
@@ -255,7 +257,7 @@ def keep(s: str, chars: str | set, replace_with: str = "") -> str:
255
257
 
256
258
  Args:
257
259
  s (str): Input string
258
- chrs (str | set): Characters to keep
260
+ chars (str | set): Characters to keep
259
261
  replace_with (str, optional): If provided, replace other characters with this value.
260
262
 
261
263
  """
@@ -1,9 +1,10 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: stdl
3
- Version: 0.5.2
3
+ Version: 0.5.3
4
4
  Summary: Extended Python Standard Library
5
5
  Author-email: Žiga Ivanšek <ziga.ivansek@gmail.com>
6
6
  Project-URL: Repository, https://github.com/zigai/stdl
7
+ Project-URL: Documentation, https://stdl.readthedocs.io
7
8
  Keywords: python utilites,filesystem,string manipulation,logging configuration,list utils,standard library,ANSI colors,terminal output
8
9
  Classifier: Intended Audience :: Developers
9
10
  Classifier: License :: OSI Approved :: MIT License
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
File without changes
File without changes
File without changes
File without changes
File without changes