python-base-toolkit 0.0.1__tar.gz → 0.0.2__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.
Files changed (42) hide show
  1. {python_base_toolkit-0.0.1/python_base_toolkit.egg-info → python_base_toolkit-0.0.2}/PKG-INFO +6 -4
  2. {python_base_toolkit-0.0.1 → python_base_toolkit-0.0.2}/README.md +3 -3
  3. python_base_toolkit-0.0.2/python_base_toolkit/consts/operating_system.py +4 -0
  4. {python_base_toolkit-0.0.1 → python_base_toolkit-0.0.2}/python_base_toolkit/consts/units/__init__.py +2 -2
  5. python_base_toolkit-0.0.2/python_base_toolkit/consts/units/binary_units.py +13 -0
  6. {python_base_toolkit-0.0.1 → python_base_toolkit-0.0.2}/python_base_toolkit/decorators/telemetry.py +7 -9
  7. {python_base_toolkit-0.0.1 → python_base_toolkit-0.0.2}/python_base_toolkit/decorators/timer.py +10 -3
  8. {python_base_toolkit-0.0.1 → python_base_toolkit-0.0.2}/python_base_toolkit/instances/instance_manager.py +17 -16
  9. {python_base_toolkit-0.0.1 → python_base_toolkit-0.0.2}/python_base_toolkit/utils/data_serialization.py +3 -3
  10. {python_base_toolkit-0.0.1 → python_base_toolkit-0.0.2}/python_base_toolkit/utils/date_time.py +2 -2
  11. {python_base_toolkit-0.0.1 → python_base_toolkit-0.0.2}/python_base_toolkit/utils/execute.py +1 -1
  12. {python_base_toolkit-0.0.1 → python_base_toolkit-0.0.2}/python_base_toolkit/utils/file_utils.py +167 -160
  13. python_base_toolkit-0.0.2/python_base_toolkit/utils/generate_id.py +35 -0
  14. {python_base_toolkit-0.0.1 → python_base_toolkit-0.0.2}/python_base_toolkit/utils/logo.py +1 -1
  15. python_base_toolkit-0.0.2/python_base_toolkit/utils/network.py +146 -0
  16. {python_base_toolkit-0.0.1 → python_base_toolkit-0.0.2}/python_base_toolkit/utils/path_utils.py +4 -5
  17. {python_base_toolkit-0.0.1 → python_base_toolkit-0.0.2}/python_base_toolkit/utils/pretty_print.py +3 -6
  18. {python_base_toolkit-0.0.1 → python_base_toolkit-0.0.2}/python_base_toolkit/utils/pycache.py +3 -3
  19. {python_base_toolkit-0.0.1 → python_base_toolkit-0.0.2}/python_base_toolkit/utils/random_utils.py +7 -7
  20. python_base_toolkit-0.0.2/python_base_toolkit/utils/venv_details.py +10 -0
  21. {python_base_toolkit-0.0.1 → python_base_toolkit-0.0.2/python_base_toolkit.egg-info}/PKG-INFO +6 -4
  22. {python_base_toolkit-0.0.1 → python_base_toolkit-0.0.2}/python_base_toolkit.egg-info/SOURCES.txt +2 -0
  23. {python_base_toolkit-0.0.1 → python_base_toolkit-0.0.2}/python_base_toolkit.egg-info/requires.txt +2 -0
  24. {python_base_toolkit-0.0.1 → python_base_toolkit-0.0.2}/requirements.txt +2 -0
  25. python_base_toolkit-0.0.2/setup.py +40 -0
  26. python_base_toolkit-0.0.1/python_base_toolkit/consts/units/binary_units.py +0 -13
  27. python_base_toolkit-0.0.1/python_base_toolkit/utils/network.py +0 -102
  28. python_base_toolkit-0.0.1/python_base_toolkit/utils/venv_details.py +0 -10
  29. python_base_toolkit-0.0.1/setup.py +0 -42
  30. {python_base_toolkit-0.0.1 → python_base_toolkit-0.0.2}/LICENSE +0 -0
  31. {python_base_toolkit-0.0.1 → python_base_toolkit-0.0.2}/MANIFEST.in +0 -0
  32. {python_base_toolkit-0.0.1 → python_base_toolkit-0.0.2}/pyproject.toml +0 -0
  33. {python_base_toolkit-0.0.1 → python_base_toolkit-0.0.2}/python_base_toolkit/__init__.py +0 -0
  34. {python_base_toolkit-0.0.1 → python_base_toolkit-0.0.2}/python_base_toolkit/consts/__init__.py +0 -0
  35. {python_base_toolkit-0.0.1 → python_base_toolkit-0.0.2}/python_base_toolkit/consts/units/time_units.py +0 -0
  36. {python_base_toolkit-0.0.1 → python_base_toolkit-0.0.2}/python_base_toolkit/decorators/__init__.py +0 -0
  37. {python_base_toolkit-0.0.1 → python_base_toolkit-0.0.2}/python_base_toolkit/instances/__init__.py +0 -0
  38. {python_base_toolkit-0.0.1 → python_base_toolkit-0.0.2}/python_base_toolkit/utils/__init__.py +0 -0
  39. {python_base_toolkit-0.0.1 → python_base_toolkit-0.0.2}/python_base_toolkit/utils/shorten_url.py +0 -0
  40. {python_base_toolkit-0.0.1 → python_base_toolkit-0.0.2}/python_base_toolkit.egg-info/dependency_links.txt +0 -0
  41. {python_base_toolkit-0.0.1 → python_base_toolkit-0.0.2}/python_base_toolkit.egg-info/top_level.txt +0 -0
  42. {python_base_toolkit-0.0.1 → python_base_toolkit-0.0.2}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: python-base-toolkit
