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
@@ -6,79 +6,97 @@
6
6
  from tqdm import tqdm
7
7
  from crocodile.core import List as L
8
8
  from machineconfig.utils.utils import LIBRARY_ROOT, choose_multiple_options
9
- from machineconfig.utils.installer import get_installers, Installer, install_all
9
+ from machineconfig.utils.installer import get_installers, install_all, Installer, get_all_dicts
10
10
  from platform import system
11
- from typing import Any, Optional, Literal, TypeAlias
11
+ from typing import Any, Optional, Literal, TypeAlias, get_args
12
12
 
13
13
 
14
- WHICH: TypeAlias = Literal["AllEssentials", "EssentialsAndOthers", "SystemInstallers", "OtherDevApps", "PrecheckedCloudInstaller"]
14
+ WHICH_CAT: TypeAlias = Literal["AllEssentials", "EssentialsAndOthers", "SystemInstallers", "PrecheckedCloudInstaller"]
15
15
 
16
16
 
17
- def main(which: Optional[str] = None):
18
- sys = system()
19
- installers = get_installers(dev=False, system=sys) # + get_installers(dev=True, system=sys)
20
- default = "AllEssentials"
21
- options = ["SystemInstallers", "OtherDevApps", "EssentialsAndOthers", "PrecheckedCloudInstaller", default]
22
- options = [x.get_description() for x in tqdm(installers, desc="Checking installed programs")] + options
17
+ def main(which: Optional[WHICH_CAT | str] = None):
23
18
 
24
- if which is not None:
25
- return get_program(program_name=which, options=options, installers=list(installers))
19
+ if which is not None and which in get_args(WHICH_CAT): # install by category
20
+ return get_programs_by_category(program_name=which) # type: ignore
21
+
22
+ if which is not None: # install by name
23
+ program_total = ""
24
+ for a_which in (which.split(",") if type(which) == str else which):
25
+ kv = {}
26
+ for _category, v in get_all_dicts(system=system()).items():
27
+ kv.update(v)
28
+ if a_which not in kv:
29
+ raise ValueError(f"{a_which=} not found in {kv.keys()}")
30
+ print(f"Installing {a_which}", kv[a_which])
31
+ installer = Installer.from_dict(name=a_which, d=kv[a_which])
32
+ print(installer)
33
+ program = installer.install_robust(version=None) # finish the task
34
+ program = "echo 'Finished Installation'" # write an empty program
35
+ program_total += "\n" + program
36
+ return program_total
37
+
38
+ # interactive installation
39
+ installers = [Installer.from_dict(d=vd, name=name) for __kat, vds in get_all_dicts(system=system()).items() for name, vd in vds.items()]
40
+ options = [x.get_description() for x in tqdm(installers, desc="Checking installed programs")] + list(get_args(WHICH_CAT))
41
+ program_names = choose_multiple_options(msg="", options=options, header="CHOOSE DEV APP", default="AllEssentials")
26
42
 
27
- program_names = choose_multiple_options(msg="", options=options, header="CHOOSE DEV APP", default=str(default))
28
43
  total_program = ""
29
- for which in program_names:
30
- assert isinstance(which, str), f"program_name is not a string: {which}"
31
- total_program += "\n" + get_program(program_name=which, options=options, installers=list(installers))
44
+ for _an_idx, a_program_name in enumerate(program_names):
45
+ print(a_program_name)
46
+ if a_program_name in get_args(WHICH_CAT):
47
+ total_program += "\n" + get_programs_by_category(program_name=a_program_name) # type: ignore
48
+ else:
49
+ an_installer = installers[options.index(a_program_name)]
50
+ total_program += "\n" + an_installer.install_robust(version=None) # finish the task
32
51
  return total_program
33
52
 
34
53
 
