stdl 0.5.1__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.
- {stdl-0.5.1/stdl.egg-info → stdl-0.5.3}/PKG-INFO +30 -6
- stdl-0.5.3/README.md +38 -0
- {stdl-0.5.1 → stdl-0.5.3}/pyproject.toml +20 -3
- stdl-0.5.3/stdl/__init__.py +1 -0
- {stdl-0.5.1 → stdl-0.5.3}/stdl/decorators.py +6 -3
- {stdl-0.5.1 → stdl-0.5.3}/stdl/dt.py +48 -49
- {stdl-0.5.1 → stdl-0.5.3}/stdl/fs.py +226 -162
- {stdl-0.5.1 → stdl-0.5.3}/stdl/log.py +9 -7
- {stdl-0.5.1 → stdl-0.5.3}/stdl/lst.py +8 -18
- {stdl-0.5.1 → stdl-0.5.3}/stdl/net.py +3 -3
- {stdl-0.5.1 → stdl-0.5.3}/stdl/st.py +12 -9
- {stdl-0.5.1 → stdl-0.5.3/stdl.egg-info}/PKG-INFO +30 -6
- {stdl-0.5.1 → stdl-0.5.3}/stdl.egg-info/SOURCES.txt +0 -1
- stdl-0.5.3/stdl.egg-info/requires.txt +16 -0
- {stdl-0.5.1 → stdl-0.5.3}/tests/test_fs.py +32 -0
- stdl-0.5.3/tests/test_st.py +128 -0
- stdl-0.5.1/README.md +0 -20
- stdl-0.5.1/stdl/__init__.py +0 -1
- stdl-0.5.1/stdl/dataclass.py +0 -45
- stdl-0.5.1/stdl.egg-info/requires.txt +0 -11
- stdl-0.5.1/tests/test_st.py +0 -41
- {stdl-0.5.1 → stdl-0.5.3}/LICENSE +0 -0
- {stdl-0.5.1 → stdl-0.5.3}/setup.cfg +0 -0
- {stdl-0.5.1 → stdl-0.5.3}/setup.py +0 -0
- {stdl-0.5.1 → stdl-0.5.3}/stdl.egg-info/dependency_links.txt +0 -0
- {stdl-0.5.1 → stdl-0.5.3}/stdl.egg-info/top_level.txt +0 -0
- {stdl-0.5.1 → stdl-0.5.3}/tests/test_decorators.py +0 -0
- {stdl-0.5.1 → stdl-0.5.3}/tests/test_dt.py +0 -0
- {stdl-0.5.1 → stdl-0.5.3}/tests/test_lst.py +0 -0
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: stdl
|
|
3
|
-
Version: 0.5.
|
|
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
|
-
|
|
7
|
+
Project-URL: Documentation, https://stdl.readthedocs.io
|
|
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
|
|
10
11
|
Classifier: Operating System :: OS Independent
|
|
@@ -19,23 +20,46 @@ Description-Content-Type: text/markdown
|
|
|
19
20
|
License-File: LICENSE
|
|
20
21
|
Requires-Dist: PyYAML>=6.0
|
|
21
22
|
Requires-Dist: tqdm
|
|
22
|
-
Requires-Dist: python-dateutil
|
|
23
|
+
Requires-Dist: python-dateutil>=2.8.2
|
|
24
|
+
Requires-Dist: toml>=0.10.2
|
|
23
25
|
Provides-Extra: test
|
|
24
26
|
Requires-Dist: pytest; extra == "test"
|
|
25
27
|
Provides-Extra: dev
|
|
26
28
|
Requires-Dist: black; extra == "dev"
|
|
27
29
|
Requires-Dist: pytest; extra == "dev"
|
|
28
30
|
Requires-Dist: ruff; extra == "dev"
|
|
31
|
+
Requires-Dist: mkdocs; extra == "dev"
|
|
32
|
+
Requires-Dist: mkdocs-material; extra == "dev"
|
|
33
|
+
Requires-Dist: mkdocs-autorefs; extra == "dev"
|
|
34
|
+
Requires-Dist: mkdocstrings[python]; extra == "dev"
|
|
29
35
|
|
|
30
36
|
# stdl
|
|
31
37
|
[](https://github.com/zigai/stdl/actions/workflows/tests.yml)
|
|
38
|
+
[](https://stdl.readthedocs.io/en/latest/?badge=latest)
|
|
32
39
|
[](https://badge.fury.io/py/stdl)
|
|
33
40
|

|
|
34
41
|
[](https://pepy.tech/project/stdl)
|
|
35
42
|
[](https://github.com/zigai/stdl/blob/master/LICENSE)
|
|
36
43
|
|
|
37
|
-
|
|
38
|
-
|
|
44
|
+
`stdl` is a collection of Python utilities that complement the standard library. It provides common functions and tools that developers frequently need, with minimal external dependencies.
|
|
45
|
+
|
|
46
|
+
## Features
|
|
47
|
+
- File and directory operations
|
|
48
|
+
- String manipulation
|
|
49
|
+
- ANSI color support for terminal output
|
|
50
|
+
- Date and time formatting
|
|
51
|
+
- List processing
|
|
52
|
+
- Function decorators
|
|
53
|
+
- Logging configuration for `logging` and `loguru`
|
|
54
|
+
- [See docs](https://stdl.readthedocs.io/en/latest/?badge=latest)
|
|
55
|
+
|
|
56
|
+
## Dependencies
|
|
57
|
+
- PyYAML
|
|
58
|
+
- python-dateutil
|
|
59
|
+
- toml
|
|
60
|
+
- tqdm
|
|
61
|
+
|
|
62
|
+
## Installation
|
|
39
63
|
|
|
40
64
|
#### Using pip
|
|
41
65
|
```
|
|
@@ -45,5 +69,5 @@ pip install stdl
|
|
|
45
69
|
```
|
|
46
70
|
pip install git+https://github.com/zigai/stdl
|
|
47
71
|
```
|
|
48
|
-
|
|
72
|
+
## License
|
|
49
73
|
[MIT License](https://github.com/zigai/stdl/blob/master/LICENSE)
|
stdl-0.5.3/README.md
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# stdl
|
|
2
|
+
[](https://github.com/zigai/stdl/actions/workflows/tests.yml)
|
|
3
|
+
[](https://stdl.readthedocs.io/en/latest/?badge=latest)
|
|
4
|
+
[](https://badge.fury.io/py/stdl)
|
|
5
|
+

|
|
6
|
+
[](https://pepy.tech/project/stdl)
|
|
7
|
+
[](https://github.com/zigai/stdl/blob/master/LICENSE)
|
|
8
|
+
|
|
9
|
+
`stdl` is a collection of Python utilities that complement the standard library. It provides common functions and tools that developers frequently need, with minimal external dependencies.
|
|
10
|
+
|
|
11
|
+
## Features
|
|
12
|
+
- File and directory operations
|
|
13
|
+
- String manipulation
|
|
14
|
+
- ANSI color support for terminal output
|
|
15
|
+
- Date and time formatting
|
|
16
|
+
- List processing
|
|
17
|
+
- Function decorators
|
|
18
|
+
- Logging configuration for `logging` and `loguru`
|
|
19
|
+
- [See docs](https://stdl.readthedocs.io/en/latest/?badge=latest)
|
|
20
|
+
|
|
21
|
+
## Dependencies
|
|
22
|
+
- PyYAML
|
|
23
|
+
- python-dateutil
|
|
24
|
+
- toml
|
|
25
|
+
- tqdm
|
|
26
|
+
|
|
27
|
+
## Installation
|
|
28
|
+
|
|
29
|
+
#### Using pip
|
|
30
|
+
```
|
|
31
|
+
pip install stdl
|
|
32
|
+
```
|
|
33
|
+
#### From source
|
|
34
|
+
```
|
|
35
|
+
pip install git+https://github.com/zigai/stdl
|
|
36
|
+
```
|
|
37
|
+
## License
|
|
38
|
+
[MIT License](https://github.com/zigai/stdl/blob/master/LICENSE)
|
|
@@ -1,12 +1,18 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "stdl"
|
|
3
|
-
version = "0.5.
|
|
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" }
|
|
7
7
|
readme = "README.md"
|
|
8
8
|
requires-python = ">=3.10"
|
|
9
|
-
|
|
9
|
+
|
|
10
|
+
dependencies = [
|
|
11
|
+
"PyYAML>=6.0",
|
|
12
|
+
"tqdm",
|
|
13
|
+
"python-dateutil>=2.8.2",
|
|
14
|
+
"toml>=0.10.2 ",
|
|
15
|
+
]
|
|
10
16
|
|
|
11
17
|
classifiers = [
|
|
12
18
|
"Intended Audience :: Developers",
|
|
@@ -27,15 +33,26 @@ keywords = [
|
|
|
27
33
|
"logging configuration",
|
|
28
34
|
"list utils",
|
|
29
35
|
"standard library",
|
|
36
|
+
"ANSI colors",
|
|
37
|
+
"terminal output",
|
|
30
38
|
]
|
|
31
39
|
|
|
32
40
|
|
|
33
41
|
[project.optional-dependencies]
|
|
34
42
|
test = ["pytest"]
|
|
35
|
-
dev = [
|
|
43
|
+
dev = [
|
|
44
|
+
"black",
|
|
45
|
+
"pytest",
|
|
46
|
+
"ruff",
|
|
47
|
+
"mkdocs",
|
|
48
|
+
"mkdocs-material",
|
|
49
|
+
"mkdocs-autorefs",
|
|
50
|
+
"mkdocstrings[python]",
|
|
51
|
+
]
|
|
36
52
|
|
|
37
53
|
[project.urls]
|
|
38
54
|
Repository = "https://github.com/zigai/stdl"
|
|
55
|
+
Documentation = "https://stdl.readthedocs.io"
|
|
39
56
|
|
|
40
57
|
[tool.black]
|
|
41
58
|
line-length = 100
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from stdl import dt, fs, log, lst, net, st
|
|
@@ -2,13 +2,13 @@ import inspect
|
|
|
2
2
|
import json
|
|
3
3
|
import sys
|
|
4
4
|
import time
|
|
5
|
+
import typing as T
|
|
5
6
|
from functools import wraps
|
|
6
|
-
from typing import Callable
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
def timer(
|
|
10
10
|
r: int | None = 2,
|
|
11
|
-
sink: Callable = sys.stdout.write,
|
|
11
|
+
sink: T.Callable = sys.stdout.write,
|
|
12
12
|
show_args: bool = False,
|
|
13
13
|
serialize: bool = False,
|
|
14
14
|
sep=" | ",
|
|
@@ -24,7 +24,7 @@ def timer(
|
|
|
24
24
|
sep (str, optional): Separator between the function/method name and the arguments. Defaults to " | ".
|
|
25
25
|
"""
|
|
26
26
|
|
|
27
|
-
def decorator(func: Callable):
|
|
27
|
+
def decorator(func: T.Callable):
|
|
28
28
|
@wraps(func)
|
|
29
29
|
def wrapper(*args, **kwargs):
|
|
30
30
|
time_start = time.perf_counter()
|
|
@@ -84,3 +84,6 @@ def retry(attempts: int, delay: float = 0):
|
|
|
84
84
|
return wrapper
|
|
85
85
|
|
|
86
86
|
return decorator
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
__all__ = ["timer", "retry"]
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import random
|
|
2
2
|
import time
|
|
3
|
+
import typing as T
|
|
3
4
|
from dataclasses import dataclass
|
|
4
5
|
from datetime import date, datetime, timedelta, timezone
|
|
5
|
-
from typing import Generator
|
|
6
6
|
|
|
7
7
|
from dateutil.parser import parse as parse_datetime_str
|
|
8
8
|
|
|
@@ -40,12 +40,12 @@ class Timer:
|
|
|
40
40
|
Stop the timer.
|
|
41
41
|
|
|
42
42
|
Args:
|
|
43
|
-
label (str | None, optional): Label for the stop.
|
|
43
|
+
label (str | None, optional): Label for the stop.
|
|
44
44
|
|
|
45
45
|
Returns:
|
|
46
46
|
TimerStop: The stop data
|
|
47
47
|
"""
|
|
48
|
-
t = 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.
|
|
81
|
+
self.start = time.perf_counter()
|
|
82
82
|
self.stops: list[TimerStop] = [
|
|
83
83
|
TimerStop(
|
|
84
84
|
total=timedelta(seconds=0),
|
|
@@ -88,10 +88,6 @@ class Timer:
|
|
|
88
88
|
)
|
|
89
89
|
]
|
|
90
90
|
|
|
91
|
-
def print_stops(self) -> None:
|
|
92
|
-
for stop in self.stops:
|
|
93
|
-
print(stop)
|
|
94
|
-
|
|
95
91
|
|
|
96
92
|
def datetime_fmt(
|
|
97
93
|
d: str | float | int | None | datetime = None,
|
|
@@ -105,12 +101,12 @@ def datetime_fmt(
|
|
|
105
101
|
"""Format date and time
|
|
106
102
|
|
|
107
103
|
Args:
|
|
108
|
-
d (str | float | None | datetime, optional): Input datetime. Defaults to
|
|
109
|
-
fmt (str, optional): Date format.
|
|
110
|
-
dsep (str, optional): Date values separator.
|
|
111
|
-
tsep (str, optional): Time values separator.
|
|
112
|
-
ms (bool, optional): include miliseconds.
|
|
113
|
-
utc (bool, optional): Use the UTC timezone when building a datetime object from a timestamp.
|
|
104
|
+
d (str | float | None | datetime, optional): Input datetime. Defaults to current date and time.
|
|
105
|
+
fmt (str, optional): Date format.
|
|
106
|
+
dsep (str, optional): Date values separator.
|
|
107
|
+
tsep (str, optional): Time values separator.
|
|
108
|
+
ms (bool, optional): include miliseconds.
|
|
109
|
+
utc (bool, optional): Use the UTC timezone when building a datetime object from a timestamp.
|
|
114
110
|
|
|
115
111
|
Raises:
|
|
116
112
|
TypeError: Raises TypeError if the type of ``d`` is not one of the following: float, str, None, datetime, int
|
|
@@ -118,17 +114,18 @@ def datetime_fmt(
|
|
|
118
114
|
Returns:
|
|
119
115
|
str: Formated date and time.
|
|
120
116
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
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
|
+
```
|
|
129
126
|
"""
|
|
130
127
|
if d is None:
|
|
131
|
-
d = datetime.fromtimestamp(time.
|
|
128
|
+
d = datetime.fromtimestamp(time.perf_counter(), **{"tz": timezone.utc} if utc else {})
|
|
132
129
|
|
|
133
130
|
elif isinstance(d, str):
|
|
134
131
|
d = parse_datetime_str(d)
|
|
@@ -153,10 +150,10 @@ def time_fmt(
|
|
|
153
150
|
Format time
|
|
154
151
|
|
|
155
152
|
Args:
|
|
156
|
-
t (float | datetime | int | None, optional): Input time. Defaults to current time
|
|
157
|
-
sep (str, optional): Character(s) that separates hours, minutes, seconds...
|
|
158
|
-
ms (bool, optional): include miliseconds.
|
|
159
|
-
utc (bool, optional): Use the UTC timezone when building a time object from a timestamp.
|
|
153
|
+
t (float | datetime | int | None, optional): Input time. Defaults to current time.
|
|
154
|
+
sep (str, optional): Character(s) that separates hours, minutes, seconds...
|
|
155
|
+
ms (bool, optional): include miliseconds.
|
|
156
|
+
utc (bool, optional): Use the UTC timezone when building a time object from a timestamp.
|
|
160
157
|
|
|
161
158
|
Raises:
|
|
162
159
|
TypeError: Raises TypeError if the type of ``t`` is not one of the following: float, None, datetime, int
|
|
@@ -165,7 +162,7 @@ def time_fmt(
|
|
|
165
162
|
str: Formated time.
|
|
166
163
|
"""
|
|
167
164
|
if t is None:
|
|
168
|
-
tm = datetime.fromtimestamp(time.
|
|
165
|
+
tm = datetime.fromtimestamp(time.perf_counter(), **{"tz": timezone.utc} if utc else {})
|
|
169
166
|
elif isinstance(t, datetime):
|
|
170
167
|
tm = t.time()
|
|
171
168
|
elif isinstance(t, (int, float)):
|
|
@@ -188,9 +185,9 @@ def date_fmt(
|
|
|
188
185
|
Format date
|
|
189
186
|
|
|
190
187
|
Args:
|
|
191
|
-
d (float | date | datetime | int | None ): Input date. Defaults to current date
|
|
192
|
-
fmt (str, optional): Date format.
|
|
193
|
-
sep (str, optional): Character(s) that separates days, months and years.
|
|
188
|
+
d (float | date | datetime | int | None ): Input date. Defaults to current date.
|
|
189
|
+
fmt (str, optional): Date format.
|
|
190
|
+
sep (str, optional): Character(s) that separates days, months and years.
|
|
194
191
|
|
|
195
192
|
Raises:
|
|
196
193
|
TypeError: Raises TypeError if the type of ``d`` is not one of the following: float, None, date, datetime, int
|
|
@@ -198,19 +195,20 @@ def date_fmt(
|
|
|
198
195
|
Returns:
|
|
199
196
|
str: Formated date.
|
|
200
197
|
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
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
|
+
```
|
|
211
209
|
"""
|
|
212
210
|
if d is None:
|
|
213
|
-
d = date.fromtimestamp(time.
|
|
211
|
+
d = date.fromtimestamp(time.perf_counter())
|
|
214
212
|
elif isinstance(d, (float, int)):
|
|
215
213
|
d = date.fromtimestamp(d)
|
|
216
214
|
elif isinstance(d, datetime):
|
|
@@ -222,16 +220,17 @@ def date_fmt(
|
|
|
222
220
|
return d.strftime(f"%{fmt[0]}{sep}%{fmt[1]}{sep}%{fmt[2]}")
|
|
223
221
|
|
|
224
222
|
|
|
225
|
-
def date_range(start: date, end: date) -> Generator[date, None, None]:
|
|
223
|
+
def date_range(start: date, end: date) -> T.Generator[date, None, None]:
|
|
226
224
|
"""
|
|
227
225
|
Returns a generator for dates between ``start`` and ``end``
|
|
228
226
|
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
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
|
+
```
|
|
235
234
|
"""
|
|
236
235
|
for n in range(int((end - start).days)):
|
|
237
236
|
yield start + timedelta(n)
|