monkeytoolbox 0.1.0__tar.gz → 0.3.0__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.
@@ -0,0 +1,22 @@
1
+ # Changelog
2
+ All notable changes to this project will be documented in this
3
+ file.
4
+
5
+ The format is based on [Keep a
6
+ Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to
7
+ the [PEP 440 version scheme](https://peps.python.org/pep-0440/#version-scheme).
8
+
9
+
10
+ ## [v0.3.0 - 2024-01-16]
11
+ ### Fixed
12
+ - The location of the `py.typed` file so that type checking is now properly
13
+ supported
14
+
15
+ ## [v0.2.0 - 2024-01-04]
16
+ ### Added
17
+ - `get_os_version()`
18
+ - `get_hostname()`
19
+ - Support for type checking (py.typed marker file)
20
+
21
+ ### Changed
22
+ - `get_os()` raises `RuntimeError` if the operating system is not supported
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: monkeytoolbox
3
- Version: 0.1.0
3
+ Version: 0.3.0
4
4
  Summary: Miscellaneous convenience utilities for Python programs
5
5
  Home-page: https://github.com/guardicode/monkeytoolbox
6
6
  License: GPLv3
@@ -1,4 +1,4 @@
1
- from .environment import get_os, get_hardware_id
1
+ from .environment import get_hardware_id, get_hostname, get_os, get_os_version
2
2
  from .decorators import request_cache
3
3
  from .code_utils import (
4
4
  apply_filters,
@@ -6,7 +6,7 @@ from .code_utils import (
6
6
  del_key,
7
7
  insecure_generate_random_string,
8
8
  secure_generate_random_string,
9
- PeriodicCaller
9
+ PeriodicCaller,
10
10
  )
11
11
  from .file_utils import (
12
12
  append_bytes,
@@ -15,20 +15,16 @@ from .file_utils import (
15
15
  expand_path,
16
16
  get_text_file_contents,
17
17
  get_all_regular_files_in_directory,
18
- get_binary_io_sha256_hash
18
+ get_binary_io_sha256_hash,
19
19
  )
20
20
  from .secure_directory import create_secure_directory
21
21
  from .secure_file import open_new_securely_permissioned_file
22
22
  from .threading import (
23
- ThreadSafeIterator,
24
- InterruptableThreadMixin,
25
- interruptible_function,
23
+ ThreadSafeIterator,
24
+ InterruptableThreadMixin,
25
+ interruptible_function,
26
26
  interruptible_iter,
27
27
  create_daemon_thread,
28
- run_worker_threads
29
- )
30
- from .network_utils import (
31
- port_is_used,
32
- get_network_interfaces,
33
- get_my_ip_addresses
28
+ run_worker_threads,
34
29
  )
30
+ from .network_utils import port_is_used, get_network_interfaces, get_my_ip_addresses
@@ -2,7 +2,7 @@ import threading
2
2
  from functools import wraps
3
3
  from typing import Any, Callable
4
4
 
5
- from egg_timer import EggTimer
5
+ from eggtimer import EggTimer
6
6
 
7
7
 
8
8
  def request_cache(ttl: float):
@@ -1,4 +1,5 @@
1
1
  import platform
2
+ import socket
2
3
  import uuid
3
4
  from contextlib import suppress
4
5
 
@@ -6,10 +7,21 @@ from monkeytypes import HardwareID, OperatingSystem
6
7
 
7
8
 
8
9
  def get_os() -> OperatingSystem:
9
- if platform.system() == "Windows":
10
+ """
11
+ Get the OperatingSystem of the current execution environment.
12
+
13
+ :return: The OperatingSystem of the current execution environment
14
+ :raises: RuntimeError if the current OperatingSystem is not supported
15
+ """
16
+ system = platform.system()
17
+
18
+ if system == "Windows":
10
19
  return OperatingSystem.WINDOWS
11
20
 
12
- return OperatingSystem.LINUX
21
+ if system == "Linux":
22
+ return OperatingSystem.LINUX
23
+
24
+ raise RuntimeError(f"'{system}' is not a supported operating system")
13
25
 
14
26
 
15
27
  def get_hardware_id() -> HardwareID:
@@ -36,3 +48,11 @@ def _get_hardware_id_linux() -> HardwareID:
36
48
  machine_id = uuid.getnode()
37
49
 
38
50
  return machine_id
51
+
52
+
53
+ def get_os_version() -> str:
54
+ return platform.platform()
55
+
56
+
57
+ def get_hostname():
58
+ return socket.gethostname()
File without changes
@@ -3,10 +3,10 @@ import stat
3
3
  from pathlib import Path
4
4
  from typing import Callable
5
5
 
6
- from . import get_os
7
-
8
6
  from monkeytypes import OperatingSystem
9
7
 
8
+ from . import get_os
9
+
10
10
  if get_os() == OperatingSystem.WINDOWS:
11
11
  import win32file
12
12
  import win32security
@@ -74,9 +74,7 @@ def _make_existing_directory_secure_windows(path: Path):
74
74
 
75
75
  def _create_secure_directory_windows(path: Path):
76
76
  security_attributes = win32security.SECURITY_ATTRIBUTES()
77
- security_attributes.SECURITY_DESCRIPTOR = (
78
- get_security_descriptor_for_owner_only_permissions()
79
- )
77
+ security_attributes.SECURITY_DESCRIPTOR = get_security_descriptor_for_owner_only_permissions()
80
78
  win32file.CreateDirectory(str(path), security_attributes)
81
79
 
82
80
 
@@ -4,9 +4,10 @@ import stat
4
4
  from contextlib import contextmanager
5
5
  from typing import Generator
6
6
 
7
- from . import get_os
8
7
  from monkeytypes import OperatingSystem
9
8
 
9
+ from . import get_os
10
+
10
11
  if get_os() == OperatingSystem.WINDOWS:
11
12
  import win32file
12
13
  import win32job
@@ -10,25 +10,30 @@ from monkeytypes import Event
10
10
  logger = logging.getLogger(__name__)
11
11
 
12
12
 
13
- def run_worker_threads(
14
- target: Callable[..., None],
15
- name_prefix: str,
16
- args: Tuple = (),
17
- num_workers: int = 2,
18
- ):
19
- worker_threads = []
20
- counter = run_worker_threads.counters.setdefault(name_prefix, count(start=1))
21
- for i in range(0, num_workers):
22
- name = f"{name_prefix}-{next(counter):02d}"
23
- t = create_daemon_thread(target=target, name=name, args=args)
24
- t.start()
25
- worker_threads.append(t)
26
-
27
- for t in worker_threads:
28
- t.join()
29
-
30
-
31
- run_worker_threads.counters = {}
13
+ class RunWorkerThreads:
14
+ def __init__(self):
15
+ self._counters = {}
16
+
17
+ def __call__(
18
+ self,
19
+ target: Callable[..., None],
20
+ name_prefix: str,
21
+ args: Tuple = (),
22
+ num_workers: int = 2,
23
+ ):
24
+ worker_threads = []
25
+ counter = self._counters.setdefault(name_prefix, count(start=1))
26
+ for i in range(0, num_workers):
27
+ name = f"{name_prefix}-{next(counter):02d}"
28
+ t = create_daemon_thread(target=target, name=name, args=args)
29
+ t.start()
30
+ worker_threads.append(t)
31
+
32
+ for t in worker_threads:
33
+ t.join()
34
+
35
+
36
+ run_worker_threads = RunWorkerThreads()
32
37
 
33
38
 
34
39
  def create_daemon_thread(target: Callable[..., None], name: str, args: Tuple = ()) -> Thread:
@@ -43,7 +43,7 @@ paths = ["monkeytoolbox", "vulture_allowlist.py"]
43
43
 
44
44
  [tool.poetry]
45
45
  name = "monkeytoolbox"
46
- version = "v0.1.0"
46
+ version = "v0.3.0"
47
47
  description = "Miscellaneous convenience utilities for Python programs"
48
48
  authors = [
49
49
  "Ilija Lazoroski <ilija.la@live.com>",
@@ -1,15 +0,0 @@
1
- # Changelog
2
- All notable changes to this project will be documented in this
3
- file.
4
-
5
- The format is based on [Keep a
6
- Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to
7
- the [PEP 440 version scheme](https://peps.python.org/pep-0440/#version-scheme).
8
-
9
-
10
- ## [Unreleased]
11
- ### Added
12
- ### Changed
13
- ### Fixed
14
- ### Removed
15
- ### Security
File without changes
File without changes