35
- def get_program(program_name: str, options: list[str], installers: list[Installer]):
36
- if program_name == "AllEssentials" or program_name == "EssentialsAndOthers":
37
- installers_ = get_installers(dev=False, system=system())
38
- if program_name == "EssentialsAndOthers":
39
- installers_ += get_installers(dev=True, system=system())
40
- install_all(installers=L(installers))
41
- program = ""
42
- elif program_name == "SystemInstallers":
43
- if system() == "Windows": options_system = parse_apps_installer_windows(LIBRARY_ROOT.joinpath("setup_windows/apps.ps1").read_text())
44
- elif system() == "Linux":
45
- options_system_1 = parse_apps_installer_linux(LIBRARY_ROOT.joinpath("setup_linux/apps_dev.sh").read_text())
46
- options_system_2 = parse_apps_installer_linux(LIBRARY_ROOT.joinpath("setup_linux/apps.sh").read_text())
47
- options_system = {**options_system_1, **options_system_2}
48
- else: raise NotImplementedError(f"System {system()} not supported")
49
- program_names = choose_multiple_options(msg="", options=sorted(list(options_system.keys())), header="CHOOSE DEV APP")
50
- program = ""
51
- for name in program_names:
52
- sub_program = options_system[name]
53
- if sub_program.startswith("#winget"): sub_program = sub_program[1:]
54
- program += "\n" + sub_program
55
- elif program_name == "OtherDevApps":
56
- installers = get_installers(dev=True, system=system())
57
- options__: list[str] = [x.get_description() for x in tqdm(installers, desc="Checking installed programs")]
58
- program_names = choose_multiple_options(msg="", options=sorted(options__) + ["all"], header="CHOOSE DEV APP")
59
- if "all" in program_names: program_names = options__
60
- program = ""
61
- print(f"Installing:")
62
- L(program_names).print()
63
- for name in program_names:
64
- try:
65
- idx = options__.index(name)
66
- except ValueError as ve:
67
- print(f"{name=}")
68
- print(f"{options__=}")
69
- raise ve
70
- print(f"Installing {name}")
71
- sub_program = installers[idx].install_robust(version=None) # finish the task
72
- elif program_name == "PrecheckedCloudInstaller":
73
- from machineconfig.jobs.python.check_installations import PrecheckedCloudInstaller
74
- ci = PrecheckedCloudInstaller()
75
- ci.download_safe_apps(name="AllEssentials")
76
- program = ""
77
- else:
78
- idx = options.index(program_name)
79
- print(installers[idx])
80
- program = installers[idx].install_robust(version=None) # finish the task
81
- program = "echo 'Finished Installation'" # write an empty program
54
+ def get_programs_by_category(program_name: WHICH_CAT):
55
+ match program_name:
56
+ case "AllEssentials" | "EssentialsAndOthers":
57
+ installers_ = get_installers(dev=False, system=system())
58
+ if program_name == "EssentialsAndOthers":
59
+ installers_ += get_installers(dev=True, system=system())
60
+ install_all(installers=L(installers_))
61
+ program = ""
62
+
63
+ case "SystemInstallers":
64
+ if system() == "Windows": options_system = parse_apps_installer_windows(LIBRARY_ROOT.joinpath("setup_windows/apps.ps1").read_text())
65
+ elif system() == "Linux":
66
+ options_system_1 = parse_apps_installer_linux(LIBRARY_ROOT.joinpath("setup_linux/apps_dev.sh").read_text())
67
+ options_system_2 = parse_apps_installer_linux(LIBRARY_ROOT.joinpath("setup_linux/apps.sh").read_text())
68
+ options_system = {**options_system_1, **options_system_2}
69
+ else: raise NotImplementedError(f"System {system()} not supported")
70
+ program_names = choose_multiple_options(msg="", options=sorted(list(options_system.keys())), header="CHOOSE DEV APP")
71
+ program = ""
72
+ for name in program_names:
73
+ sub_program = options_system[name]
74
+ if sub_program.startswith("#winget"): sub_program = sub_program[1:]
75
+ program += "\n" + sub_program
76
+
77
+ # case "OtherDevApps":
78
+ # installers = get_installers(dev=True, system=system())
79
+ # options__: list[str] = [x.get_description() for x in tqdm(installers, desc="Checking installed programs")]
80
+ # program_names = choose_multiple_options(msg="", options=sorted(options__) + ["all"], header="CHOOSE DEV APP")
81
+ # if "all" in program_names: program_names = options__
82
+ # program = ""
83
+ # print("Installing:")
84
+ # L(program_names).print()
85
+ # for name in program_names:
86
+ # try:
87
+ # idx = options__.index(name)
88
+ # except ValueError as ve:
89
+ # print(f"{name=}")
90
+ # print(f"{options__=}")
91
+ # raise ve
92
+ # print(f"Installing {name}")
93
+ # sub_program = installers[idx].install_robust(version=None) # finish the task
94
+
95
+ case "PrecheckedCloudInstaller":
96
+ from machineconfig.jobs.python.check_installations import PrecheckedCloudInstaller
97
+ ci = PrecheckedCloudInstaller()
98
+ ci.download_safe_apps(name="AllEssentials")
99
+ program = ""
82
100
  return program
83
101
 
84
102
 
