machineconfig 1.9__py3-none-any.whl → 1.91__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.

Files changed (53) hide show
  1. machineconfig/__init__.py +1 -1
  2. machineconfig/jobs/python/check_installations.py +7 -5
  3. machineconfig/jobs/python/checkout_version.py +27 -32
  4. machineconfig/jobs/python/create_bootable_media.py +1 -1
  5. machineconfig/jobs/python/python_cargo_build_share.py +2 -2
  6. machineconfig/jobs/python/tasks.py +2 -2
  7. machineconfig/jobs/python_custom_installers/{helix.py → hx.py} +17 -5
  8. machineconfig/profile/create.py +23 -21
  9. machineconfig/profile/create_hardlinks.py +101 -0
  10. machineconfig/profile/shell.py +5 -5
  11. machineconfig/scripts/python/cloud_copy.py +19 -16
  12. machineconfig/scripts/python/cloud_repo_sync.py +92 -47
  13. machineconfig/scripts/python/cloud_sync.py +70 -63
  14. machineconfig/scripts/python/croshell.py +6 -6
  15. machineconfig/scripts/python/devops.py +19 -20
  16. machineconfig/scripts/python/devops_backup_retrieve.py +19 -10
  17. machineconfig/scripts/python/devops_devapps_install.py +80 -62
  18. machineconfig/scripts/python/devops_update_repos.py +5 -5
  19. machineconfig/scripts/python/dotfile.py +4 -4
  20. machineconfig/scripts/python/fire_jobs.py +57 -23
  21. machineconfig/scripts/python/gh_models.py +53 -0
  22. machineconfig/scripts/python/mount_nfs.py +1 -1
  23. machineconfig/scripts/python/mount_nw_drive.py +3 -3
  24. machineconfig/scripts/python/mount_ssh.py +2 -3
  25. machineconfig/scripts/python/pomodoro.py +1 -1
  26. machineconfig/scripts/python/repos.py +21 -22
  27. machineconfig/scripts/python/scheduler.py +1 -1
  28. machineconfig/scripts/python/start_slidev.py +10 -4
  29. machineconfig/scripts/python/start_terminals.py +5 -4
  30. machineconfig/scripts/python/wifi_conn.py +34 -42
  31. machineconfig/scripts/python/wsl_windows_transfer.py +1 -1
  32. machineconfig/setup_windows/wt_and_pwsh/set_pwsh_theme.py +1 -1
  33. machineconfig/setup_windows/wt_and_pwsh/set_wt_settings.py +3 -2
  34. machineconfig/utils/installer.py +78 -39
  35. machineconfig/utils/procs.py +2 -2
  36. machineconfig/utils/scheduling.py +3 -3
  37. machineconfig/utils/utils.py +131 -52
  38. machineconfig/utils/ve.py +145 -95
  39. {machineconfig-1.9.dist-info → machineconfig-1.91.dist-info}/METADATA +160 -155
  40. machineconfig-1.91.dist-info/RECORD +69 -0
  41. machineconfig/jobs/python_custom_installers/azuredatastudio.py +0 -36
  42. machineconfig/jobs/python_custom_installers/bypass_paywall.py +0 -30
  43. machineconfig/jobs/python_custom_installers/docker_desktop.py +0 -52
  44. machineconfig/jobs/python_custom_installers/goes.py +0 -35
  45. machineconfig/jobs/python_custom_installers/lvim.py +0 -48
  46. machineconfig/jobs/python_custom_installers/ngrok.py +0 -39
  47. machineconfig/jobs/python_custom_installers/nvim.py +0 -48
  48. machineconfig/jobs/python_custom_installers/vscode.py +0 -45
  49. machineconfig/jobs/python_custom_installers/wezterm.py +0 -41
  50. machineconfig-1.9.dist-info/RECORD +0 -76
  51. {machineconfig-1.9.dist-info → machineconfig-1.91.dist-info}/LICENSE +0 -0
  52. {machineconfig-1.9.dist-info → machineconfig-1.91.dist-info}/WHEEL +0 -0
  53. {machineconfig-1.9.dist-info → machineconfig-1.91.dist-info}/top_level.txt +0 -0
