stouputils 1.12.1__py3-none-any.whl → 1.13.0__py3-none-any.whl
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.
- stouputils/__init__.py +4 -4
- stouputils/__init__.pyi +1 -0
- stouputils/__main__.py +14 -9
- stouputils/continuous_delivery/pypi.py +39 -1
- stouputils/continuous_delivery/pypi.pyi +9 -0
- stouputils/ctx.py +408 -408
- stouputils/data_science/config/set.py +125 -125
- stouputils/data_science/models/keras_utils/callbacks/model_checkpoint_v2.py +31 -31
- stouputils/data_science/utils.py +285 -285
- stouputils/installer/__init__.py +18 -18
- stouputils/installer/linux.py +144 -144
- stouputils/installer/main.py +223 -223
- stouputils/installer/windows.py +136 -136
- stouputils/print.py +0 -58
- stouputils/print.pyi +0 -10
- stouputils/py.typed +1 -1
- stouputils/stouputils/__init__.pyi +15 -0
- stouputils/stouputils/_deprecated.pyi +12 -0
- stouputils/stouputils/all_doctests.pyi +46 -0
- stouputils/stouputils/applications/__init__.pyi +2 -0
- stouputils/stouputils/applications/automatic_docs.pyi +106 -0
- stouputils/stouputils/applications/upscaler/__init__.pyi +3 -0
- stouputils/stouputils/applications/upscaler/config.pyi +18 -0
- stouputils/stouputils/applications/upscaler/image.pyi +109 -0
- stouputils/stouputils/applications/upscaler/video.pyi +60 -0
- stouputils/stouputils/archive.pyi +67 -0
- stouputils/stouputils/backup.pyi +109 -0
- stouputils/stouputils/collections.pyi +86 -0
- stouputils/stouputils/continuous_delivery/__init__.pyi +5 -0
- stouputils/stouputils/continuous_delivery/cd_utils.pyi +129 -0
- stouputils/stouputils/continuous_delivery/github.pyi +162 -0
- stouputils/stouputils/continuous_delivery/pypi.pyi +53 -0
- stouputils/stouputils/continuous_delivery/pyproject.pyi +67 -0
- stouputils/stouputils/continuous_delivery/stubs.pyi +39 -0
- stouputils/stouputils/ctx.pyi +211 -0
- stouputils/stouputils/decorators.pyi +242 -0
- stouputils/stouputils/image.pyi +172 -0
- stouputils/stouputils/installer/__init__.pyi +5 -0
- stouputils/stouputils/installer/common.pyi +39 -0
- stouputils/stouputils/installer/downloader.pyi +24 -0
- stouputils/stouputils/installer/linux.pyi +39 -0
- stouputils/stouputils/installer/main.pyi +57 -0
- stouputils/stouputils/installer/windows.pyi +31 -0
- stouputils/stouputils/io.pyi +213 -0
- stouputils/stouputils/parallel.pyi +211 -0
- stouputils/stouputils/print.pyi +136 -0
- stouputils/stouputils/version_pkg.pyi +15 -0
- stouputils/version_pkg.py +189 -0
- stouputils/version_pkg.pyi +15 -0
- {stouputils-1.12.1.dist-info → stouputils-1.13.0.dist-info}/METADATA +1 -2
- {stouputils-1.12.1.dist-info → stouputils-1.13.0.dist-info}/RECORD +53 -20
- {stouputils-1.12.1.dist-info → stouputils-1.13.0.dist-info}/WHEEL +0 -0
- {stouputils-1.12.1.dist-info → stouputils-1.13.0.dist-info}/entry_points.txt +0 -0
stouputils/installer/windows.py
CHANGED
|
@@ -1,136 +1,136 @@
|
|
|
1
|
-
""" Installer module for Windows specific functions.
|
|
2
|
-
|
|
3
|
-
Provides Windows specific implementations for checking administrator privileges,
|
|
4
|
-
determining appropriate installation paths (global/local), and modifying
|
|
5
|
-
the user's PATH environment variable.
|
|
6
|
-
"""
|
|
7
|
-
# Imports
|
|
8
|
-
import os
|
|
9
|
-
|
|
10
|
-
from ..decorators import LogLevels, handle_error
|
|
11
|
-
from ..io import clean_path
|
|
12
|
-
from ..print import debug, info, warning
|
|
13
|
-
from .common import ask_install_type, prompt_for_path
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
# Functions
|
|
17
|
-
@handle_error(message="Failed to add to PATH (Windows)", error_log=LogLevels.WARNING_TRACEBACK)
|
|
18
|
-
def add_to_path_windows(install_path: str) -> bool | None:
|
|
19
|
-
""" Add install_path to the User PATH environment variable on Windows.
|
|
20
|
-
|
|
21
|
-
Args:
|
|
22
|
-
install_path (str): The path to add to the User PATH environment variable.
|
|
23
|
-
|
|
24
|
-
Returns:
|
|
25
|
-
bool | None: True if the path was added to the User PATH environment variable, None otherwise.
|
|
26
|
-
"""
|
|
27
|
-
# Convert install_path to a Windows path if it's not already
|
|
28
|
-
install_path = install_path.replace("/", "\\")
|
|
29
|
-
os.makedirs(install_path, exist_ok=True)
|
|
30
|
-
|
|
31
|
-
# Get current user PATH
|
|
32
|
-
import winreg
|
|
33
|
-
with winreg.OpenKey(winreg.HKEY_CURRENT_USER, "Environment", 0, winreg.KEY_READ | winreg.KEY_WRITE) as key:
|
|
34
|
-
|
|
35
|
-
# Get the number of values in the registry key
|
|
36
|
-
num_values = winreg.QueryInfoKey(key)[1]
|
|
37
|
-
|
|
38
|
-
# Find the index of the 'Path' value
|
|
39
|
-
path_index = -1
|
|
40
|
-
for i in range(num_values):
|
|
41
|
-
if winreg.EnumValue(key, i)[0] == 'Path':
|
|
42
|
-
path_index = i
|
|
43
|
-
break
|
|
44
|
-
|
|
45
|
-
# Get the current path value
|
|
46
|
-
current_path: str = winreg.EnumValue(key, path_index)[1]
|
|
47
|
-
|
|
48
|
-
# Check if path is already present
|
|
49
|
-
if install_path not in current_path.split(';'):
|
|
50
|
-
new_path: str = f"{current_path};{install_path}"
|
|
51
|
-
winreg.SetValueEx(key, "Path", 0, winreg.REG_EXPAND_SZ, new_path)
|
|
52
|
-
debug(f"Added '{install_path}' to user PATH. Please restart your terminal for changes to take effect.")
|
|
53
|
-
else:
|
|
54
|
-
debug(f"'{install_path}' is already in user PATH.")
|
|
55
|
-
return True
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
def check_admin_windows() -> bool:
|
|
59
|
-
""" Check if the script is running with administrator privileges on Windows. """
|
|
60
|
-
try:
|
|
61
|
-
import ctypes
|
|
62
|
-
return ctypes.windll.shell32.IsUserAnAdmin() != 0
|
|
63
|
-
except Exception:
|
|
64
|
-
return False
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
@handle_error(message="Failed to get installation path (Windows)", error_log=LogLevels.ERROR_TRACEBACK)
|
|
68
|
-
def get_install_path_windows(
|
|
69
|
-
program_name: str,
|
|
70
|
-
ask_global: int = 0,
|
|
71
|
-
add_path: bool = True,
|
|
72
|
-
append_to_path: str = "",
|
|
73
|
-
default_global: str = os.environ.get("ProgramFiles", "C:\\Program Files")
|
|
74
|
-
) -> str:
|
|
75
|
-
""" Get the installation path for the program
|
|
76
|
-
|
|
77
|
-
Args:
|
|
78
|
-
program_name (str): The name of the program to install.
|
|
79
|
-
ask_global (int): 0 = ask for anything, 1 = install globally, 2 = install locally
|
|
80
|
-
add_path (bool): Whether to add the program to the PATH environment variable. (Only if installed globally)
|
|
81
|
-
append_to_path (str): String to append to the installation path when adding to PATH.
|
|
82
|
-
(ex: "bin" if executables are in the bin folder)
|
|
83
|
-
default_global (str): The default global installation path.
|
|
84
|
-
(Default is "C:\\Program Files" which is the most common location for executables on Windows)
|
|
85
|
-
|
|
86
|
-
Returns:
|
|
87
|
-
str: The installation path.
|
|
88
|
-
"""
|
|
89
|
-
# Default path is located in the current working directory
|
|
90
|
-
default_local_path: str = clean_path(os.path.join(os.getcwd(), program_name))
|
|
91
|
-
|
|
92
|
-
# Define default global path (used in prompt even if not chosen initially)
|
|
93
|
-
default_global_path: str = clean_path(os.path.join(default_global, program_name))
|
|
94
|
-
|
|
95
|
-
# Ask user for installation type (global/local)
|
|
96
|
-
install_type: str = ask_install_type(ask_global, default_local_path, default_global_path)
|
|
97
|
-
|
|
98
|
-
# If the user wants to install globally,
|
|
99
|
-
if install_type == 'g':
|
|
100
|
-
|
|
101
|
-
# Check if the user has admin privileges,
|
|
102
|
-
if not check_admin_windows():
|
|
103
|
-
|
|
104
|
-
# If the user doesn't have admin privileges, fallback to local
|
|
105
|
-
warning(
|
|
106
|
-
f"Global installation requires administrator privileges. Please re-run as administrator.\n"
|
|
107
|
-
f"Install locally instead to '{default_local_path}'? (Y/n): "
|
|
108
|
-
)
|
|
109
|
-
if input().lower() == 'n':
|
|
110
|
-
info("Installation cancelled.")
|
|
111
|
-
return ""
|
|
112
|
-
else:
|
|
113
|
-
# Fallback to local path if user agrees
|
|
114
|
-
return prompt_for_path(
|
|
115
|
-
f"Falling back to local installation path: {default_local_path}.",
|
|
116
|
-
default_local_path
|
|
117
|
-
)
|
|
118
|
-
|
|
119
|
-
# If the user has admin privileges,
|
|
120
|
-
else:
|
|
121
|
-
# Ask it user wants to override the default global install path
|
|
122
|
-
install_path: str = prompt_for_path(
|
|
123
|
-
f"Default global installation path is {default_global_path}.",
|
|
124
|
-
default_global_path
|
|
125
|
-
)
|
|
126
|
-
if add_path:
|
|
127
|
-
add_to_path_windows(os.path.join(install_path, append_to_path))
|
|
128
|
-
return install_path
|
|
129
|
-
|
|
130
|
-
# Local install
|
|
131
|
-
else: # install_type == 'l'
|
|
132
|
-
return prompt_for_path(
|
|
133
|
-
f"Default local installation path is {default_local_path}.",
|
|
134
|
-
default_local_path
|
|
135
|
-
)
|
|
136
|
-
|
|
1
|
+
""" Installer module for Windows specific functions.
|
|
2
|
+
|
|
3
|
+
Provides Windows specific implementations for checking administrator privileges,
|
|
4
|
+
determining appropriate installation paths (global/local), and modifying
|
|
5
|
+
the user's PATH environment variable.
|
|
6
|
+
"""
|
|
7
|
+
# Imports
|
|
8
|
+
import os
|
|
9
|
+
|
|
10
|
+
from ..decorators import LogLevels, handle_error
|
|
11
|
+
from ..io import clean_path
|
|
12
|
+
from ..print import debug, info, warning
|
|
13
|
+
from .common import ask_install_type, prompt_for_path
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
# Functions
|
|
17
|
+
@handle_error(message="Failed to add to PATH (Windows)", error_log=LogLevels.WARNING_TRACEBACK)
|
|
18
|
+
def add_to_path_windows(install_path: str) -> bool | None:
|
|
19
|
+
""" Add install_path to the User PATH environment variable on Windows.
|
|
20
|
+
|
|
21
|
+
Args:
|
|
22
|
+
install_path (str): The path to add to the User PATH environment variable.
|
|
23
|
+
|
|
24
|
+
Returns:
|
|
25
|
+
bool | None: True if the path was added to the User PATH environment variable, None otherwise.
|
|
26
|
+
"""
|
|
27
|
+
# Convert install_path to a Windows path if it's not already
|
|
28
|
+
install_path = install_path.replace("/", "\\")
|
|
29
|
+
os.makedirs(install_path, exist_ok=True)
|
|
30
|
+
|
|
31
|
+
# Get current user PATH
|
|
32
|
+
import winreg
|
|
33
|
+
with winreg.OpenKey(winreg.HKEY_CURRENT_USER, "Environment", 0, winreg.KEY_READ | winreg.KEY_WRITE) as key:
|
|
34
|
+
|
|
35
|
+
# Get the number of values in the registry key
|
|
36
|
+
num_values = winreg.QueryInfoKey(key)[1]
|
|
37
|
+
|
|
38
|
+
# Find the index of the 'Path' value
|
|
39
|
+
path_index = -1
|
|
40
|
+
for i in range(num_values):
|
|
41
|
+
if winreg.EnumValue(key, i)[0] == 'Path':
|
|
42
|
+
path_index = i
|
|
43
|
+
break
|
|
44
|
+
|
|
45
|
+
# Get the current path value
|
|
46
|
+
current_path: str = winreg.EnumValue(key, path_index)[1]
|
|
47
|
+
|
|
48
|
+
# Check if path is already present
|
|
49
|
+
if install_path not in current_path.split(';'):
|
|
50
|
+
new_path: str = f"{current_path};{install_path}"
|
|
51
|
+
winreg.SetValueEx(key, "Path", 0, winreg.REG_EXPAND_SZ, new_path)
|
|
52
|
+
debug(f"Added '{install_path}' to user PATH. Please restart your terminal for changes to take effect.")
|
|
53
|
+
else:
|
|
54
|
+
debug(f"'{install_path}' is already in user PATH.")
|
|
55
|
+
return True
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def check_admin_windows() -> bool:
|
|
59
|
+
""" Check if the script is running with administrator privileges on Windows. """
|
|
60
|
+
try:
|
|
61
|
+
import ctypes
|
|
62
|
+
return ctypes.windll.shell32.IsUserAnAdmin() != 0
|
|
63
|
+
except Exception:
|
|
64
|
+
return False
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
@handle_error(message="Failed to get installation path (Windows)", error_log=LogLevels.ERROR_TRACEBACK)
|
|
68
|
+
def get_install_path_windows(
|
|
69
|
+
program_name: str,
|
|
70
|
+
ask_global: int = 0,
|
|
71
|
+
add_path: bool = True,
|
|
72
|
+
append_to_path: str = "",
|
|
73
|
+
default_global: str = os.environ.get("ProgramFiles", "C:\\Program Files")
|
|
74
|
+
) -> str:
|
|
75
|
+
""" Get the installation path for the program
|
|
76
|
+
|
|
77
|
+
Args:
|
|
78
|
+
program_name (str): The name of the program to install.
|
|
79
|
+
ask_global (int): 0 = ask for anything, 1 = install globally, 2 = install locally
|
|
80
|
+
add_path (bool): Whether to add the program to the PATH environment variable. (Only if installed globally)
|
|
81
|
+
append_to_path (str): String to append to the installation path when adding to PATH.
|
|
82
|
+
(ex: "bin" if executables are in the bin folder)
|
|
83
|
+
default_global (str): The default global installation path.
|
|
84
|
+
(Default is "C:\\Program Files" which is the most common location for executables on Windows)
|
|
85
|
+
|
|
86
|
+
Returns:
|
|
87
|
+
str: The installation path.
|
|
88
|
+
"""
|
|
89
|
+
# Default path is located in the current working directory
|
|
90
|
+
default_local_path: str = clean_path(os.path.join(os.getcwd(), program_name))
|
|
91
|
+
|
|
92
|
+
# Define default global path (used in prompt even if not chosen initially)
|
|
93
|
+
default_global_path: str = clean_path(os.path.join(default_global, program_name))
|
|
94
|
+
|
|
95
|
+
# Ask user for installation type (global/local)
|
|
96
|
+
install_type: str = ask_install_type(ask_global, default_local_path, default_global_path)
|
|
97
|
+
|
|
98
|
+
# If the user wants to install globally,
|
|
99
|
+
if install_type == 'g':
|
|
100
|
+
|
|
101
|
+
# Check if the user has admin privileges,
|
|
102
|
+
if not check_admin_windows():
|
|
103
|
+
|
|
104
|
+
# If the user doesn't have admin privileges, fallback to local
|
|
105
|
+
warning(
|
|
106
|
+
f"Global installation requires administrator privileges. Please re-run as administrator.\n"
|
|
107
|
+
f"Install locally instead to '{default_local_path}'? (Y/n): "
|
|
108
|
+
)
|
|
109
|
+
if input().lower() == 'n':
|
|
110
|
+
info("Installation cancelled.")
|
|
111
|
+
return ""
|
|
112
|
+
else:
|
|
113
|
+
# Fallback to local path if user agrees
|
|
114
|
+
return prompt_for_path(
|
|
115
|
+
f"Falling back to local installation path: {default_local_path}.",
|
|
116
|
+
default_local_path
|
|
117
|
+
)
|
|
118
|
+
|
|
119
|
+
# If the user has admin privileges,
|
|
120
|
+
else:
|
|
121
|
+
# Ask it user wants to override the default global install path
|
|
122
|
+
install_path: str = prompt_for_path(
|
|
123
|
+
f"Default global installation path is {default_global_path}.",
|
|
124
|
+
default_global_path
|
|
125
|
+
)
|
|
126
|
+
if add_path:
|
|
127
|
+
add_to_path_windows(os.path.join(install_path, append_to_path))
|
|
128
|
+
return install_path
|
|
129
|
+
|
|
130
|
+
# Local install
|
|
131
|
+
else: # install_type == 'l'
|
|
132
|
+
return prompt_for_path(
|
|
133
|
+
f"Default local installation path is {default_local_path}.",
|
|
134
|
+
default_local_path
|
|
135
|
+
)
|
|
136
|
+
|
stouputils/print.py
CHANGED
|
@@ -432,64 +432,6 @@ def current_time() -> str:
|
|
|
432
432
|
return time.strftime("%H:%M:%S")
|
|
433
433
|
|
|
434
434
|
|
|
435
|
-
def show_version(main_package: str = "stouputils", primary_color: str = CYAN, secondary_color: str = GREEN) -> None:
|
|
436
|
-
""" Print the version of the main package and its dependencies.
|
|
437
|
-
|
|
438
|
-
Used by the "stouputils --version" command.
|
|
439
|
-
|
|
440
|
-
Args:
|
|
441
|
-
main_package (str): Name of the main package to show version for
|
|
442
|
-
primary_color (str): Color to use for the primary package name
|
|
443
|
-
secondary_color (str): Color to use for the secondary package names
|
|
444
|
-
"""
|
|
445
|
-
# Imports
|
|
446
|
-
from importlib.metadata import requires, version
|
|
447
|
-
def ver(package_name: str) -> str:
|
|
448
|
-
try:
|
|
449
|
-
return version(package_name)
|
|
450
|
-
except Exception:
|
|
451
|
-
return ""
|
|
452
|
-
|
|
453
|
-
# Get dependencies dynamically and extract package names from requirements (e.g., "tqdm>=4.0.0" -> "tqdm")
|
|
454
|
-
deps: list[str] = requires(main_package) or []
|
|
455
|
-
dep_names: list[str] = sorted([
|
|
456
|
-
dep
|
|
457
|
-
.split(">")[0]
|
|
458
|
-
.split("<")[0]
|
|
459
|
-
.split("=")[0]
|
|
460
|
-
.split("[")[0]
|
|
461
|
-
for dep in deps
|
|
462
|
-
])
|
|
463
|
-
all_deps: list[tuple[str, str]] = [
|
|
464
|
-
(x, ver(x).split("version: ")[-1])
|
|
465
|
-
for x in (main_package, *dep_names)
|
|
466
|
-
]
|
|
467
|
-
all_deps = [pair for pair in all_deps if pair[1]] # Filter out packages with no version found
|
|
468
|
-
longest_name_length: int = max(len(name) for name, _ in all_deps)
|
|
469
|
-
longest_version_length: int = max(len(ver) for _, ver in all_deps)
|
|
470
|
-
|
|
471
|
-
# Get Python version
|
|
472
|
-
python_version: str = f" Python {sys.version_info.major}.{sys.version_info.minor}.{sys.version_info.micro} "
|
|
473
|
-
minimum_separator_length: int = len(python_version) + 10 # Always at least 5 dashes on each side
|
|
474
|
-
separator_length: int = max(minimum_separator_length, longest_name_length + longest_version_length + 4)
|
|
475
|
-
python_text_length: int = len(python_version)
|
|
476
|
-
left_dashes: int = (separator_length - python_text_length) // 2
|
|
477
|
-
right_dashes: int = separator_length - python_text_length - left_dashes
|
|
478
|
-
separator_with_python: str = "─" * left_dashes + python_version + "─" * right_dashes
|
|
479
|
-
separator: str = "─" * separator_length
|
|
480
|
-
|
|
481
|
-
for pkg, v in all_deps:
|
|
482
|
-
pkg_spacing: str = " " * (longest_name_length - len(pkg))
|
|
483
|
-
|
|
484
|
-
# Highlight the main package with a different style
|
|
485
|
-
if pkg == main_package:
|
|
486
|
-
print(f"{primary_color}{separator_with_python}{RESET}")
|
|
487
|
-
print(f"{primary_color}{pkg}{pkg_spacing} {secondary_color}v{v}{RESET}")
|
|
488
|
-
print(f"{primary_color}{separator}{RESET}")
|
|
489
|
-
else:
|
|
490
|
-
print(f"{primary_color}{pkg}{pkg_spacing} {secondary_color}v{v}{RESET}")
|
|
491
|
-
return
|
|
492
|
-
|
|
493
435
|
# Test the print functions
|
|
494
436
|
if __name__ == "__main__":
|
|
495
437
|
info("Hello", "World")
|
stouputils/print.pyi
CHANGED
|
@@ -134,13 +134,3 @@ def is_same_print(*args: Any, **kwargs: Any) -> bool:
|
|
|
134
134
|
""" Checks if the current print call is the same as the previous one. """
|
|
135
135
|
def current_time() -> str:
|
|
136
136
|
''' Get the current time as "HH:MM:SS" if less than 24 hours since import, else "YYYY-MM-DD HH:MM:SS" '''
|
|
137
|
-
def show_version(main_package: str = 'stouputils', primary_color: str = ..., secondary_color: str = ...) -> None:
|
|
138
|
-
''' Print the version of the main package and its dependencies.
|
|
139
|
-
|
|
140
|
-
\tUsed by the "stouputils --version" command.
|
|
141
|
-
|
|
142
|
-
\tArgs:
|
|
143
|
-
\t\tmain_package\t\t\t(str):\t\t\tName of the main package to show version for
|
|
144
|
-
\t\tprimary_color\t\t\t(str):\t\t\tColor to use for the primary package name
|
|
145
|
-
\t\tsecondary_color\t\t\t(str):\t\t\tColor to use for the secondary package names
|
|
146
|
-
\t'''
|
stouputils/py.typed
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
from ._deprecated import *
|
|
2
|
+
from .all_doctests import *
|
|
3
|
+
from .archive import *
|
|
4
|
+
from .backup import *
|
|
5
|
+
from .collections import *
|
|
6
|
+
from .continuous_delivery import *
|
|
7
|
+
from .ctx import *
|
|
8
|
+
from .decorators import *
|
|
9
|
+
from .image import *
|
|
10
|
+
from .io import *
|
|
11
|
+
from .parallel import *
|
|
12
|
+
from .print import *
|
|
13
|
+
from .version_pkg import *
|
|
14
|
+
|
|
15
|
+
__version__: str
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
from .decorators import LogLevels as LogLevels, deprecated as deprecated
|
|
2
|
+
from .io import csv_dump as csv_dump, csv_load as csv_load, json_dump as json_dump, json_load as json_load
|
|
3
|
+
from typing import Any
|
|
4
|
+
|
|
5
|
+
def super_csv_dump(*args: Any, **kwargs: Any) -> Any:
|
|
6
|
+
''' Deprecated function, use "csv_dump" instead. '''
|
|
7
|
+
def super_csv_load(*args: Any, **kwargs: Any) -> Any:
|
|
8
|
+
''' Deprecated function, use "csv_load" instead. '''
|
|
9
|
+
def super_json_dump(*args: Any, **kwargs: Any) -> Any:
|
|
10
|
+
''' Deprecated function, use "json_dump" instead. '''
|
|
11
|
+
def super_json_load(*args: Any, **kwargs: Any) -> Any:
|
|
12
|
+
''' Deprecated function, use "json_load" instead. '''
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
from . import decorators as decorators
|
|
2
|
+
from .decorators import measure_time as measure_time
|
|
3
|
+
from .io import clean_path as clean_path, relative_path as relative_path
|
|
4
|
+
from .print import error as error, info as info, progress as progress, warning as warning
|
|
5
|
+
from doctest import TestResults as TestResults
|
|
6
|
+
from types import ModuleType
|
|
7
|
+
|
|
8
|
+
def launch_tests(root_dir: str, strict: bool = True) -> int:
|
|
9
|
+
''' Main function to launch tests for all modules in the given directory.
|
|
10
|
+
|
|
11
|
+
\tArgs:
|
|
12
|
+
\t\troot_dir\t\t\t\t(str):\t\t\tRoot directory to search for modules
|
|
13
|
+
\t\tstrict\t\t\t\t\t(bool):\t\t\tModify the force_raise_exception variable to True in the decorators module
|
|
14
|
+
|
|
15
|
+
\tReturns:
|
|
16
|
+
\t\tint: The number of failed tests
|
|
17
|
+
|
|
18
|
+
\tExamples:
|
|
19
|
+
\t\t>>> launch_tests("unknown_dir")
|
|
20
|
+
\t\tTraceback (most recent call last):
|
|
21
|
+
\t\t\t...
|
|
22
|
+
\t\tValueError: No modules found in \'unknown_dir\'
|
|
23
|
+
|
|
24
|
+
\t.. code-block:: python
|
|
25
|
+
|
|
26
|
+
\t\t> if launch_tests("/path/to/source") > 0:
|
|
27
|
+
\t\t\tsys.exit(1)
|
|
28
|
+
\t\t[PROGRESS HH:MM:SS] Importing module \'module1\'\ttook 0.001s
|
|
29
|
+
\t\t[PROGRESS HH:MM:SS] Importing module \'module2\'\ttook 0.002s
|
|
30
|
+
\t\t[PROGRESS HH:MM:SS] Importing module \'module3\'\ttook 0.003s
|
|
31
|
+
\t\t[PROGRESS HH:MM:SS] Importing module \'module4\'\ttook 0.004s
|
|
32
|
+
\t\t[INFO HH:MM:SS] Testing 4 modules...
|
|
33
|
+
\t\t[PROGRESS HH:MM:SS] Testing module \'module1\'\ttook 0.005s
|
|
34
|
+
\t\t[PROGRESS HH:MM:SS] Testing module \'module2\'\ttook 0.006s
|
|
35
|
+
\t\t[PROGRESS HH:MM:SS] Testing module \'module3\'\ttook 0.007s
|
|
36
|
+
\t\t[PROGRESS HH:MM:SS] Testing module \'module4\'\ttook 0.008s
|
|
37
|
+
\t'''
|
|
38
|
+
def test_module_with_progress(module: ModuleType, separator: str) -> TestResults:
|
|
39
|
+
""" Test a module with testmod and measure the time taken with progress printing.
|
|
40
|
+
|
|
41
|
+
\tArgs:
|
|
42
|
+
\t\tmodule\t\t(ModuleType):\tModule to test
|
|
43
|
+
\t\tseparator\t(str):\t\t\tSeparator string for alignment in output
|
|
44
|
+
\tReturns:
|
|
45
|
+
\t\tTestResults: The results of the tests
|
|
46
|
+
\t"""
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
from ..continuous_delivery import version_to_float as version_to_float
|
|
2
|
+
from ..decorators import LogLevels as LogLevels, handle_error as handle_error, simple_cache as simple_cache
|
|
3
|
+
from ..io import clean_path as clean_path, json_dump as json_dump, super_open as super_open
|
|
4
|
+
from ..print import info as info
|
|
5
|
+
from collections.abc import Callable as Callable
|
|
6
|
+
|
|
7
|
+
REQUIREMENTS: list[str]
|
|
8
|
+
|
|
9
|
+
def check_dependencies(html_theme: str) -> None:
|
|
10
|
+
''' Check for each requirement if it is installed.
|
|
11
|
+
|
|
12
|
+
\tArgs:
|
|
13
|
+
\t\thtml_theme (str): HTML theme to use for the documentation, to check if it is installed (e.g. "breeze", "pydata_sphinx_theme", "furo", etc.)
|
|
14
|
+
\t'''
|
|
15
|
+
def get_sphinx_conf_content(project: str, project_dir: str, author: str, current_version: str, copyright: str, html_logo: str, html_favicon: str, html_theme: str = 'breeze', github_user: str = '', github_repo: str = '', version_list: list[str] | None = None, skip_undocumented: bool = True) -> str:
|
|
16
|
+
""" Get the content of the Sphinx configuration file.
|
|
17
|
+
|
|
18
|
+
\tArgs:
|
|
19
|
+
\t\tproject (str): Name of the project
|
|
20
|
+
\t\tproject_dir (str): Path to the project directory
|
|
21
|
+
\t\tauthor (str): Author of the project
|
|
22
|
+
\t\tcurrent_version (str): Current version
|
|
23
|
+
\t\tcopyright (str): Copyright information
|
|
24
|
+
\t\thtml_logo (str): URL to the logo
|
|
25
|
+
\t\thtml_favicon (str): URL to the favicon
|
|
26
|
+
\t\tgithub_user (str): GitHub username
|
|
27
|
+
\t\tgithub_repo (str): GitHub repository name
|
|
28
|
+
\t\tversion_list (list[str] | None): List of versions. Defaults to None
|
|
29
|
+
\t\tskip_undocumented (bool): Whether to skip undocumented members. Defaults to True
|
|
30
|
+
|
|
31
|
+
\tReturns:
|
|
32
|
+
\t\tstr: Content of the Sphinx configuration file
|
|
33
|
+
\t"""
|
|
34
|
+
def get_versions_from_github(github_user: str, github_repo: str, recent_minor_versions: int = 2) -> list[str]:
|
|
35
|
+
""" Get list of versions from GitHub gh-pages branch.
|
|
36
|
+
\tOnly shows detailed versions for the last N minor versions, and keeps only
|
|
37
|
+
\tthe latest patch version for older minor versions.
|
|
38
|
+
|
|
39
|
+
\tArgs:
|
|
40
|
+
\t\tgithub_user (str): GitHub username
|
|
41
|
+
\t\tgithub_repo (str): GitHub repository name
|
|
42
|
+
\t\trecent_minor_versions (int): Number of recent minor versions to show all patches for (-1 for all).
|
|
43
|
+
|
|
44
|
+
\tReturns:
|
|
45
|
+
\t\tlist[str]: List of versions, with 'latest' as first element
|
|
46
|
+
\t"""
|
|
47
|
+
def markdown_to_rst(markdown_content: str) -> str:
|
|
48
|
+
""" Convert markdown content to RST format.
|
|
49
|
+
|
|
50
|
+
\tArgs:
|
|
51
|
+
\t\tmarkdown_content (str): Markdown content
|
|
52
|
+
|
|
53
|
+
\tReturns:
|
|
54
|
+
\t\tstr: RST content
|
|
55
|
+
\t"""
|
|
56
|
+
def generate_index_rst(readme_path: str, index_path: str, project: str, github_user: str, github_repo: str, get_versions_function: Callable[[str, str, int], list[str]] = ..., recent_minor_versions: int = 2) -> None:
|
|
57
|
+
""" Generate index.rst from README.md content.
|
|
58
|
+
|
|
59
|
+
\tArgs:
|
|
60
|
+
\t\treadme_path (str): Path to the README.md file
|
|
61
|
+
\t\tindex_path (str): Path where index.rst should be created
|
|
62
|
+
\t\tproject (str): Name of the project
|
|
63
|
+
\t\tgithub_user (str): GitHub username
|
|
64
|
+
\t\tgithub_repo (str): GitHub repository name
|
|
65
|
+
\t\tget_versions_function (Callable[[str, str, int], list[str]]): Function to get versions from GitHub
|
|
66
|
+
\t\trecent_minor_versions (int): Number of recent minor versions to show all patches for. Defaults to 2
|
|
67
|
+
\t"""
|
|
68
|
+
def generate_documentation(source_dir: str, modules_dir: str, project_dir: str, build_dir: str) -> None:
|
|
69
|
+
""" Generate documentation using Sphinx.
|
|
70
|
+
|
|
71
|
+
\tArgs:
|
|
72
|
+
\t\tsource_dir (str): Source directory
|
|
73
|
+
\t\tmodules_dir (str): Modules directory
|
|
74
|
+
\t\tproject_dir (str): Project directory
|
|
75
|
+
\t\tbuild_dir (str): Build directory
|
|
76
|
+
\t"""
|
|
77
|
+
def generate_redirect_html(filepath: str) -> None:
|
|
78
|
+
""" Generate HTML content for redirect page.
|
|
79
|
+
|
|
80
|
+
\tArgs:
|
|
81
|
+
\t\tfilepath (str): Path to the file where the HTML content should be written
|
|
82
|
+
\t"""
|
|
83
|
+
def update_documentation(root_path: str, project: str, project_dir: str = '', author: str = 'Author', copyright: str = '2025, Author', html_logo: str = '', html_favicon: str = '', html_theme: str = 'breeze', github_user: str = '', github_repo: str = '', version: str | None = None, skip_undocumented: bool = True, recent_minor_versions: int = 2, get_versions_function: Callable[[str, str, int], list[str]] = ..., generate_index_function: Callable[..., None] = ..., generate_docs_function: Callable[..., None] = ..., generate_redirect_function: Callable[[str], None] = ..., get_conf_content_function: Callable[..., str] = ...) -> None:
|
|
84
|
+
''' Update the Sphinx documentation.
|
|
85
|
+
|
|
86
|
+
\tArgs:
|
|
87
|
+
\t\troot_path (str): Root path of the project
|
|
88
|
+
\t\tproject (str): Name of the project
|
|
89
|
+
\t\tproject_dir (str): Path to the project directory (to be used with generate_docs_function)
|
|
90
|
+
\t\tauthor (str): Author of the project
|
|
91
|
+
\t\tcopyright (str): Copyright information
|
|
92
|
+
\t\thtml_logo (str): URL to the logo
|
|
93
|
+
\t\thtml_favicon (str): URL to the favicon
|
|
94
|
+
\t\thtml_theme (str): Theme to use for the documentation. Defaults to "breeze"
|
|
95
|
+
\t\tgithub_user (str): GitHub username
|
|
96
|
+
\t\tgithub_repo (str): GitHub repository name
|
|
97
|
+
\t\tversion (str | None): Version to build documentation for (e.g. "1.0.0", defaults to "latest")
|
|
98
|
+
\t\tskip_undocumented (bool): Whether to skip undocumented members. Defaults to True
|
|
99
|
+
\t\trecent_minor_versions (int): Number of recent minor versions to show all patches for. Defaults to 2
|
|
100
|
+
|
|
101
|
+
\t\tget_versions_function (Callable[[str, str, int], list[str]]): Function to get versions from GitHub
|
|
102
|
+
\t\tgenerate_index_function (Callable[..., None]): Function to generate index.rst
|
|
103
|
+
\t\tgenerate_docs_function (Callable[..., None]): Function to generate documentation
|
|
104
|
+
\t\tgenerate_redirect_function (Callable[[str], None]): Function to create redirect file
|
|
105
|
+
\t\tget_conf_content_function (Callable[..., str]): Function to get Sphinx conf.py content
|
|
106
|
+
\t'''
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
WAIFU2X_NCNN_VULKAN_RELEASES: dict[str, str]
|
|
2
|
+
FFMPEG_RELEASES: dict[str, str]
|
|
3
|
+
YOUTUBE_BITRATE_RECOMMENDATIONS: dict[str, dict[str, dict[int, int]]]
|
|
4
|
+
|
|
5
|
+
class Config:
|
|
6
|
+
""" Configuration class for the upscaler. """
|
|
7
|
+
JPG_QUALITY: int
|
|
8
|
+
VIDEO_FINAL_BITRATE: int
|
|
9
|
+
FFMPEG_EXECUTABLE: str
|
|
10
|
+
FFMPEG_ARGS: tuple[str, ...]
|
|
11
|
+
FFPROBE_EXECUTABLE: str
|
|
12
|
+
FFMPEG_CHECK_HELP_TEXT: str
|
|
13
|
+
UPSCALER_EXECUTABLE: str
|
|
14
|
+
UPSCALER_ARGS: tuple[str, ...]
|
|
15
|
+
UPSCALER_EXECUTABLE_HELP_TEXT: str
|
|
16
|
+
SLIGHTLY_FASTER_MODE: bool
|
|
17
|
+
upscaler_executable_checked: bool
|
|
18
|
+
ffmpeg_executable_checked: bool
|