@@ -3,7 +3,6 @@
3
3
  """
4
4
 
5
5
  from crocodile.file_management import P, Read
6
- from crocodile.core import install_n_import
7
6
  from machineconfig.utils.utils import DEFAULTS_PATH
8
7
  from platform import system
9
8
 
@@ -11,7 +10,7 @@ from platform import system
11
10
  sep = "\n"
12
11
 
13
12
 
14
- def main(verbose: bool = True) -> str:
13
+ def main(verbose: bool=True) -> str:
15
14
  _ = verbose
16
15
  repos: list[str] = ["~/code/crocodile", "~/code/machineconfig", ]
17
16
  try:
@@ -20,10 +19,10 @@ def main(verbose: bool = True) -> str:
20
19
  repos += tmp
21
20
  except (FileNotFoundError, KeyError, IndexError):
22
21
  print(f"Missing {DEFAULTS_PATH} or section [general] or key repos. Using default repos.")
23
- print(f"""It should look like this:
22
+ print("""It should look like this:
24
23
  [general]
25
24
  repos = ~/code/repo1,~/code/repo2
26
- rclone_config_name = onedriveWork
25
+ rclone_config_name = onedrivePersonal
27
26
  email_config_name = Yahoo3
28
27
  to_email = myemail@email.com
29
28
  """)
@@ -31,7 +30,8 @@ to_email = myemail@email.com
31
30
  repos_objs = []
32
31
  for a_package_path in repos:
33
32
  try:
34
- repo = install_n_import("git", "gitpython").Repo(str(P(a_package_path).expanduser()), search_parent_directories=True)
33
+ import git
34
+ repo = git.Repo(str(P(a_package_path).expanduser()), search_parent_directories=True)
35
35
  repos_objs.append(repo)
36
36
  except Exception as ex:
37
37
  print(ex)
@@ -4,7 +4,7 @@
4
4
 
5
5
 
6
6
  from crocodile.file_management import P
7
- from machineconfig.profile.create import symlink
7
+ from machineconfig.profile.create import symlink_func
8
8
  from machineconfig.utils.utils import LIBRARY_ROOT, REPO_ROOT
9
9
  import argparse
10
10
 
@@ -16,7 +16,7 @@ def main():
16
16
  # FLAGS
17
17
  parser.add_argument("--overwrite", "-o", help="Overwrite.", action="store_true") # default is False
18
18
  # optional
19
- parser.add_argument("-d", "--dest", help=f"destination folder", default="")
19
+ parser.add_argument("-d", "--dest", help="destination folder", default="")
20
20
 
21
21
  args = parser.parse_args()
22
22
  orig_path = P(args.file).expanduser().absolute()
@@ -28,9 +28,9 @@ def main():
28
28
  new_path = REPO_ROOT.joinpath(junction)
29
29
  else: new_path = P(args.dest).expanduser().absolute().create().joinpath(orig_path.name)
30
30
 
31
- symlink(this=orig_path, to_this=new_path, prioritize_to_this=args.overwrite)
31
+ symlink_func(this=orig_path, to_this=new_path, prioritize_to_this=args.overwrite)
32
32
 
33
- print(f"Map completed. To enshrine this mapping, add the following line to the mapper.toml file:")
33
+ print("Map completed. To enshrine this mapping, add the following line to the mapper.toml file:")
34
34
  print(f"nano {LIBRARY_ROOT}/symlinks/mapper.toml")