machineconfig/utils/ve.py CHANGED
@@ -2,10 +2,12 @@
2
2
  """python and ve installation related utils
3
3
  """
4
4
 
5
- from crocodile.file_management import P, Struct, modify_text, List, Read, Save
5
+ from crocodile.core import Struct, Save, List
6
+ from crocodile.file_management import P, Read
7
+
6
8
  from machineconfig.utils.utils import LIBRARY_ROOT
7
9
  import platform
8
- from dataclasses import dataclass
10
+ from dataclasses import dataclass, asdict
9
11
  from typing import Optional, Literal
10
12
 
11
13
 
@@ -25,7 +27,7 @@ class VE_INI:
25
27
  def get_ipython_profile(init_path: P):
26
28
  """Relies on .ipy_profile"""
27
29
  a_path = init_path
28
- ipy_profile: str = "default"
30
+ ipy_profile: str="default"
29
31
  idx = len(a_path.parts)
30
32
  while idx >= 0:
31
33
  if a_path.joinpath(".ipy_profile").exists():
@@ -37,9 +39,7 @@ def get_ipython_profile(init_path: P):
37
39
  else:
38
40
  print(f"⚠️ Using default IPython: {ipy_profile}")
39
41
  return ipy_profile
40
-
41
-
42
- def get_ve_profile(init_path: P, strict: bool = False):
42
+ def get_ve_profile(init_path: P, strict: bool=False):
43
43
  """Relies on .ve_path"""
44
44
  ve = ""
45
45
  tmp = init_path
@@ -51,8 +51,6 @@ def get_ve_profile(init_path: P, strict: bool = False):
51
51
  tmp = tmp.parent
52
52
  if ve == "" and strict: raise ValueError("❌ No virtual environment found.")
53
53
  return ve
54
-
55
-
56
54
  def get_ve_name_and_ipython_profile(init_path: P):
57
55
  ve_name = "ve"
58
56
  ipy_profile = "default"
@@ -68,8 +66,6 @@ def get_ve_name_and_ipython_profile(init_path: P):
68
66
  break
69
67
  tmp = tmp.parent
70
68
  return ve_name, ipy_profile
71
-
72
-
73
69
  def get_current_ve():
74
70
  import sys
75
71
  path = P(sys.executable) # something like ~\\venvs\\ve\\Scripts\\python.exe'
@@ -86,27 +82,26 @@ def get_installed_interpreters() -> list[P]:
86
82
  tmp = list(set(items.filter(lambda x: not x.is_symlink() and "-" not in x)))
87
83
  List(tmp).print()
88
84
  return list(set([P(x) for x in tmp]))
89
-
90
-
91
85
  def get_ve_specs(ve_path: P) -> dict[str, str]:
92
86
  ini = r"[mysection]\n" + ve_path.joinpath("pyvenv.cfg").read_text()
93
87
  import configparser
94
88
  config = configparser.ConfigParser()
95
89
  config.read_string(ini)
96
90
  res = dict(config['mysection'])
97
- res['version_major_minor'] = ".".join(res['version'].split(".")[0:2])
91
+ # try:
92
+ # res['version_major_minor'] = ".".join(res['version'].split(".")[0:2])
93
+ # except KeyError:
94
+ # # res['version_major_minor'] = ".".join(res['version_info'].split(".")[0:2])
98
95
  return res
99
96
 
100
97
 
101
- def get_ve_install_script(ve_name: Optional[str] = None, py_version: Optional[str] = None, install_crocodile_and_machineconfig: Optional[bool] = None,
102
- delete_if_exists: bool = True,
103
- system: Optional[Literal["Windows", "Linux"]] = None) -> str:
98
+ def get_ve_install_script(ve_name: Optional[str] = None, py_version: Optional[str] = None,
99
+ install_crocodile_and_machineconfig: Optional[bool] = None,
100
+ delete_if_exists: bool=True,
101
+ # system: Optional[Literal["Windows", "Linux"]] = None
102
+ ) -> str:
104
103
  from rich.console import Console