3
- Version: 0.0.1
3
+ Version: 0.0.2
4
4
  Summary: A Python package for managing pytest plugins.
5
5
  Home-page: https://github.com/aviz92/python-base-toolkit
6
6
  Author: Avi Zaguri
@@ -13,6 +13,8 @@ Description-Content-Type: text/markdown
13
13
  License-File: LICENSE
14
14
  Requires-Dist: setuptools
15
15
  Requires-Dist: wheel
16
+ Requires-Dist: python-dotenv
17
+ Requires-Dist: pre-commit
16
18
  Requires-Dist: colorlog
17
19
  Requires-Dist: pathlib
18
20
  Requires-Dist: requests
@@ -47,15 +49,15 @@ pip install python-toolkit
47
49
  ---
48
50
 
49
51
  ## 🚀 Features
50
- - Constants Pack
51
- - binary
52
+ - Constants Pack
53
+ - binary
52
54
  - time
53
55
 
54
56
  - Decorators Pack
55
57
  - telemetry
56
58
  - timer
57
59
 
58
- - Instances Pack
60
+ - Instances Pack
59
61
  - instance_manager
60
62
 
61
63
  - Utilities Pack
@@ -13,15 +13,15 @@ pip install python-toolkit
13
13
  ---
14
14
 
15
15
  ## 🚀 Features
16
- - Constants Pack
17
- - binary
16
+ - Constants Pack
17
+ - binary
18
18
  - time
19
19
 
20
20
  - Decorators Pack
21
21
  - telemetry
22
22
  - timer
23
23
 
24
- - Instances Pack
24
+ - Instances Pack
25
25
  - instance_manager
26
26
 
27
27
  - Utilities Pack
@@ -0,0 +1,4 @@
1
+ class Platform:
2
+ WINDOWS = "Windows"
3
+ LINUX = "Linux"
4
+ MACOS = "macOS"
@@ -2,6 +2,6 @@ import python_base_toolkit.consts.units.binary_units
2
2
  import python_base_toolkit.consts.units.time_units
3
3
 
4
4
  __all__ = [
5
- 'binary_units',
6
- 'time_units',
5
+ "binary_units",
6
+ "time_units",
7
7
  ]
@@ -0,0 +1,13 @@
1
+ B = 8
2
+ KiB = 1024
3
+ MiB = KiB * 1024
4
+ GiB = MiB * 1024
5
+ TiB = GiB * 1024
6
+ PiB = TiB * 1024
7
+ EiB = PiB * 1024
8
+
9
+ KB = 1000 # 1 kilobyte (KB) = 1000 bytes in decimal (SI)
10
+ GB = 1000**3 # 1 gigabyte (GB) = 1000^3 bytes in decimal (SI)
11
+ TB = 1000**4 # 1 terabyte (TB) = 1000^4 bytes in decimal (SI)
12
+ PB = 1000**5 # 1 petabyte (PB) = 1000^5 bytes in decimal (SI)
13
+ EB = 1000**6 # 1 exabyte (EB) = 1000^6 bytes in decimal (SI)
@@ -1,8 +1,9 @@
1
+ import datetime
1
2
  import json
2
3
  import time
4
+ from collections.abc import Callable
3
5
  from functools import wraps