35
35
  print(f"""
36
36
  [{new_path.parent.name}]
@@ -10,7 +10,7 @@ fire
10
10
 
11
11
 
12
12
  from machineconfig.utils.utils import display_options, choose_one_option, PROGRAM_PATH, choose_ssh_host, match_file_name, sanitize_path
13
- from crocodile.file_management import P, install_n_import
13
+ from crocodile.file_management import P, install_n_import, Read
14
14
  from crocodile.core import Display, randstr
15
15
  import inspect
16
16
  import platform
@@ -19,6 +19,23 @@ from typing import Callable, Any, Optional
19
19
  import argparse
20
20
 
21
21
 
22
+ def search_for_files_of_interest(path_obj: P):
23
+ if path_obj.joinpath(".venv").exists():
24
+ path_objects = path_obj.search("*", not_in=[".venv"]).list
25
+ files: list[P] = []
26
+ for a_path_obj in path_objects:
27
+ files += search_for_files_of_interest(path_obj=a_path_obj)
28
+ return files
29
+ py_files = path_obj.search(pattern="*.py", not_in=["__init__.py"], r=True).list
30
+ ps_files = path_obj.search(pattern="*.ps1", r=True).list
31
+ sh_files = path_obj.search(pattern="*.sh", r=True).list
32
+ files = py_files + ps_files + sh_files
33
+ return files
34
+
35
+
36
+ str2obj = {"True": True, "False": False, "None": None}
37
+
38
+
22
39
  def main() -> None:
23
40
  parser = argparse.ArgumentParser()
24
41
  parser.add_argument("path", nargs='?', type=str, help="The directory containing the jobs", default=".")
@@ -37,6 +54,7 @@ def main() -> None:
37
54
  parser.add_argument("--streamlit", "-S", action="store_true", help="run as streamlit app")
38
55
  parser.add_argument("--history", "-H", action="store_true", help="choose from history")
39
56
  # parser.add_argument("--git_pull", "-g", action="store_true", help="Start by pulling the git repo")
57
+ parser.add_argument("--optimized", "-O", action="store_true", help="Run the optimized version of the function")
40
58
  parser.add_argument("--Nprocess", "-p", type=int, help="Number of processes to use", default=1)
41
59
  parser.add_argument("--kw", nargs="*", default=None, help="keyword arguments to pass to the function in the form of k1 v1 k2 v2 ...")
42
60
 
@@ -44,23 +62,21 @@ def main() -> None:
44
62
  if args.kw is not None:
45
63
  assert len(args.kw) % 2 == 0, f"args.kw must be a list of even length. Got {len(args.kw)}"
46
64
  kwargs = dict(zip(args.kw[::2], args.kw[1::2]))
65
+ for key, value in kwargs.items():
66
+ if value in str2obj:
67
+ kwargs[key] = str2obj[value]
47
68
  # print(f"kwargs = {kwargs}")
48
69
  else:
49
70
  kwargs = {}
50
71
 
51
72
  path_obj = sanitize_path(P(args.path))
52
73
  if not path_obj.exists():
53
- path_obj = match_file_name(args.path)
54
- print(path_obj)
74
+ path_obj = match_file_name(sub_string=args.path)
55
75
  else: pass
56
76
 
57
77
  if path_obj.is_dir():
58
78
  print(f"Seaching recursively for all python file in directory `{path_obj}`")
59
- py_files = path_obj.search(pattern="*.py", not_in=["__init__.py"], r=True).list
60
- ps_files = path_obj.search(pattern="*.ps1", r=True).list
61
- sh_files = path_obj.search(pattern="*.sh", r=True).list
62
- files = py_files + ps_files + sh_files
63
-
79
+ files = search_for_files_of_interest(path_obj)
64
80
  choice_file = choose_one_option(options=files, fzf=True)
65
81
  choice_file = P(choice_file)
66
82
  else:
@@ -90,12 +106,19 @@ def main() -> None:
90
106
  args.ve = get_ve_profile(choice_file)
91
107
 
92
108
  if args.streamlit:
93
- import socket
94
- try: local_ip_v4 = socket.gethostbyname(socket.gethostname() + ".local") # without .local, in linux machines, '/etc/hosts' file content, you have an IP address mapping with '127.0.1.1' to your hostname
95
- except Exception:
96
- print(f"Warning: Could not get local_ip_v4. This is probably because you are running a WSL instance") # TODO find a way to get the local_ip_v4 in WSL
97
- local_ip_v4 = socket.gethostbyname(socket.gethostname())
98
- print(f"🚀 Streamlit app is running at: http://{local_ip_v4}:8501")
109
+ from crocodile.environment import get_network_addresses
110
+ local_ip_v4 = get_network_addresses()["local_ip_v4"]
111
+ computer_name = platform.node()
112
+ port = 8501
113
+ if choice_file.parent.joinpath(".streamlit/config.toml").exists():
114
+ config = Read.toml(choice_file.parent.joinpath(".streamlit/config.toml"))
115
+ if "server" in config:
116
+ if "port" in config["server"]:
117
+ port = config["server"]["port"]
118
+ message = f"🚀 Streamlit app is running @:\n1- http://{local_ip_v4}:{port}\n2- http://{computer_name}:{port}\n3- http://localhost:{port}"
119
+ from rich.panel import Panel
120
+ from rich import print as rprint
121
+ rprint(Panel(message))
99
122
  exe = "streamlit run --server.address 0.0.0.0 --server.headless true"
100
123
  elif args.interactive is False: exe = "python"
101
124
  elif args.jupyter: exe = "jupyter-lab"
@@ -105,7 +128,7 @@ def main() -> None:
105
128
 
106
129
  if args.module or (args.debug and args.choose_function): # because debugging tools do not support choosing functions and don't interplay with fire module. So the only way to have debugging and choose function options is to import the file as a module into a new script and run the function of interest there and debug the new script.
107
130
  import_line = get_import_module_code(str(choice_file))
108
- txt: str = f"""
131
+ txt: str=f"""
109
132
  try:
110
133
  {import_line}
111
134
  except (ImportError, ModuleNotFoundError) as ex:
@@ -183,9 +206,9 @@ except ImportError as _ex:
183
206
  if "ipdb" in command: command = f"pip install ipdb\n\n{command}"
184
207
  if "pudb" in command: command = f"pip install pudb\n\n{command}"
185
208
  if platform.system() == "Windows":
186
- command = f". activate_ve {args.ve}\n\n{command}"
209
+ command = f". $HOME/scripts/activate_ve {args.ve}\n\n{command}"
187
210
  else:
188
- command = f". ~/scripts/activate_ve {args.ve}\n\n{command}"
211
+ command = f". $HOME/scripts/activate_ve {args.ve}\n\n{command}"
189
212
  else:
190
213
  # CMD equivalent
191
214
  if "ipdb" in command: command = f"pip install ipdb & {command}"
@@ -195,20 +218,22 @@ except ImportError as _ex:
195
218
 
196
219
  if args.submit_to_cloud:
197
220
  command = f"""
198
- . activate_ve {args.ve}
221
+ . $HOME/scripts/activate_ve {args.ve}
199
222
  python -m crocodile.cluster.templates.cli_click --file {choice_file} """
200
223
  if choice_function is not None: command += f"--function {choice_function} "
201
224
  try: install_n_import("clipboard").copy(command)
202
225
  except Exception as ex: print(f"Failed to copy command to clipboard. {ex}")
203
226
 
204
227
  if args.loop:
205
- command = command + f"\n" + f". {PROGRAM_PATH}"
228
+ command = command + "\n" + f". {PROGRAM_PATH}"
206
229
 
207
230
  if args.Nprocess > 1:
208
231
  lines = [f""" zellij action new-tab --name nProcess{randstr(2)}"""]
209
- command = command.replace(". activate_ve", ". ~/scripts/activate_ve")
232
+ command = command.replace(". activate_ve", ". $HOME/scripts/activate_ve")
210
233
  for an_arg in range(args.Nprocess):
211
234
  sub_command = f"{command} --idx={an_arg} --idx_max={args.Nprocess}"
235
+ if args.optimized:
236
+ sub_command = sub_command.replace("python ", "python -OO ")
212
237
  sub_command_path = P.tmpfile(suffix=".sh").write_text(sub_command)
213
238
  lines.append(f"""zellij action new-pane -- bash {sub_command_path} """)
214
239
  lines.append("sleep 1") # python tends to freeze if you launch instances within 1 microsecond of each other
@@ -216,9 +241,17 @@ python -m crocodile.cluster.templates.cli_click --file {choice_file} """
216
241
 
217
242
  # TODO: send this command to terminal history. In powershell & bash there is no way to do it with a command other than goiing to history file. In Mcfly there is a way but its linux only tool. # if platform.system() == "Windows": command = f" ({command}) | Add-History -PassThru "
218
243
  # mcfly add --exit 0 command
219
- print(f"🔥 command:\n{command}\n\n")
244
+ if args.optimized:
245
+ # note that in ipython, optimization is meaningless.
246
+ command = command.replace("python ", "python -OO ")
220
247
  # if platform.system() == "Linux":
221
248
  # command = "timeout 1s aafire -driver slang\nclear\n" + command
249
+
250
+ from rich.panel import Panel
251
+ from rich.console import Console
252
+ from rich.syntax import Syntax
253
+ console = Console()
254
+ console.print(Panel(Syntax(command, lexer="shell"), title=f"🔥 fire command @ {PROGRAM_PATH}: "), style="bold red")
222
255
  PROGRAM_PATH.write_text(command)
223
256
 
224
257
 
@@ -290,7 +323,8 @@ def interactively_run_function(func: Callable[[Any], Any]):
290
323
  if value == "": value = default
291
324
  else: value = input(f"Please enter a value for argument `{param.name}` (type = {hint}) : ")
292
325
  try:
293
- if param.annotation is not inspect.Parameter.empty: value = param.annotation(value)
326
+ if param.annotation is not inspect.Parameter.empty:
327
+ value = param.annotation
294
328
  except (TypeError, ValueError) as err:
295
329
  raise ValueError(f"Invalid input: {value} is not of type {param.annotation}") from err
296
330
  if param.kind == inspect.Parameter.KEYWORD_ONLY: kwargs[param.name] = value
@@ -315,7 +349,7 @@ def run_on_remote(func_file: str, args: argparse.Namespace):
315
349
 
316
350
  def find_repo_root_path(start_path: str) -> Optional[str]:
317
351
  root_files = ['setup.py', 'pyproject.toml', '.git']
318
- path: str = start_path
352
+ path: str=start_path
319
353
  trials = 0
320
354
  root_path = os.path.abspath(os.sep)
321
355
  while path != root_path and trials < 20:
@@ -0,0 +1,53 @@
1
+
2
+ # as per https://github.com/marketplace/models/azure-openai/o1-preview
3
+ from openai import OpenAI
4
+ from crocodile.file_management import Read, P
5
+
6
+
7
+ gh_token = Read.ini(P.home().joinpath("dotfiles/creds/git/git_host_tokens.ini"))['thisismygitrepo']['newLongterm']
8
+ endpoint = "https://models.inference.ai.azure.com"
9
+ model_name_preferences = ["o1-preview", "o1-mini", "GPT-4o", "GPT-4-o-mini"]
10
+ client__ = OpenAI(
11
+ base_url=endpoint,
12
+ api_key=gh_token,
13
+ )
14
+
15
+ def get_response(client, model_name, messages):
16
+ try:
17
+ response = client.chat.completions.create(
18
+ messages=messages,
19
+ model=model_name
20
+ )
21
+ return response.choices
22
+ except Exception as e:
23
+ print(f"Error with model {model_name}: {e}")
24
+ return None
25
+
26
+
27
+ def interactive_chat():
28
+ conversation_history = []
29
+ model_index = 0
30
+ model_name = model_name_preferences[model_index]
31
+ while True:
32
+ print(f"Using model {model_name}".center(80, "="))
33
+ while True:
34
+ user_input = input("You: ")
35
+ conversation_history.append({"role": "user", "content": user_input})
36
+
37
+ while True:
38
+ choices = get_response(client__, model_name, conversation_history)
39
+ if choices is None:
40
+ model_index += 1
41
+ model_name = model_name_preferences[model_index % len(model_name_preferences)]
42
+ print(f"Switching to model {model_name}".center(80, "="))
43
+ continue
44
+ else:
45
+ break
46
+
47
+ for a_choice in choices:
48
+ response_content = a_choice.message.content
49
+ print("\n" * 5)
50
+ print(f"AI: {response_content}")
51
+ conversation_history.append({"role": "assistant", "content": response_content})
52
+
53
+ interactive_chat()
@@ -11,7 +11,7 @@ import platform
11
11
 
12
12
 
13
13
  def main():
14
- print(f"Mounting NFS Share ... ")
14
+ print("Mounting NFS Share ... ")
15
15
  share_info = input("share path? (e.g. machine:~/data/share_nfs) [press enter for interactive choice] = ")
16
16
  if share_info == "":
17
17
  tmp = choose_ssh_host(multi=False)
@@ -6,15 +6,15 @@ import platform
6
6
 
7
7
 
8
8
  def main():
9
- print(f"Welcome to the WindowsNetworkDrive Mounting Wizard")
9
+ print("Welcome to the WindowsNetworkDrive Mounting Wizard")
10
10
  drive_location = input("Enter the network drive location (ex: //192.168.1.100/Share): ")
11
11
  machine_name = drive_location.split("//")[1].split("/")[0]
12
12
  mount_point = input(f"Enter the mount point directory (ex: /mnt/network) [default: ~/data/mount_nw/{machine_name}]: ")
13
13
  if mount_point == "": mount_point = P.home().joinpath(fr"data/mount_nw/{machine_name}")
14
14
  else: mount_point = P(mount_point).expanduser()
15
15
 
16
- username = input(f"Enter the username: ")
17
- password = input(f"Enter the password: ")
16
+ username = input("Enter the username: ")
17
+ password = input("Enter the password: ")
18
18
  if platform.system() == "Linux":
19
19
  PROGRAM_PATH.write_text(f"""
20
20
  drive_location='{drive_location}'
@@ -11,8 +11,7 @@ from machineconfig.utils.utils import PROGRAM_PATH, choose_ssh_host
11
11
 
12
12
 
13
13
  def main():
14
-
15
- print(f"Mounting SSHFS ... ")
14
+ print("Mounting SSHFS ... ")
16
15
  share_info = input("share path? (e.g. user@host:/path) [press enter for interactive choice] = ")
17
16
  if share_info == "":
18
17
  tmp = choose_ssh_host(multi=False)
@@ -28,7 +27,7 @@ def main():
28
27
  if mount_point == "": mount_point = P.home().joinpath(fr"data/mount_ssh/{ssh.hostname}")
29
28
 
30
29
  if system() == "Linux":
31
- txt = fr"""
30
+ txt = """
32
31
  sshfs alex@:/media/dbhdd /media/dbhdd\
33
32
  """
34
33
  elif system() == "Windows":
@@ -16,7 +16,7 @@ def pomodoro(work: int = 25, rest: int = 5, repeats: int = 4):
16
16
  while (diff := rest - ((datetime.now() - start).seconds / 60)) > 0: logger.critical(f"Keep Resting. Time Left: {round(diff)} minutes"); time.sleep(60 * 1)
17
17
  def speak(txt: str):
18
18
  install_n_import("gtts").gTTS(txt, lang='en', tld='com.au').save(tmp := P.tmpfile(suffix=".mp3")); time.sleep(0.5)
19
- pyglet = install_n_import("pyglet"); pyglet.resource.path = [tmp.parent.str]; pyglet.resource.reindex(); pyglet.resource.media(tmp.name).play()
19
+ pyglet = install_n_import("pyglet"); pyglet.resource.path = [tmp.parent.to_str()]; pyglet.resource.reindex(); pyglet.resource.media(tmp.name).play()
20
20
  def beep(duration: int = 1, frequency: int = 3000):
21
21
  try: import winsound
22
22
  except ImportError: __import__("os").system(f'beep -f {frequency} -l {1000 * duration}')
@@ -8,7 +8,7 @@ in the event that username@github.com is not mentioned in the remote url.
8
8
 
9
9
  from rich import print as pprint
10
10
  from machineconfig.utils.utils import write_shell_script, CONFIG_PATH, DEFAULTS_PATH
11
- from crocodile.file_management import P, install_n_import, Read, Save
11
+ from crocodile.file_management import P, Read, Save
12
12
  from crocodile.core import randstr
13
13
  import argparse
14
14
  from dataclasses import dataclass
@@ -31,7 +31,7 @@ class RepoRecord:
31
31
  version: dict[str, str]
32
32
 
33
33
 
34
- def git_action(path: P, action: GitAction, mess: Optional[str] = None, r: bool = False) -> str:
34
+ def git_action(path: P, action: GitAction, mess: Optional[str] = None, r: bool=False) -> str:
35
35
  from git.exc import InvalidGitRepositoryError
36
36
  from git.repo import Repo
37
37
  try:
@@ -57,7 +57,7 @@ git add .; git commit -am "{mess}"
57
57
  action_name = "pull" if action == GitAction.pull else "push"
58
58
  cmds = [f'echo "pulling from {remote.url}" ; git {action_name} {remote.name} {repo.active_branch.name}' for remote in repo.remotes]
59
59
  program += '\n' + '\n'.join(cmds) + '\n'
60
- program = program + f'''
60
+ program = program + '''
61
61
  echo ""; echo ""
62
62
  '''
63
63
  return program
@@ -68,41 +68,40 @@ def main():
68
68
  # POSITIONAL
69
69
  parser.add_argument("directory", help="folder containing repos to record a json out of OR a specs json file to follow.", default="")
70
70
  # FLAGS
71
- parser.add_argument("--push", help=f"push", action="store_true")
72
- parser.add_argument("--pull", help=f"pull", action="store_true")
73
- parser.add_argument("--commit", help=f"commit", action="store_true")
74
- parser.add_argument("--all", help=f"pull, commit and push", action="store_true")
75
- parser.add_argument("--record", help=f"record respos", action="store_true")
76
- parser.add_argument("--clone", help=f"clone repos from record", action="store_true")
77
- parser.add_argument("--checkout", help=f"Check out to versions prvided in this json file", action="store_true")
71
+ parser.add_argument("--push", help="push", action="store_true")
72
+ parser.add_argument("--pull", help="pull", action="store_true")
73
+ parser.add_argument("--commit", help="commit", action="store_true")
74
+ parser.add_argument("--all", help="pull, commit and push", action="store_true")
75
+ parser.add_argument("--record", help="record respos", action="store_true")
76
+ parser.add_argument("--clone", help="clone repos from record", action="store_true")
77
+ parser.add_argument("--checkout", help="Check out to versions prvided in this json file", action="store_true")
78
78
  parser.add_argument("--checkout_to_branch", help="Checkout to the main branch", action="store_true")
79
- parser.add_argument("--recursive", "-r", help=f"recursive flag", action="store_true")
79
+ parser.add_argument("--recursive", "-r", help="recursive flag", action="store_true")
80
80
  # OPTIONAL
81
- parser.add_argument("--cloud", "-c", help=f"cloud", default=None)
81
+ parser.add_argument("--cloud", "-c", help="cloud", default=None)
82
82
  args = parser.parse_args()
83
83
 
84
84
  if args.directory == "": repos_root = P.home().joinpath("code") # it is a positional argument, can never be empty.
85
85
  else: repos_root = P(args.directory).expanduser().absolute()
86
- _ = install_n_import("git", "gitpython")
87
86
 
88
87
  program = ""
89
88
  if args.record:
90
89
  res = record_repos(repos_root=str(repos_root))
91
- pprint(f"Recorded repositories:\n", res)
90
+ pprint("Recorded repositories:\n", res)
92
91
  save_path = CONFIG_PATH.joinpath("repos").joinpath(repos_root.rel2home()).joinpath("repos.json")
93
92
  # Save.pickle(obj=res, path=save_path)
94
- Save.json(obj=res, path=save_path)
93
+ Save.json(obj=res, path=save_path, indent=4)
95
94
  pprint(f"Result pickled at {P(save_path)}")
96
95
  if args.cloud is not None: P(save_path).to_cloud(rel2home=True, cloud=args.cloud)
97
- program += f"""\necho '>>>>>>>>> Finished Recording'\n"""
96
+ program += """\necho '>>>>>>>>> Finished Recording'\n"""
98
97
  elif args.clone or args.checkout or args.checkout_to_branch:
99
98
  # preferred_remote = input("Enter preferred remote to use (default: None): ") or ""
100
- program += f"""\necho '>>>>>>>>> Cloning Repos'\n"""
99
+ program += """\necho '>>>>>>>>> Cloning Repos'\n"""
101
100
  if not repos_root.exists() or repos_root.stem != 'repos.json': # user didn't pass absolute path to pickle file, but rather expected it to be in the default save location
102
101
  repos_root = CONFIG_PATH.joinpath("repos").joinpath(repos_root.rel2home()).joinpath("repos.json")
103
102
  if not repos_root.exists():
104
103
  if args.cloud is None:
105
- cloud: str = Read.ini(DEFAULTS_PATH)['general']['rclone_config_name']
104
+ cloud: str=Read.ini(DEFAULTS_PATH)['general']['rclone_config_name']
106
105
  print(f"⚠️ Using default cloud: {cloud}")
107
106
  else:
108
107
  cloud = args.cloud
@@ -122,7 +121,7 @@ def main():
122
121
  write_shell_script(program, "Script to update repos")
123
122
 
124
123
 
125
- def record_repos(repos_root: str, r: bool = True) -> list[dict[str, Any]]:
124
+ def record_repos(repos_root: str, r: bool=True) -> list[dict[str, Any]]:
126
125
  path_obj = P(repos_root).expanduser().absolute()
127
126
  if path_obj.is_file(): return []
128
127
  search_res = path_obj.search("*", files=False)
@@ -135,7 +134,7 @@ def record_repos(repos_root: str, r: bool = True) -> list[dict[str, Any]]:
135
134
  return res
136
135
 
137
136
 
138
- def record_a_repo(path: P, search_parent_directories: bool = False, preferred_remote: Optional[str] = None):
137
+ def record_a_repo(path: P, search_parent_directories: bool=False, preferred_remote: Optional[str] = None):
139
138
  from git.repo import Repo
140
139
  repo = Repo(path, search_parent_directories=search_parent_directories) # get list of remotes using git python
141
140
  repo_root = P(repo.working_dir).absolute()
@@ -160,7 +159,7 @@ def record_a_repo(path: P, search_parent_directories: bool = False, preferred_re
160
159
  return res
161
160
 
162
161
 
163
- def install_repos(specs_path: str, clone: bool = True, checkout_to_recorded_commit: bool = False, checkout_to_branch: bool = False, editable_install: bool = False, preferred_remote: Optional[str] = None):
162
+ def install_repos(specs_path: str, clone: bool=True, checkout_to_recorded_commit: bool=False, checkout_to_branch: bool=False, editable_install: bool=False, preferred_remote: Optional[str] = None):
164
163
  program = ""
165
164
  path_obj = P(specs_path).expanduser().absolute()
166
165
  repos: list[dict[str, Any]] = Read.json(path_obj)
@@ -189,7 +188,7 @@ def install_repos(specs_path: str, clone: bool = True, checkout_to_recorded_comm
189
188
  program += f"\ncd {parent_dir.collapseuser().as_posix()}/{repo['name']}; git checkout {repo['current_branch']}"
190
189
  break
191
190
  if editable_install and idx == 0:
192
- program += f"\ncd {parent_dir.collapseuser().as_posix()}/{repo['name']}; pip install -e ."
191
+ program += f"\ncd {parent_dir.collapseuser().as_posix()}/{repo['name']}; uv pip install -e ."
193
192
  program += "\n"
194
193
  pprint(program)
195
194
  return program