machineconfig 1.8__py3-none-any.whl → 1.9__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.
Potentially problematic release.
This version of machineconfig might be problematic. Click here for more details.
- machineconfig/__init__.py +4 -2
- machineconfig/jobs/python/check_installations.py +1 -1
- machineconfig/jobs/python_custom_installers/azuredatastudio.py +36 -0
- machineconfig/jobs/{script_installer → python_custom_installers}/bypass_paywall.py +8 -1
- machineconfig/jobs/{script_installer → python_custom_installers}/docker_desktop.py +14 -3
- machineconfig/jobs/python_custom_installers/gh.py +53 -0
- machineconfig/jobs/python_custom_installers/goes.py +35 -0
- machineconfig/jobs/python_custom_installers/helix.py +43 -0
- machineconfig/jobs/python_custom_installers/lvim.py +48 -0
- machineconfig/jobs/{script_installer → python_custom_installers}/ngrok.py +11 -1
- machineconfig/jobs/python_custom_installers/nvim.py +48 -0
- machineconfig/jobs/{script_installer/code.py → python_custom_installers/vscode.py} +11 -0
- machineconfig/jobs/python_custom_installers/wezterm.py +41 -0
- machineconfig/profile/create.py +4 -1
- machineconfig/scripts/python/choose_wezterm_theme.py +96 -0
- machineconfig/scripts/python/cloud_copy.py +5 -1
- machineconfig/scripts/python/cloud_mount.py +20 -10
- machineconfig/scripts/python/cloud_repo_sync.py +30 -22
- machineconfig/scripts/python/cloud_sync.py +4 -6
- machineconfig/scripts/python/croshell.py +17 -8
- machineconfig/scripts/python/devops_devapps_install.py +12 -6
- machineconfig/scripts/python/fire_jobs.py +92 -53
- machineconfig/scripts/python/ftpx.py +17 -7
- machineconfig/scripts/python/repos.py +5 -1
- machineconfig/scripts/python/start_terminals.py +1 -1
- machineconfig/utils/installer.py +98 -30
- machineconfig/utils/utils.py +6 -4
- machineconfig/utils/ve.py +37 -16
- machineconfig-1.9.dist-info/LICENSE +201 -0
- {machineconfig-1.8.dist-info → machineconfig-1.9.dist-info}/METADATA +155 -140
- {machineconfig-1.8.dist-info → machineconfig-1.9.dist-info}/RECORD +34 -28
- {machineconfig-1.8.dist-info → machineconfig-1.9.dist-info}/WHEEL +1 -1
- machineconfig/jobs/script_installer/azure_data_studio.py +0 -22
- machineconfig/jobs/script_installer/skim.py +0 -21
- machineconfig/jobs/script_installer/wezterm.py +0 -34
- /machineconfig/jobs/{script_installer → python_custom_installers}/__init__.py +0 -0
- {machineconfig-1.8.dist-info → machineconfig-1.9.dist-info}/top_level.txt +0 -0
machineconfig/utils/installer.py
CHANGED
|
@@ -13,7 +13,12 @@ import platform
|
|
|
13
13
|
# import os
|
|
14
14
|
|
|
15
15
|
|
|
16
|
+
LINUX_INSTALL_PATH = '/usr/local/bin'
|
|
17
|
+
WINDOWS_INSTALL_PATH = '~/AppData/Local/Microsoft/WindowsApps'
|
|
18
|
+
|
|
19
|
+
|
|
16
20
|
def find_move_delete_windows(downloaded_file_path: P, exe_name: Optional[str] = None, delete: bool = True, rename_to: Optional[str] = None):
|
|
21
|
+
"""Moves executable to {WINDOWS_INSTALL_PATH}"""
|
|
17
22
|
if exe_name is not None and ".exe" in exe_name: exe_name = exe_name.replace(".exe", "")
|
|
18
23
|
if downloaded_file_path.is_file():
|
|
19
24
|
exe = downloaded_file_path
|
|
@@ -22,10 +27,14 @@ def find_move_delete_windows(downloaded_file_path: P, exe_name: Optional[str] =
|
|
|
22
27
|
else:
|
|
23
28
|
tmp = downloaded_file_path.search(f"{exe_name}.exe", r=True)
|
|
24
29
|
if len(tmp) == 1: exe = tmp.list[0]
|
|
25
|
-
else:
|
|
30
|
+
else:
|
|
31
|
+
search_res = downloaded_file_path.search("*.exe", r=True)
|
|
32
|
+
if len(search_res) == 0: raise IndexError(f"No executable found in {downloaded_file_path}")
|
|
33
|
+
elif len(search_res) == 1: exe = search_res.list[0]
|
|
34
|
+
else: exe = search_res.sort(lambda x: x.size("kb")).list[-1]
|
|
26
35
|
if rename_to and exe.name != rename_to:
|
|
27
36
|
exe = exe.with_name(name=rename_to, inplace=True)
|
|
28
|
-
exe_new_location = exe.move(folder=
|
|
37
|
+
exe_new_location = exe.move(folder=WINDOWS_INSTALL_PATH, overwrite=True) # latest version overwrites older installation.
|
|
29
38
|
if delete: downloaded_file_path.delete(sure=True)
|
|
30
39
|
return exe_new_location
|
|
31
40
|
|
|
@@ -41,16 +50,18 @@ def find_move_delete_linux(downloaded: P, tool_name: str, delete: Optional[bool]
|
|
|
41
50
|
if len(exe_search_res) == 0:
|
|
42
51
|
print(f"No search results for `{tool_name}` in `{downloaded}`")
|
|
43
52
|
raise IndexError(f"No executable found in {downloaded}")
|
|
44
|
-
|
|
53
|
+
elif len(exe_search_res) == 1:
|
|
45
54
|
exe = exe_search_res.list[0]
|
|
55
|
+
else:
|
|
56
|
+
exe = exe_search_res.sort(lambda x: x.size("kb")).list[-1]
|
|
46
57
|
if rename_to and exe.name != rename_to:
|
|
47
58
|
exe = exe.with_name(name=rename_to, inplace=True)
|
|
48
|
-
print(f"MOVING file `{repr(exe)}` to '
|
|
59
|
+
print(f"MOVING file `{repr(exe)}` to '{LINUX_INSTALL_PATH}'")
|
|
49
60
|
exe.chmod(0o777)
|
|
50
|
-
# exe.move(folder=
|
|
51
|
-
Terminal().run(f"sudo mv {exe} /
|
|
61
|
+
# exe.move(folder=LINUX_INSTALL_PATH, overwrite=False)
|
|
62
|
+
Terminal().run(f"sudo mv {exe} {LINUX_INSTALL_PATH}/").print_if_unsuccessful(desc=f"MOVING executable `{exe}` to {LINUX_INSTALL_PATH}", strict_err=True, strict_returncode=True)
|
|
52
63
|
if delete: downloaded.delete(sure=True)
|
|
53
|
-
exe_new_location = P(
|
|
64
|
+
exe_new_location = P(LINUX_INSTALL_PATH).joinpath(exe.name)
|
|
54
65
|
return exe_new_location
|
|
55
66
|
|
|
56
67
|
|
|
@@ -67,7 +78,7 @@ class Installer:
|
|
|
67
78
|
def get_description(self):
|
|
68
79
|
# old_version_cli = Terminal().run(f"{self.exe_name} --version").op.replace("\n", "")
|
|
69
80
|
# old_version_cli = os.system(f"{self.exe_name} --version").replace("\n", "")
|
|
70
|
-
old_version_cli = check_tool_exists(self.exe_name)
|
|
81
|
+
old_version_cli = check_tool_exists(tool_name=self.exe_name)
|
|
71
82
|
old_version_cli_str = "✅" if old_version_cli else "❌"
|
|
72
83
|
# name_version = f"{self.exe_name} {old_version_cli_str}"
|
|
73
84
|
return f"{self.exe_name:<12} {old_version_cli_str} {self.doc}"
|
|
@@ -83,10 +94,11 @@ class Installer:
|
|
|
83
94
|
from machineconfig.utils.utils import choose_one_option
|
|
84
95
|
path = choose_one_option(options=LIBRARY_ROOT.joinpath("jobs").search("config.json", r=True).list)
|
|
85
96
|
config: dict[str, Any] = Read.json(path) # /python_generic_installers/config.json"))
|
|
86
|
-
|
|
87
|
-
for keys, dict_ in config.items():
|
|
88
|
-
|
|
89
|
-
|
|
97
|
+
app_name = choose_one_option(options=list(config.keys()), fzf=True)
|
|
98
|
+
# for keys, dict_ in config.items():
|
|
99
|
+
installer = Installer.from_dict(d=config[app_name], name=app_name)
|
|
100
|
+
version = input(f"Enter version to install for {installer.exe_name} [latest]: ") or None
|
|
101
|
+
installer.install(version=version)
|
|
90
102
|
|
|
91
103
|
def install_robust(self, version: Optional[str]):
|
|
92
104
|
try:
|
|
@@ -101,11 +113,13 @@ class Installer:
|
|
|
101
113
|
|
|
102
114
|
def install(self, version: Optional[str]):
|
|
103
115
|
if self.repo_url == "CUSTOM":
|
|
104
|
-
import machineconfig.jobs.
|
|
105
|
-
installer_path = P(
|
|
116
|
+
import machineconfig.jobs.python_custom_installers as python_custom_installers
|
|
117
|
+
installer_path = P(python_custom_installers.__file__).parent.joinpath(self.exe_name + ".py")
|
|
106
118
|
import runpy
|
|
107
|
-
program = runpy.run_path(str(installer_path), run_name=
|
|
108
|
-
Terminal().
|
|
119
|
+
program = runpy.run_path(str(installer_path), run_name=None)['main'](version=version)
|
|
120
|
+
Terminal().run_script(script=program, shell="default").print(desc="Running custom installer", capture=True)
|
|
121
|
+
# import subprocess
|
|
122
|
+
# subprocess.run(program, shell=True, check=True)
|
|
109
123
|
version_to_be_installed = str(version)
|
|
110
124
|
elif "npm " in self.repo_url:
|
|
111
125
|
Terminal().run(self.repo_url, shell="default").print_if_unsuccessful(desc="npm install", strict_err=True, strict_returncode=True)
|
|
@@ -158,7 +172,7 @@ class Installer:
|
|
|
158
172
|
else: raise NotImplementedError(f"📦️ System {platform.system()} not implemented")
|
|
159
173
|
print(f"📦️ File name", file_name)
|
|
160
174
|
download_link = release_url.joinpath(file_name)
|
|
161
|
-
print("📦️ Downloading: ", download_link.as_url_str())
|
|
175
|
+
print(f"📦️ Downloading {self.name}: ", download_link.as_url_str())
|
|
162
176
|
downloaded = download_link.download(folder=INSTALL_TMP_DIR).decompress()
|
|
163
177
|
return downloaded, version_to_be_installed
|
|
164
178
|
|
|
@@ -168,6 +182,7 @@ class Installer:
|
|
|
168
182
|
print(f"📦️ Inspecting latest release @ {repo_url} ...")
|
|
169
183
|
# with console.status("Installing..."): # makes troubles on linux when prompt asks for password to move file to /usr/bin
|
|
170
184
|
if version is None:
|
|
185
|
+
# see this: https://api.github.com/repos/cointop-sh/cointop/releases/latest
|
|
171
186
|
import requests # https://docs.github.com/en/repositories/releasing-projects-on-github/linking-to-releases
|
|
172
187
|
_latest_version = requests.get(str(repo_url) + "/releases/latest", timeout=10).url.split("/")[-1] # this is to resolve the redirection that occures: https://stackoverflow.com/questions/36070821/how-to-get-redirect-url-using-python-requests
|
|
173
188
|
version_to_be_installed = _latest_version
|
|
@@ -178,29 +193,69 @@ class Installer:
|
|
|
178
193
|
return release_url, version_to_be_installed
|
|
179
194
|
|
|
180
195
|
@staticmethod
|
|
181
|
-
def check_if_installed_already(exe_name: str, version: str):
|
|
196
|
+
def check_if_installed_already(exe_name: str, version: str, use_cache: bool):
|
|
182
197
|
version_to_be_installed = version
|
|
183
198
|
tmp_path = INSTALL_VERSION_ROOT.joinpath(exe_name).create(parents_only=True)
|
|
184
|
-
|
|
185
|
-
|
|
199
|
+
|
|
200
|
+
if use_cache:
|
|
201
|
+
if tmp_path.exists(): existing_version = tmp_path.read_text().rstrip()
|
|
202
|
+
else: existing_version = None
|
|
203
|
+
else:
|
|
204
|
+
# check_tool_exists(tool_name=exe_name)
|
|
205
|
+
# raise NotImplementedError("Not implemented")
|
|
206
|
+
# import subprocess
|
|
207
|
+
# try:
|
|
208
|
+
# existing_version = subprocess.check_output([exe_name, "--version"], text=True)
|
|
209
|
+
# existing_version = existing_version.strip()
|
|
210
|
+
# except (subprocess.CalledProcessError, FileNotFoundError):
|
|
211
|
+
# print(f"Failed to get version of {exe_name}")
|
|
212
|
+
# existing_version = None
|
|
213
|
+
resp = Terminal().run(exe_name, "--version", check=False).capture()
|
|
214
|
+
if resp.op == '': existing_version = None
|
|
215
|
+
else: existing_version = resp.op.strip()
|
|
186
216
|
|
|
187
217
|
if existing_version is not None:
|
|
188
218
|
if existing_version == version_to_be_installed:
|
|
189
219
|
print(f"📦️ ⚠️ {exe_name} already installed at version {version_to_be_installed}. See {INSTALL_VERSION_ROOT}")
|
|
190
|
-
return
|
|
220
|
+
return ("✅ Uptodate", version.strip(), version_to_be_installed.strip())
|
|
191
221
|
else:
|
|
192
222
|
# print(f"Latest version is {version}, logged at {tmp_path}")
|
|
193
223
|
print(f"📦️ ⬆️ {exe_name} installed at version {existing_version.rstrip()} --> Installing version {version_to_be_installed} ")
|
|
194
224
|
tmp_path.write_text(version_to_be_installed)
|
|
225
|
+
return ("❌ Outdated", existing_version.strip(), version_to_be_installed.strip())
|
|
195
226
|
else:
|
|
196
227
|
print(f"📦️ {exe_name} has no known version. Installing version `{version_to_be_installed}` ")
|
|
197
228
|
tmp_path.write_text(version_to_be_installed)
|
|
198
|
-
return
|
|
229
|
+
return ("⚠️NotInstalled", "None", version_to_be_installed.strip())
|
|
230
|
+
|
|
231
|
+
|
|
232
|
+
def check_latest():
|
|
233
|
+
installers = get_installers(system=platform.system(), dev=False)
|
|
234
|
+
# installers += get_installers(system=platform.system(), dev=True)
|
|
235
|
+
installers_gitshub = []
|
|
236
|
+
for inst__ in installers:
|
|
237
|
+
if "ntop" in inst__.name: continue
|
|
238
|
+
if "github" not in inst__.repo_url:
|
|
239
|
+
print(f"Skipping {inst__.name} as it is not a github release")
|
|
240
|
+
continue
|
|
241
|
+
installers_gitshub.append(inst__)
|
|
242
|
+
|
|
243
|
+
def func(inst: Installer):
|
|
244
|
+
_release_url, version_to_be_installed = inst.get_github_release(repo_url=inst.repo_url, version=None)
|
|
245
|
+
verdict, current_ver, new_ver = inst.check_if_installed_already(exe_name=inst.exe_name, version=version_to_be_installed, use_cache=False)
|
|
246
|
+
return inst.exe_name, verdict, current_ver, new_ver
|
|
247
|
+
|
|
248
|
+
res = L(installers_gitshub).apply(func=func, jobs=1)
|
|
249
|
+
import pandas as pd
|
|
250
|
+
res_df = pd.DataFrame(res, columns=["Tool", "Status", "Current Version", "New Version"]).groupby("Status").apply(lambda x: x).reset_index(drop=True)
|
|
251
|
+
from crocodile.core import Display
|
|
252
|
+
Display.set_pandas_display()
|
|
253
|
+
print(res_df)
|
|
199
254
|
|
|
200
255
|
|
|
201
256
|
def get_installed_cli_apps():
|
|
202
257
|
if platform.system() == "Windows": apps = P.home().joinpath("AppData/Local/Microsoft/WindowsApps").search("*.exe", not_in=["notepad"])
|
|
203
|
-
elif platform.system() == "Linux": apps = P(
|
|
258
|
+
elif platform.system() == "Linux": apps = P(LINUX_INSTALL_PATH).search("*")
|
|
204
259
|
else: raise NotImplementedError("Not implemented for this OS")
|
|
205
260
|
apps = L([app for app in apps if app.size("kb") > 0.1 and not app.is_symlink()]) # no symlinks like paint and wsl and bash
|
|
206
261
|
return apps
|
|
@@ -210,14 +265,23 @@ def get_installers(system: str, dev: bool) -> list[Installer]:
|
|
|
210
265
|
if system == "Windows": import machineconfig.jobs.python_windows_installers as os_specific_installer
|
|
211
266
|
else: import machineconfig.jobs.python_linux_installers as os_specific_installer
|
|
212
267
|
import machineconfig.jobs.python_generic_installers as generic_installer
|
|
213
|
-
|
|
214
|
-
|
|
268
|
+
path_os_specific = P(os_specific_installer.__file__).parent
|
|
269
|
+
path_os_generic = P(generic_installer.__file__).parent
|
|
270
|
+
path_custom_installer = path_os_generic.with_name("python_custom_installers")
|
|
215
271
|
if dev:
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
res1: dict[str, Any] = Read.json(path=
|
|
219
|
-
res2: dict[str, Any] = Read.json(path=
|
|
272
|
+
path_os_specific = path_os_specific.joinpath("dev")
|
|
273
|
+
path_os_generic = path_os_generic.joinpath("dev")
|
|
274
|
+
res1: dict[str, Any] = Read.json(path=path_os_specific.joinpath("config.json"))
|
|
275
|
+
res2: dict[str, Any] = Read.json(path=path_os_generic.joinpath("config.json"))
|
|
220
276
|
res2.update(res1)
|
|
277
|
+
import runpy
|
|
278
|
+
for item in path_custom_installer.search("*.py", r=False):
|
|
279
|
+
try:
|
|
280
|
+
config_dict = runpy.run_path(str(item), run_name=None)['config_dict']
|
|
281
|
+
res2[item.stem] = config_dict
|
|
282
|
+
except Exception as ex:
|
|
283
|
+
print(f"Failed to load {item}: {ex}")
|
|
284
|
+
|
|
221
285
|
return [Installer.from_dict(d=vd, name=k) for k, vd in res2.items()]
|
|
222
286
|
|
|
223
287
|
|
|
@@ -229,7 +293,7 @@ def install_all(installers: L[Installer], safe: bool = False, jobs: int = 10, fr
|
|
|
229
293
|
if platform.system().lower() == "windows":
|
|
230
294
|
apps_dir.search("*").apply(lambda app: app.move(folder=P.get_env().WindowsApps))
|
|
231
295
|
elif platform.system().lower() == "linux":
|
|
232
|
-
Terminal().run(f"sudo mv {apps_dir.as_posix()}/* /
|
|
296
|
+
Terminal().run(f"sudo mv {apps_dir.as_posix()}/* {LINUX_INSTALL_PATH}/").print_if_unsuccessful(desc=f"MOVING executable to {LINUX_INSTALL_PATH}", strict_err=True, strict_returncode=True)
|
|
233
297
|
else: raise NotImplementedError(f"I don't know this system {platform.system()}")
|
|
234
298
|
apps_dir.delete(sure=True)
|
|
235
299
|
return None
|
|
@@ -249,3 +313,7 @@ def install_all(installers: L[Installer], safe: bool = False, jobs: int = 10, fr
|
|
|
249
313
|
print("\n")
|
|
250
314
|
print("Completed Installation".center(100, "-"))
|
|
251
315
|
print("\n" * 2)
|
|
316
|
+
|
|
317
|
+
|
|
318
|
+
if __name__ == "__main__":
|
|
319
|
+
pass
|
machineconfig/utils/utils.py
CHANGED
|
@@ -49,7 +49,7 @@ def sanitize_path(a_path: P) -> P:
|
|
|
49
49
|
path = P(a_path)
|
|
50
50
|
if path.as_posix().startswith("/home"):
|
|
51
51
|
if platform.system() == "Windows": # path copied from Linux to Windows
|
|
52
|
-
path = P.home().joinpath(*path.parts[
|
|
52
|
+
path = P.home().joinpath(*path.parts[3:]) # exlcude /home/username
|
|
53
53
|
assert path.exists(), f"File not found: {path}"
|
|
54
54
|
print(f"\n{'--' * 50}\n🔗 Mapped `{a_path}` ➡️ `{path}`\n{'--' * 50}\n")
|
|
55
55
|
elif platform.system() == "Linux" and P.home().as_posix() not in path.as_posix(): # copied from Linux to Linux with different username
|
|
@@ -195,7 +195,8 @@ def display_options(msg: str, options: Iterable[T], header: str = "", tail: str
|
|
|
195
195
|
if choice_string in options_strings: # string input
|
|
196
196
|
choice_idx = options_strings.index(choice_one) # type: ignore #TODO: fix this
|
|
197
197
|
choice_one = list(options)[choice_idx]
|
|
198
|
-
elif custom_input:
|
|
198
|
+
elif custom_input:
|
|
199
|
+
return choice_string # type: ignore #TODO: fix this
|
|
199
200
|
else: raise ValueError(f"Unknown choice. {choice_string}") from te
|
|
200
201
|
print(f"{choice_idx}: {choice_one}", f"<<<<-------- CHOICE MADE")
|
|
201
202
|
if multi: return [choice_one]
|
|
@@ -223,7 +224,8 @@ def symlink(this: P, to_this: P, prioritize_to_this: bool = True):
|
|
|
223
224
|
if not to_this.exists(): to_this.touch() # we have to touch it (file) or create it (folder)
|
|
224
225
|
if platform.system() == "Windows": _ = install_n_import("win32api", "pywin32") # this is crucial for windows to pop up the concent window in case python was not run as admin.
|
|
225
226
|
try:
|
|
226
|
-
|
|
227
|
+
# print(f"Linking {this} ➡️ {to_this}")
|
|
228
|
+
P(this).symlink_to(target=to_this, verbose=True, overwrite=True)
|
|
227
229
|
except Exception as ex: print(f"Failed at linking {this} ➡️ {to_this}.\nReason: {ex}")
|
|
228
230
|
|
|
229
231
|
|
|
@@ -311,7 +313,7 @@ def check_tool_exists(tool_name: str, install_script: Optional[str] = None) -> b
|
|
|
311
313
|
else: raise NotImplementedError(f"platform {platform.system()} not implemented")
|
|
312
314
|
|
|
313
315
|
try:
|
|
314
|
-
_tmp = subprocess.check_output([cmd, tool_name])
|
|
316
|
+
_tmp = subprocess.check_output([cmd, tool_name], stderr=subprocess.DEVNULL)
|
|
315
317
|
res: bool = True
|
|
316
318
|
except (subprocess.CalledProcessError, FileNotFoundError):
|
|
317
319
|
res = False
|
machineconfig/utils/ve.py
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"""python and ve installation related utils
|
|
3
3
|
"""
|
|
4
4
|
|
|
5
|
-
from crocodile.file_management import P, Struct, modify_text, List
|
|
5
|
+
from crocodile.file_management import P, Struct, modify_text, List, Read, Save
|
|
6
6
|
from machineconfig.utils.utils import LIBRARY_ROOT
|
|
7
7
|
import platform
|
|
8
8
|
from dataclasses import dataclass
|
|
@@ -23,6 +23,7 @@ class VE_INI:
|
|
|
23
23
|
|
|
24
24
|
|
|
25
25
|
def get_ipython_profile(init_path: P):
|
|
26
|
+
"""Relies on .ipy_profile"""
|
|
26
27
|
a_path = init_path
|
|
27
28
|
ipy_profile: str = "default"
|
|
28
29
|
idx = len(a_path.parts)
|
|
@@ -39,6 +40,7 @@ def get_ipython_profile(init_path: P):
|
|
|
39
40
|
|
|
40
41
|
|
|
41
42
|
def get_ve_profile(init_path: P, strict: bool = False):
|
|
43
|
+
"""Relies on .ve_path"""
|
|
42
44
|
ve = ""
|
|
43
45
|
tmp = init_path
|
|
44
46
|
for _ in init_path.parents:
|
|
@@ -51,6 +53,23 @@ def get_ve_profile(init_path: P, strict: bool = False):
|
|
|
51
53
|
return ve
|
|
52
54
|
|
|
53
55
|
|
|
56
|
+
def get_ve_name_and_ipython_profile(init_path: P):
|
|
57
|
+
ve_name = "ve"
|
|
58
|
+
ipy_profile = "default"
|
|
59
|
+
tmp = init_path
|
|
60
|
+
for _ in init_path.parents:
|
|
61
|
+
if tmp.joinpath(".ve.ini").exists():
|
|
62
|
+
ini = Read.ini(tmp.joinpath(".ve.ini"))
|
|
63
|
+
ve_name = ini["specs"]["ve_name"]
|
|
64
|
+
# py_version = ini["specs"]["py_version"]
|
|
65
|
+
ipy_profile = ini["specs"]["ipy_profile"]
|
|
66
|
+
print(f"✅ Using Virtual Environment: {ve_name}")
|
|
67
|
+
print(f"✅ Using IPython profile: {ipy_profile}")
|
|
68
|
+
break
|
|
69
|
+
tmp = tmp.parent
|
|
70
|
+
return ve_name, ipy_profile
|
|
71
|
+
|
|
72
|
+
|
|
54
73
|
def get_current_ve():
|
|
55
74
|
import sys
|
|
56
75
|
path = P(sys.executable) # something like ~\\venvs\\ve\\Scripts\\python.exe'
|
|
@@ -61,9 +80,10 @@ def get_current_ve():
|
|
|
61
80
|
def get_installed_interpreters() -> list[P]:
|
|
62
81
|
system = platform.system()
|
|
63
82
|
if system == "Windows":
|
|
64
|
-
tmp: list[P] = P.get_env().PATH.search("python.exe").reduce().list[1:]
|
|
83
|
+
tmp: list[P] = P.get_env().PATH.search("python.exe").reduce(func=lambda x, y: x+y).list[1:]
|
|
65
84
|
else:
|
|
66
|
-
|
|
85
|
+
items: List[P] = P.get_env().PATH.search("python3*").reduce(lambda x, y: x+y)
|
|
86
|
+
tmp = list(set(items.filter(lambda x: not x.is_symlink() and "-" not in x)))
|
|
67
87
|
List(tmp).print()
|
|
68
88
|
return list(set([P(x) for x in tmp]))
|
|
69
89
|
|
|
@@ -134,7 +154,6 @@ def get_ve_install_script(ve_name: Optional[str] = None, py_version: Optional[st
|
|
|
134
154
|
|
|
135
155
|
|
|
136
156
|
def get_ve_install_script_from_specs(repo_root: str, system: Literal["Windows", "Linux"]):
|
|
137
|
-
from crocodile.file_management import Read, Save
|
|
138
157
|
ini_file = P(repo_root).joinpath(".ve.ini")
|
|
139
158
|
assert ini_file.exists(), f"File {ini_file} does not exist."
|
|
140
159
|
ini = Read.ini(ini_file)
|
|
@@ -142,16 +161,10 @@ def get_ve_install_script_from_specs(repo_root: str, system: Literal["Windows",
|
|
|
142
161
|
py_version = ini["specs"]["py_version"]
|
|
143
162
|
ipy_profile = ini["specs"]["ipy_profile"]
|
|
144
163
|
|
|
145
|
-
# repo_root = ini_file.with_name("requirements.txt").parent
|
|
146
|
-
|
|
147
164
|
# for backward compatibility:
|
|
148
165
|
ini_file.with_name(".ve_path").write_text(f"~/venvs/{ve_name}")
|
|
149
166
|
ini_file.with_name(".ipy_profile").write_text(ipy_profile)
|
|
150
167
|
|
|
151
|
-
# vscode:
|
|
152
|
-
if not system == "Windows": # symlinks on windows require admin rights.
|
|
153
|
-
P(repo_root).joinpath(".venv").symlink_to(P.home().joinpath("venvs", ve_name))
|
|
154
|
-
|
|
155
168
|
vscode_settings = P(repo_root).joinpath(".vscode/settings.json")
|
|
156
169
|
if vscode_settings.exists():
|
|
157
170
|
settings = Read.json(vscode_settings)
|
|
@@ -166,7 +179,8 @@ def get_ve_install_script_from_specs(repo_root: str, system: Literal["Windows",
|
|
|
166
179
|
raise NotImplementedError(f"System {system} not supported.")
|
|
167
180
|
Save.json(obj=settings, path=vscode_settings, indent=4)
|
|
168
181
|
|
|
169
|
-
|
|
182
|
+
subpath = "versions/init"
|
|
183
|
+
base_path = P(repo_root).joinpath(subpath).create()
|
|
170
184
|
if system == "Windows":
|
|
171
185
|
script = get_ps1_install_template(ve_name=ve_name, py_version=py_version)
|
|
172
186
|
base_path.joinpath("install_ve.ps1").write_text(script)
|
|
@@ -176,8 +190,13 @@ def get_ve_install_script_from_specs(repo_root: str, system: Literal["Windows",
|
|
|
176
190
|
else:
|
|
177
191
|
raise NotImplementedError(f"System {system} not supported.")
|
|
178
192
|
|
|
179
|
-
base_path.joinpath("install_requirements.ps1").write_text(get_install_requirements_template(repo_root=P(repo_root)))
|
|
180
|
-
base_path.joinpath("install_requirements.sh").write_text(get_install_requirements_template(repo_root=P(repo_root)))
|
|
193
|
+
base_path.joinpath("install_requirements.ps1").write_text(get_install_requirements_template(repo_root=P(repo_root), requirements_subpath=subpath))
|
|
194
|
+
base_path.joinpath("install_requirements.sh").write_text(get_install_requirements_template(repo_root=P(repo_root), requirements_subpath=subpath))
|
|
195
|
+
|
|
196
|
+
# vscode:
|
|
197
|
+
if not system == "Windows": # symlinks on windows require admin rights.
|
|
198
|
+
P(repo_root).joinpath(".venv").symlink_to(target=P.home().joinpath("venvs", ve_name), strict=False)
|
|
199
|
+
# set strict to False since ve doesn't exist yet.
|
|
181
200
|
|
|
182
201
|
return script
|
|
183
202
|
|
|
@@ -200,13 +219,15 @@ curl -L https://bit.ly/cfgvelinux | bash
|
|
|
200
219
|
return template
|
|
201
220
|
|
|
202
221
|
|
|
203
|
-
def get_install_requirements_template(repo_root: P):
|
|
222
|
+
def get_install_requirements_template(repo_root: P, requirements_subpath: str):
|
|
204
223
|
return f"""
|
|
205
224
|
# This is a template that is meant to be modified manually to install requirements.txt and editable packages.
|
|
206
225
|
# one can dispense with this and install libraries manually and on adhoc-basis and then use version_checkout utility.
|
|
207
|
-
|
|
226
|
+
|
|
227
|
+
set -e # exit on error, you don't want to install reqiurements in wrong environment.
|
|
228
|
+
cd $HOME/{repo_root.rel2home().as_posix()}
|
|
208
229
|
. $HOME/scripts/activate_ve
|
|
209
|
-
pip install -r requirements.txt
|
|
230
|
+
pip install -r {requirements_subpath}/requirements.txt
|
|
210
231
|
pip install -e .
|
|
211
232
|
|
|
212
233
|
# cd ~/code; git clone https://github.com/thisismygitrepo/crocodile.git --origin origin
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|