4
- import datetime
5
- from typing import Callable, Any
6
+ from typing import Any
6
7
 
7
8
  from custom_python_logger import get_logger
8
9
 
@@ -10,11 +11,7 @@ logger = get_logger(__name__)
10
11
 
11
12
 
12
13
  def report_telemetry(
13
- func: Callable[..., Any],
14
- start_time: datetime.datetime,
15
- end_time: datetime.datetime,
16
- *args: Any,
17
- **kwargs: Any
14
+ func: Callable[..., Any], start_time: datetime.datetime, end_time: datetime.datetime, *args: Any, **kwargs: Any
18
15
  ) -> None:
19
16
  data = {
20
17
  "function_name": func.__name__,
@@ -25,7 +22,8 @@ def report_telemetry(
25
22
  "timestamp": time.time(),
26
23
  }
27
24
  logger.info(
28
- f"Sending telemetry data with the following data: {json.dumps(data, indent=4, sort_keys=False, default=str)}")
25
+ f"Sending telemetry data with the following data: {json.dumps(data, indent=4, sort_keys=False, default=str)}"
26
+ )
29
27
 
30
28
 
31
29
  def report_func_telemetry(func: Callable[..., Any]) -> Callable[..., Any]:
@@ -37,7 +35,7 @@ def report_func_telemetry(func: Callable[..., Any]) -> Callable[..., Any]:
37
35
  start_time = datetime.datetime.now(datetime.UTC)
38
36
  result = func(*args, **kwargs)
39
37
  end_time = datetime.datetime.now(datetime.UTC)
40
- report_telemetry(func=func, start_time=start_time, end_time=end_time, *args, **kwargs)
38
+ report_telemetry(*args, func=func, start_time=start_time, end_time=end_time, **kwargs)
41
39
  return result
42
40
 
43
41
  return wrapper
@@ -1,6 +1,7 @@
1
1
  import time
2
+ from collections.abc import Callable
2
3
  from functools import wraps
3
- from typing import Callable, Any
4
+ from typing import Any
4
5
 
5
6
  from custom_python_logger import get_logger
6
7
 
@@ -8,12 +9,17 @@ logger = get_logger(__name__)
8
9
 
9
10
 
10
11
  class Timer:
11
- def __enter__(self):
12
+ def __init__(self) -> None:
13
+ self.start_time = None
14
+ self.end_time = None
15
+ self.elapsed_time = None
16
+
17
+ def __enter__(self) -> "Timer":
12
18
  self.start_time = time.perf_counter()
13
19
  logger.info("Timer started.")
14
20
  return self
15
21
 
16
- def __exit__(self, exc_type, exc_value, exc_traceback):
22
+ def __exit__(self, exc_type: type, exc_value: Exception, exc_traceback: object) -> None:
17
23
  # logger.info(exc_type, exc_value, exc_traceback)
18
24
  self.end_time = time.perf_counter()
19
25
  self.elapsed_time = self.end_time - self.start_time
@@ -25,4 +31,5 @@ def timer(func: Callable[..., Any]) -> Callable[..., Any]:
25
31
  def wrapper(*args: Any, **kwargs: Any) -> Any:
26
32
  with Timer():
27
33
  return func(*args, **kwargs)
34
+
28
35
  return wrapper
@@ -1,18 +1,19 @@
1
1
  from custom_python_logger.logger import get_logger
2
2
 
3
+
3
4
  class InstanceManager:
4
- def __init__(self):
5
+ def __init__(self) -> None:
5
6
  self.logger = get_logger(__class__.__name__)
6
7
  self._instances = []
7
8
 
8
- def add(self, instance):
9
+ def add(self, instance: object) -> None:
9
10
  self._instances.append(instance)
10
11
 
11
- def close_all(self):
12
+ def close_all(self) -> None:
12
13
  for instance in reversed(self._instances):
13
14
  _instance_name = instance.__class__.__name__
14
15
  try:
15
- if hasattr(instance, 'close'):
16
+ if hasattr(instance, "close"):
16
17
  instance.close()
17
18
  else: # hasattr(instance, '__exit__'):
18
19
  instance.__exit__(None, None, None)
@@ -20,31 +21,31 @@ class InstanceManager:
20
21
  except Exception as e:
21
22
  self.logger.info(f"Failed to close instance {instance}: {e}")
22
23
 
23
- def __enter__(self):
24
+ def __enter__(self) -> "InstanceManager":
24
25
  return self
25
26
 