105
- if system is None:
106
- system_: str = platform.system()
107
- else: system_ = system
108
104
  console = Console()
109
-
110
105
  if py_version is None:
111
106
  print("\n\n")
112
107
  console.rule("Existing Python versions", style="bold red")
@@ -114,130 +109,185 @@ def get_ve_install_script(ve_name: Optional[str] = None, py_version: Optional[st
114
109
  List(res).print()
115
110
  print("\n\n")
116
111
  dotted_py_version = input("Enter python version (3.11): ") or "3.11"
117
- else: dotted_py_version = py_version
112
+ else:
113
+ dotted_py_version = py_version
118
114
 
119
115
  if ve_name is None:
120
- console.rule(f"Existing virtual environments")
116
+ console.rule("Existing virtual environments")
121
117
  for ve_path in P.home().joinpath("venvs").search("*", files=False):
122
- ve_specs = get_ve_specs(ve_path)
123
- # console.print(Panel(str(ve_specs), title=ve_path.stem, style="bold blue"))
118
+ try:
119
+ ve_specs = get_ve_specs(ve_path)
120
+ except Exception as _e:
121
+ continue
124
122
  Struct(ve_specs).print(title=ve_path.stem, as_config=True)
125
123
  ve_name = input("Enter virtual environment name (tst): ") or "tst"
126
124
 
127
- if install_crocodile_and_machineconfig is None: croco_mac = input("Install essential repos? (y/[n]): ") == "y"
128
- else: croco_mac = install_crocodile_and_machineconfig
125
+ if install_crocodile_and_machineconfig is None:
126
+ essential_repos = input("Install essential repos? (y/[n]): ") == "y"
127
+ other_repos = input("Input space separated other packages: ")
128
+ else:
129
+ essential_repos = install_crocodile_and_machineconfig
130
+ other_repos = ""
129
131
 
130
132
  env_path = P.home().joinpath("venvs", ve_name)
131
133
  if delete_if_exists and env_path.exists():
132
134
  sure = input(f"An existing environment found. Are you sure you want to delete {env_path} before making new one? (y/[n]): ") == "y"
133
- console.rule(f"Deleting existing enviroment with similar name")
135
+ console.rule("Deleting existing enviroment with similar name")
134
136
  env_path.delete(sure=sure)
135
137
 
136
- scripts = LIBRARY_ROOT.joinpath(f"setup_{system_.lower()}/ve.{'ps1' if system_ == 'Windows' else 'sh'}").read_text()
137
-
138
- variable_prefix = "$" if system_ == "Windows" else ""
139
- line1 = f"{variable_prefix}ve_name='{ve_name}'"
140
- line2 = f"{variable_prefix}py_version='{dotted_py_version}'"
141
- line_start = "# --- Define ve name and python version here ---"
142
- line_end = "# --- End of user defined variables ---"
143
- assert line_start in scripts and line_end in scripts, "Script template was mutated beyond recognition."
144
- scripts = scripts.split(line_start)[0] + "\n".join([line_start, line1, line2, line_end]) + scripts.split(line_end)[1]
145
-
146
- if croco_mac: # TODO make this more robust by removing sections of the script as opposed to word placeholders.
147
- text = LIBRARY_ROOT.joinpath(f"setup_{system_.lower()}/repos.{'ps1' if system_ == 'Windows' else 'sh'}").read_text()
148
- text = modify_text(txt_raw=text, txt_search="ve_name=", txt_alt=f"{variable_prefix}ve_name='{ve_name}'", replace_line=True)
149
- scripts += text
138
+ system = platform.system()
139
+ if system == "Windows":
140
+ script = get_ps1_ve_install_script(ve_name=ve_name, py_version=dotted_py_version, use_web=False, system=system)
141
+ elif system == "Linux":
142
+ script = get_bash_ve_install_script(ve_name=ve_name, py_version=dotted_py_version, use_web=False, system=system)
143
+ else:
144
+ raise NotImplementedError(f"System {system} not supported.")
150
145
 
151
- # ve_ini_specs = VE_Specs(ve_name=ve_name, py_version=dotted_py_version, ipy_profile="default", os=system_)
152
- # ve_ini = VE_INI(specs=ve_ini_specs)
153
- return scripts
146
+ if essential_repos:
147
+ if system == "Windows":
148
+ script += "\n" + get_ps1_repos_install_script(ve_name=ve_name, use_web=False, system=system)
149
+ elif system == "Linux":
150
+ script += "\n" + get_bash_repos_install_script(ve_name=ve_name, use_web=False, system=system)
151
+ else:
152
+ raise NotImplementedError(f"System {system} not supported.")
153
+
154
+ if other_repos != "":
155
+ # TODO: check the quivalent full path of uv on windows $HOME/.local/bin/
156
+ script += "\nuv pip install " + other_repos
157
+ # target = repo_root.joinpath(".venv")
158
+ # source = P.home().joinpath("venvs", ve_name)
159
+ # if system == "Windows": cmd = f'New-Item -ItemType SymbolicLink -Path "{target}" -Target "{source}"'
160
+ # elif system == "Linux": cmd = f'ln -s "{source}" "{target}"'
161
+ # else: raise NotImplementedError(f"System {system} not supported.")
162
+ # script += f"\n{cmd}"
163
+
164
+ link_ve: str=input("Create symlinks? [y/[n]] ") == "y"
165
+ if link_ve: create_symlinks(repo_root=P.cwd(), ve_name=ve_name, dotted_py_version=dotted_py_version, system=system, ipy_profile="default")
166
+ make_installation_recipe(repo_root=P.cwd(), ve_name=ve_name, py_version=dotted_py_version)
167
+ return script
154
168
 
155
169
 
156
- def get_ve_install_script_from_specs(repo_root: str, system: Literal["Windows", "Linux"]):
157
- ini_file = P(repo_root).joinpath(".ve.ini")
158
- assert ini_file.exists(), f"File {ini_file} does not exist."
159
- ini = Read.ini(ini_file)
160
- ve_name = ini["specs"]["ve_name"]
161
- py_version = ini["specs"]["py_version"]
162
- ipy_profile = ini["specs"]["ipy_profile"]
170
+ def create_symlinks(repo_root: P, ve_name: str, dotted_py_version: str, system: Literal["Windows", "Linux"], ipy_profile: str):
171
+ from machineconfig.utils.utils import symlink_func
172
+ source = repo_root.joinpath(".venv")
173
+ target = P.home().joinpath("venvs", ve_name)
174
+ target.mkdir(exist_ok=True, parents=True) # if ve not created yet, make up a folder at least, so that symlink can be created, then this folder is either populated or recreated by ve creation script.
175
+ symlink_func(this=source, to_this=target)
163
176
 
164
177
  # for backward compatibility:
165
- ini_file.with_name(".ve_path").write_text(f"~/venvs/{ve_name}")
166
- ini_file.with_name(".ipy_profile").write_text(ipy_profile)
167
-
168
- vscode_settings = P(repo_root).joinpath(".vscode/settings.json")
169
- if vscode_settings.exists():
170
- settings = Read.json(vscode_settings)
178
+ repo_root.joinpath(".ve_path").write_text(f"~/venvs/{ve_name}")
179
+ repo_root.joinpath(".ipy_profile").write_text(ipy_profile)
180
+
181
+ ve_ini_specs = VE_Specs(ve_name=ve_name, py_version=dotted_py_version, ipy_profile="default", os=system)
182
+ ve_ini = VE_INI(specs=ve_ini_specs)
183
+ Save.ini(obj=asdict(ve_ini), path=repo_root.joinpath(".ve.ini"))
184
+ vscode = repo_root.joinpath(".vscode/settings.json")
185
+ if vscode.exists():
186
+ settings = Read.json(vscode)
171
187
  else:
172
188
  settings = {}
173
189
  if system == "Windows":
174
- settings["python.defaultInterpreterPath"] = f"~/venvs/{ve_name}/Scripts/python.exe"
190
+ settings["python.defaultInterpreterPath"] = P.home().joinpath("venvs", ve_name, "Scripts", "python.exe").as_posix()
175
191
  elif system == "Linux":
176
- settings["python.defaultInterpreterPath"] = f"~/venvs/{ve_name}/bin/python"
177
- pass
192
+ settings["python.defaultInterpreterPath"] = P.home().joinpath("venvs", ve_name, "bin", "python").as_posix()
178
193
  else:
179
194
  raise NotImplementedError(f"System {system} not supported.")
180
- Save.json(obj=settings, path=vscode_settings, indent=4)
195
+ Save.json(obj=settings, path=vscode, indent=4)
196
+
181
197
 
198
+ def make_installation_recipe(repo_root: str, ve_name: str, py_version: str):
182
199
  subpath = "versions/init"
183
200
  base_path = P(repo_root).joinpath(subpath).create()
184
- if system == "Windows":
185
- script = get_ps1_install_template(ve_name=ve_name, py_version=py_version)
186
- base_path.joinpath("install_ve.ps1").write_text(script)
187
- elif system == "Linux":
188
- script = get_bash_install_template(ve_name=ve_name, py_version=py_version)
189
- base_path.joinpath("install_ve.sh").write_text(script)
190
- else:
191
- raise NotImplementedError(f"System {system} not supported.")
192
-
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
201
 
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.
202
+ system = "Windows"
203
+ path3 = base_path.joinpath("install_requirements.ps1")
204
+ if path3.exists(): print(f" File already exists @ {path3}, skipping.")
205
+ else:
206
+ install_ve_script = get_ps1_ve_install_script(ve_name=ve_name, py_version=py_version, use_web=True, system=system)
207
+ install_req_script = get_install_requirements_template(repo_root=P(repo_root), requirements_subpath=subpath, ve_name=ve_name, system=system)
208
+ path3.write_text(install_ve_script + "\n" + install_req_script)
200
209
 
201
- return script
210
+ system= "Linux"
211
+ path4 = base_path.joinpath("install_requirements.sh")
212
+ if path4.exists(): print(f"❌ File already exists @ {path4}, skipping.")
213
+ else:
214
+ install_ve_script = get_bash_ve_install_script(ve_name=ve_name, py_version=py_version, use_web=True, system=system)
215
+ install_req_script = get_install_requirements_template(repo_root=P(repo_root), requirements_subpath=subpath, ve_name=ve_name, system=system)
216
+ path4.write_text(install_ve_script + "\n" + install_req_script)
217
+ return None
202
218
 
203
219
 
204
- def get_ps1_install_template(ve_name: str, py_version: str):
220
+ def get_ps1_ve_install_script(ve_name: str, py_version: str, use_web: bool, system: Literal["Windows", "Linux"]):
221
+ if use_web:
222
+ install_line = """(Invoke-WebRequest https://bit.ly/cfgvewindows).Content | Invoke-Expression"""
223
+ else:
224
+ install_line = LIBRARY_ROOT.joinpath(f"setup_{system.lower()}/ve.{'ps1' if system == 'Windows' else 'sh'}").read_text()
205
225
  template = f"""
206
226
  $ve_name = '{ve_name}'
207
227
  $py_version = '{py_version}' # type: ignore
208
- (Invoke-WebRequest https://bit.ly/cfgvewindows).Content | Invoke-Expression
228
+ {install_line}
209
229
  . $HOME/scripts/activate_ve $ve_name
210
230
  """
211
231
  return template
212
- def get_bash_install_template(ve_name: str, py_version: str):
232
+ def get_bash_ve_install_script(ve_name: str, py_version: str, use_web: bool, system: Literal["Windows", "Linux"]):
233
+ if use_web: install_line = """curl -L https://bit.ly/cfgvelinux | bash"""
234
+ else:
235
+ install_line = LIBRARY_ROOT.joinpath(f"setup_{system.lower()}/ve.{'ps1' if system == 'Windows' else 'sh'}").read_text()
213
236
  template = f"""
214
237
  export ve_name='{ve_name}'
215
238
  export py_version='{py_version}' # type: ignore
216
- curl -L https://bit.ly/cfgvelinux | bash
239
+ {install_line}
217
240
  . $HOME/scripts/activate_ve $ve_name
241
+ """
242
+ return template
243
+ def get_ps1_repos_install_script(ve_name: str, use_web: bool, system: Literal["Windows", "Linux"]):
244
+ if use_web: install_line = """(Invoke-WebRequest https://bit.ly/cfgreposwindows).Content | Invoke-Expression"""
245
+ else:
246
+ install_line = LIBRARY_ROOT.joinpath(f"setup_{system.lower()}/repos.{'ps1' if system == 'Windows' else 'sh'}").read_text()
247
+ template = f"""
248
+ $ve_name = '{ve_name}'
249
+ . $HOME/scripts/activate_ve $ve_name
250
+ {install_line}
218
251
  """
219
252
  return template
220
253
 
221
-
222
- def get_install_requirements_template(repo_root: P, requirements_subpath: str):
254
+ def get_bash_repos_install_script(ve_name: str, use_web: bool, system: Literal["Windows", "Linux"]):
255
+ if use_web: install_line = """curl -L https://bit.ly/cfgreposlinux | bash"""
256
+ else:
257
+ install_line = LIBRARY_ROOT.joinpath(f"setup_{system.lower()}/repos.{'ps1' if system == 'Windows' else 'sh'}").read_text()
258
+ template = f"""
259
+ export ve_name='{ve_name}'
260
+ . $HOME/scripts/activate_ve $ve_name
261
+ {install_line}
262
+ """
263
+ return template
264
+ def get_install_requirements_template(repo_root: P, requirements_subpath: str, ve_name: str, system: Literal["Windows", "Linux"]):
265
+ if system == 'Windows':
266
+ set_e_equivalent = 'Set-StrictMode -Version Latest' # PowerShell equivalent
267
+ install_line = """(Invoke-WebRequest https://bit.ly/cfgreposwindows).Content | Invoke-Expression"""
268
+ activate_ve = fr"""$HOME\venvs\{ve_name}\Scripts\Activate.ps1 -ErrorAction Stop """
269
+ elif system == 'Linux':
270
+ set_e_equivalent = 'set -e' # Bash equivalent
271
+ install_line = """curl -L https://bit.ly/cfgreposlinux | bash"""
272
+ activate_ve = fr""". $HOME/venvs/{ve_name}/bin/activate """
273
+ else: raise NotImplementedError(f"System {system} not supported.")
223
274
  return f"""
275
+
224
276
  # This is a template that is meant to be modified manually to install requirements.txt and editable packages.
225
277
  # one can dispense with this and install libraries manually and on adhoc-basis and then use version_checkout utility.
226
278
 
227
- set -e # exit on error, you don't want to install reqiurements in wrong environment.
279
+ # mkdir -p $HOME/{repo_root.rel2home().as_posix()}
280
+ # cd $HOME/{repo_root.rel2home().as_posix()}
281
+ # git clone URL --depth 2
282
+
283
+ {set_e_equivalent}
284
+
228
285
  cd $HOME/{repo_root.rel2home().as_posix()}
229
- . $HOME/scripts/activate_ve
230
- pip install -r {requirements_subpath}/requirements.txt
231
- pip install -e .
232
286
 
233
- # cd ~/code; git clone https://github.com/thisismygitrepo/crocodile.git --origin origin
234
- # cd ~/code/crocodile; git remote set-url origin https://github.com/thisismygitrepo/crocodile.git
235
- # cd ~/code/crocodile; git remote add origin https://github.com/thisismygitrepo/crocodile.git
236
- # cd ~/code/crocodile; pip install -e .
287
+ {activate_ve}
237
288
 
238
- # cd ~/code; git clone https://github.com/thisismygitrepo/machineconfig --origin origin
239
- # cd ~/code/machineconfig; git remote set-url origin https://github.com/thisismygitrepo/machineconfig
240
- # cd ~/code/machineconfig; git remote add origin https://github.com/thisismygitrepo/machineconfig
241
- # cd ~/code/machineconfig; pip install -e .
289
+ # {install_line}
290
+ pip install -r {requirements_subpath}/requirements.txt
291
+ # pip install -e .
242
292
 
243
293
  """