stouputils 1.12.2__py3-none-any.whl → 1.13.1__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/__main__.py +11 -6
- 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/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-1.12.2.dist-info → stouputils-1.13.1.dist-info}/METADATA +2 -2
- {stouputils-1.12.2.dist-info → stouputils-1.13.1.dist-info}/RECORD +47 -16
- {stouputils-1.12.2.dist-info → stouputils-1.13.1.dist-info}/WHEEL +0 -0
- {stouputils-1.12.2.dist-info → stouputils-1.13.1.dist-info}/entry_points.txt +0 -0
stouputils/installer/linux.py
CHANGED
|
@@ -1,144 +1,144 @@
|
|
|
1
|
-
""" Installer module for Linux/macOS specific functions.
|
|
2
|
-
|
|
3
|
-
Provides Linux/macOS specific implementations for checking admin privileges,
|
|
4
|
-
determining appropriate installation paths (global/local), and suggesting
|
|
5
|
-
how to add directories to the system'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 suggest how to add to PATH (Linux)", error_log=LogLevels.WARNING_TRACEBACK)
|
|
18
|
-
def add_to_path_linux(install_path: str) -> bool:
|
|
19
|
-
""" Suggest how to add install_path to PATH on Linux.
|
|
20
|
-
|
|
21
|
-
Checks the current shell and provides instructions for adding the path
|
|
22
|
-
to the appropriate configuration file (e.g., .bashrc, .zshrc, config.fish).
|
|
23
|
-
|
|
24
|
-
Args:
|
|
25
|
-
install_path (str): The path to add to the PATH environment variable.
|
|
26
|
-
|
|
27
|
-
Returns:
|
|
28
|
-
bool: True if instructions were provided, False otherwise (e.g., unknown shell).
|
|
29
|
-
"""
|
|
30
|
-
shell_config_files: dict[str, str] = {
|
|
31
|
-
"bash": "~/.bashrc",
|
|
32
|
-
"zsh": "~/.zshrc",
|
|
33
|
-
"fish": "~/.config/fish/config.fish"
|
|
34
|
-
}
|
|
35
|
-
current_shell: str = os.environ.get("SHELL", "").split('/')[-1]
|
|
36
|
-
config_file: str | None = shell_config_files.get(current_shell)
|
|
37
|
-
|
|
38
|
-
if config_file:
|
|
39
|
-
export_cmd: str = ""
|
|
40
|
-
if current_shell == "fish":
|
|
41
|
-
export_cmd = f"set -gx PATH $PATH {install_path}"
|
|
42
|
-
else:
|
|
43
|
-
export_cmd = f"export PATH=\"$PATH:{install_path}\"" # Escape quotes for print
|
|
44
|
-
|
|
45
|
-
debug(
|
|
46
|
-
f"To add the installation directory to your PATH, add the following line to your '{config_file}':\n"
|
|
47
|
-
f" {export_cmd}\n"
|
|
48
|
-
f"Then restart your shell or run 'source {config_file}'."
|
|
49
|
-
)
|
|
50
|
-
return True
|
|
51
|
-
else:
|
|
52
|
-
warning(f"Could not determine your shell configuration file. Please add '{install_path}' to your PATH manually.")
|
|
53
|
-
return False
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
def check_admin_linux() -> bool:
|
|
57
|
-
""" Check if the script is running with root privileges on Linux/macOS.
|
|
58
|
-
|
|
59
|
-
Returns:
|
|
60
|
-
bool: True if the effective user ID is 0 (root), False otherwise.
|
|
61
|
-
"""
|
|
62
|
-
try:
|
|
63
|
-
return os.geteuid() == 0 # type: ignore
|
|
64
|
-
except AttributeError as e:
|
|
65
|
-
# os.geteuid() is not available on all platforms (e.g., Windows)
|
|
66
|
-
# This function should ideally only be called on Linux/macOS.
|
|
67
|
-
warning(f"Could not determine user privileges on this platform: {e}")
|
|
68
|
-
return False
|
|
69
|
-
except Exception as e:
|
|
70
|
-
warning(f"Error checking admin privileges: {e}")
|
|
71
|
-
return False
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
@handle_error(message="Failed to get installation path (Linux)", error_log=LogLevels.ERROR_TRACEBACK)
|
|
75
|
-
def get_install_path_linux(
|
|
76
|
-
program_name: str,
|
|
77
|
-
ask_global: int = 0,
|
|
78
|
-
add_path: bool = True,
|
|
79
|
-
append_to_path: str = "",
|
|
80
|
-
default_global: str = "/usr/local/bin",
|
|
81
|
-
) -> str:
|
|
82
|
-
""" Get the installation path for the program on Linux/macOS.
|
|
83
|
-
|
|
84
|
-
Args:
|
|
85
|
-
program_name (str): The name of the program to install.
|
|
86
|
-
ask_global (int): 0 = ask for anything, 1 = install globally, 2 = install locally
|
|
87
|
-
add_path (bool): Whether to add the program to the PATH environment variable. (Only if installed globally)
|
|
88
|
-
append_to_path (str): String to append to the installation path when adding to PATH.
|
|
89
|
-
(ex: "bin" if executables are in the bin folder)
|
|
90
|
-
default_global (str): The default global installation path.
|
|
91
|
-
(Default is "/usr/local/bin" which is the most common location for executables on Linux/macOS,
|
|
92
|
-
could be "/opt" or any other directory)
|
|
93
|
-
|
|
94
|
-
Returns:
|
|
95
|
-
str: The chosen installation path, or an empty string if installation is cancelled.
|
|
96
|
-
"""
|
|
97
|
-
# Default paths
|
|
98
|
-
default_local_path: str = clean_path(os.path.join(os.getcwd(), program_name))
|
|
99
|
-
|
|
100
|
-
# Common global locations: /usr/local/bin for executables, /opt/ for self-contained apps
|
|
101
|
-
# We assume 'program_name' might be an executable or a directory, /usr/local/ is safer
|
|
102
|
-
default_global_path: str = clean_path(f"{default_global}/{program_name}") # Or potentially /opt/{program_name}
|
|
103
|
-
|
|
104
|
-
# Ask user for installation type (global/local)
|
|
105
|
-
install_type: str = ask_install_type(ask_global, default_local_path, default_global_path)
|
|
106
|
-
|
|
107
|
-
# Handle global installation choice
|
|
108
|
-
if install_type == 'g':
|
|
109
|
-
if not check_admin_linux():
|
|
110
|
-
warning(
|
|
111
|
-
f"Global installation typically requires sudo privileges to write to "
|
|
112
|
-
f"'{os.path.dirname(default_global_path)}'.\n"
|
|
113
|
-
f"You may need to re-run the script with 'sudo'.\n"
|
|
114
|
-
f"Install locally instead to '{default_local_path}'? (Y/n): "
|
|
115
|
-
)
|
|
116
|
-
if input().lower() == 'n':
|
|
117
|
-
info("Installation cancelled.")
|
|
118
|
-
return ""
|
|
119
|
-
else:
|
|
120
|
-
# Fallback to local path if user agrees
|
|
121
|
-
return prompt_for_path(
|
|
122
|
-
f"Falling back to local installation path: {default_local_path}.",
|
|
123
|
-
default_local_path
|
|
124
|
-
)
|
|
125
|
-
else:
|
|
126
|
-
# User is admin or proceeding with global install anyway
|
|
127
|
-
install_path: str = prompt_for_path(
|
|
128
|
-
f"Default global installation path is {default_global_path}.",
|
|
129
|
-
default_global_path
|
|
130
|
-
)
|
|
131
|
-
if add_path:
|
|
132
|
-
# Suggest adding the *directory* containing the program to PATH,
|
|
133
|
-
# or the path itself if it seems like a directory install
|
|
134
|
-
path_to_add: str = os.path.dirname(install_path) if os.path.isfile(install_path) else install_path
|
|
135
|
-
add_to_path_linux(os.path.join(path_to_add, append_to_path))
|
|
136
|
-
return install_path
|
|
137
|
-
|
|
138
|
-
# Handle local installation choice
|
|
139
|
-
else: # install_type == 'l'
|
|
140
|
-
return prompt_for_path(
|
|
141
|
-
f"Default local installation path is {default_local_path}.",
|
|
142
|
-
default_local_path
|
|
143
|
-
)
|
|
144
|
-
|
|
1
|
+
""" Installer module for Linux/macOS specific functions.
|
|
2
|
+
|
|
3
|
+
Provides Linux/macOS specific implementations for checking admin privileges,
|
|
4
|
+
determining appropriate installation paths (global/local), and suggesting
|
|
5
|
+
how to add directories to the system'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 suggest how to add to PATH (Linux)", error_log=LogLevels.WARNING_TRACEBACK)
|
|
18
|
+
def add_to_path_linux(install_path: str) -> bool:
|
|
19
|
+
""" Suggest how to add install_path to PATH on Linux.
|
|
20
|
+
|
|
21
|
+
Checks the current shell and provides instructions for adding the path
|
|
22
|
+
to the appropriate configuration file (e.g., .bashrc, .zshrc, config.fish).
|
|
23
|
+
|
|
24
|
+
Args:
|
|
25
|
+
install_path (str): The path to add to the PATH environment variable.
|
|
26
|
+
|
|
27
|
+
Returns:
|
|
28
|
+
bool: True if instructions were provided, False otherwise (e.g., unknown shell).
|
|
29
|
+
"""
|
|
30
|
+
shell_config_files: dict[str, str] = {
|
|
31
|
+
"bash": "~/.bashrc",
|
|
32
|
+
"zsh": "~/.zshrc",
|
|
33
|
+
"fish": "~/.config/fish/config.fish"
|
|
34
|
+
}
|
|
35
|
+
current_shell: str = os.environ.get("SHELL", "").split('/')[-1]
|
|
36
|
+
config_file: str | None = shell_config_files.get(current_shell)
|
|
37
|
+
|
|
38
|
+
if config_file:
|
|
39
|
+
export_cmd: str = ""
|
|
40
|
+
if current_shell == "fish":
|
|
41
|
+
export_cmd = f"set -gx PATH $PATH {install_path}"
|
|
42
|
+
else:
|
|
43
|
+
export_cmd = f"export PATH=\"$PATH:{install_path}\"" # Escape quotes for print
|
|
44
|
+
|
|
45
|
+
debug(
|
|
46
|
+
f"To add the installation directory to your PATH, add the following line to your '{config_file}':\n"
|
|
47
|
+
f" {export_cmd}\n"
|
|
48
|
+
f"Then restart your shell or run 'source {config_file}'."
|
|
49
|
+
)
|
|
50
|
+
return True
|
|
51
|
+
else:
|
|
52
|
+
warning(f"Could not determine your shell configuration file. Please add '{install_path}' to your PATH manually.")
|
|
53
|
+
return False
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def check_admin_linux() -> bool:
|
|
57
|
+
""" Check if the script is running with root privileges on Linux/macOS.
|
|
58
|
+
|
|
59
|
+
Returns:
|
|
60
|
+
bool: True if the effective user ID is 0 (root), False otherwise.
|
|
61
|
+
"""
|
|
62
|
+
try:
|
|
63
|
+
return os.geteuid() == 0 # type: ignore
|
|
64
|
+
except AttributeError as e:
|
|
65
|
+
# os.geteuid() is not available on all platforms (e.g., Windows)
|
|
66
|
+
# This function should ideally only be called on Linux/macOS.
|
|
67
|
+
warning(f"Could not determine user privileges on this platform: {e}")
|
|
68
|
+
return False
|
|
69
|
+
except Exception as e:
|
|
70
|
+
warning(f"Error checking admin privileges: {e}")
|
|
71
|
+
return False
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
@handle_error(message="Failed to get installation path (Linux)", error_log=LogLevels.ERROR_TRACEBACK)
|
|
75
|
+
def get_install_path_linux(
|
|
76
|
+
program_name: str,
|
|
77
|
+
ask_global: int = 0,
|
|
78
|
+
add_path: bool = True,
|
|
79
|
+
append_to_path: str = "",
|
|
80
|
+
default_global: str = "/usr/local/bin",
|
|
81
|
+
) -> str:
|
|
82
|
+
""" Get the installation path for the program on Linux/macOS.
|
|
83
|
+
|
|
84
|
+
Args:
|
|
85
|
+
program_name (str): The name of the program to install.
|
|
86
|
+
ask_global (int): 0 = ask for anything, 1 = install globally, 2 = install locally
|
|
87
|
+
add_path (bool): Whether to add the program to the PATH environment variable. (Only if installed globally)
|
|
88
|
+
append_to_path (str): String to append to the installation path when adding to PATH.
|
|
89
|
+
(ex: "bin" if executables are in the bin folder)
|
|
90
|
+
default_global (str): The default global installation path.
|
|
91
|
+
(Default is "/usr/local/bin" which is the most common location for executables on Linux/macOS,
|
|
92
|
+
could be "/opt" or any other directory)
|
|
93
|
+
|
|
94
|
+
Returns:
|
|
95
|
+
str: The chosen installation path, or an empty string if installation is cancelled.
|
|
96
|
+
"""
|
|
97
|
+
# Default paths
|
|
98
|
+
default_local_path: str = clean_path(os.path.join(os.getcwd(), program_name))
|
|
99
|
+
|
|
100
|
+
# Common global locations: /usr/local/bin for executables, /opt/ for self-contained apps
|
|
101
|
+
# We assume 'program_name' might be an executable or a directory, /usr/local/ is safer
|
|
102
|
+
default_global_path: str = clean_path(f"{default_global}/{program_name}") # Or potentially /opt/{program_name}
|
|
103
|
+
|
|
104
|
+
# Ask user for installation type (global/local)
|
|
105
|
+
install_type: str = ask_install_type(ask_global, default_local_path, default_global_path)
|
|
106
|
+
|
|
107
|
+
# Handle global installation choice
|
|
108
|
+
if install_type == 'g':
|
|
109
|
+
if not check_admin_linux():
|
|
110
|
+
warning(
|
|
111
|
+
f"Global installation typically requires sudo privileges to write to "
|
|
112
|
+
f"'{os.path.dirname(default_global_path)}'.\n"
|
|
113
|
+
f"You may need to re-run the script with 'sudo'.\n"
|
|
114
|
+
f"Install locally instead to '{default_local_path}'? (Y/n): "
|
|
115
|
+
)
|
|
116
|
+
if input().lower() == 'n':
|
|
117
|
+
info("Installation cancelled.")
|
|
118
|
+
return ""
|
|
119
|
+
else:
|
|
120
|
+
# Fallback to local path if user agrees
|
|
121
|
+
return prompt_for_path(
|
|
122
|
+
f"Falling back to local installation path: {default_local_path}.",
|
|
123
|
+
default_local_path
|
|
124
|
+
)
|
|
125
|
+
else:
|
|
126
|
+
# User is admin or proceeding with global install anyway
|
|
127
|
+
install_path: str = prompt_for_path(
|
|
128
|
+
f"Default global installation path is {default_global_path}.",
|
|
129
|
+
default_global_path
|
|
130
|
+
)
|
|
131
|
+
if add_path:
|
|
132
|
+
# Suggest adding the *directory* containing the program to PATH,
|
|
133
|
+
# or the path itself if it seems like a directory install
|
|
134
|
+
path_to_add: str = os.path.dirname(install_path) if os.path.isfile(install_path) else install_path
|
|
135
|
+
add_to_path_linux(os.path.join(path_to_add, append_to_path))
|
|
136
|
+
return install_path
|
|
137
|
+
|
|
138
|
+
# Handle local installation choice
|
|
139
|
+
else: # install_type == 'l'
|
|
140
|
+
return prompt_for_path(
|
|
141
|
+
f"Default local installation path is {default_local_path}.",
|
|
142
|
+
default_local_path
|
|
143
|
+
)
|
|
144
|
+
|