26
- def __exit__(self, exc_type, exc_value, traceback):
27
+ def __exit__(self, exc_type: type, exc_value: Exception, traceback: object) -> None:
27
28
  self.close_all()
28
29
 
29
30
 
30
- def main():
31
+ def main() -> None:
31
32
  class SomeInstance:
32
- def __init__(self, add_to_instance_manager: bool = False):
33
+ def __init__(self, add_to_instance_manager: bool = False) -> None:
33
34
  self.logger = get_logger(__class__.__name__)
34
35
 
35
36
  if add_to_instance_manager:
36
- instance_manager.add(self)
37
+ instance_manager.add(self) # pylint: disable=E0601
37
38
 
38
39
  @property
39
- def __class_name__(self):
40
+ def class_name(self) -> str:
40
41
  return self.__class__.__name__
41
42
 
42
- def __enter__(self):
43
- self.logger.info(f"Entering {self.__class_name__}")
43
+ def __enter__(self) -> "SomeInstance":
44
+ self.logger.info(f"Entering {self.class_name}")
44
45
  return self
45
46
 
46
- def __exit__(self, exc_type, exc_value, exc_traceback):
47
- self.logger.info(f"Exiting {self.__class_name__}")
47
+ def __exit__(self, exc_type: type, exc_value: Exception, traceback: object) -> bool:
48
+ self.logger.info(f"Exiting {self.class_name}")
48
49
  # Handle any cleanup here
49
50
  if exc_type:
50
51
  self.logger.info(f"Exception: {exc_value}")
@@ -52,8 +53,8 @@ def main():
52
53
 
53
54
  SomeInstance(add_to_instance_manager=True)
54
55
 
55
- resource1 = open('file1.txt', 'w')
56
- resource2 = open('file2.txt', 'w')
56
+ resource1 = open("file1.txt", "w") # pylint: disable=R1732
57
+ resource2 = open("file2.txt", "w") # pylint: disable=R1732
57
58
 
58
59
  instance_manager.add(resource1)
59
60
  instance_manager.add(resource2)
@@ -1,6 +1,6 @@
1
1
  import json
2
2
  from dataclasses import is_dataclass
3
- from datetime import datetime, date, time
3
+ from datetime import date, datetime, time
4
4
  from decimal import Decimal
5
5
  from enum import Enum
6
6
  from pathlib import Path
@@ -23,7 +23,7 @@ def default_serialize(obj: object) -> object:
23
23
  return list(obj)
24
24
  if isinstance(obj, tuple):
25
25
  return list(obj)
26
- if isinstance(obj, (datetime, date, time)):
26
+ if isinstance(obj, datetime | date | time):
27
27
  return obj.isoformat()
28
28
  if isinstance(obj, Decimal):
29
29
  return float(obj)
@@ -31,7 +31,7 @@ def default_serialize(obj: object) -> object:
31
31
  return str(obj)
32
32
  if obj is pd.NA:
33
33
  return None
34
- logger.error(f'Object is not serializable: {obj}')
34
+ logger.error(f"Object is not serializable: {obj}")
35
35
  raise TypeError(f"Type {type(obj)} not serializable")
36
36
 
37
37
 
@@ -1,7 +1,7 @@
1
1
  from datetime import datetime
2
2
  from zoneinfo import ZoneInfo
3
3
 
4
- utc_timezone = ZoneInfo('UTC')
4
+ utc_timezone = ZoneInfo("UTC")
5
5
 
6
6
 
7
7
  def datetime_now_with_timezone(timezone: ZoneInfo = utc_timezone) -> datetime:
@@ -9,6 +9,6 @@ def datetime_now_with_timezone(timezone: ZoneInfo = utc_timezone) -> datetime:
9
9
  raise TypeError(f"Expected pytz timezone, got {type(timezone).__name__}")
10
10
 
11
11
  now_utc = datetime.now(timezone)
12
- if timezone.key == 'UTC':
12
+ if timezone.key == "UTC":
13
13
  return now_utc
14
14
  return now_utc.astimezone(timezone)
@@ -16,7 +16,7 @@ def _timed_execution(
16
16
  pbar = tqdm(total=timeout, desc=pb_description, unit="s", ncols=100)
17
17
  start_time = time()
18
18
 
19
- while time() - start_time < timeout:
19
+ while time() - start_time < timeout: # pylint: disable=W0149
20
20
  res = func()
21
21
  if (expect_true and res) or (not expect_true and not res):
22
22
  pbar.close()