torizon-templates-utils 0.0.10__tar.gz → 1.0.0__tar.gz

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.
Files changed (17) hide show
  1. {torizon_templates_utils-0.0.10 → torizon_templates_utils-1.0.0}/PKG-INFO +1 -1
  2. {torizon_templates_utils-0.0.10 → torizon_templates_utils-1.0.0}/pyproject.toml +1 -1
  3. {torizon_templates_utils-0.0.10 → torizon_templates_utils-1.0.0}/torizon_templates_utils/network.py +9 -0
  4. {torizon_templates_utils-0.0.10 → torizon_templates_utils-1.0.0}/torizon_templates_utils/tasks.py +104 -15
  5. {torizon_templates_utils-0.0.10 → torizon_templates_utils-1.0.0}/torizon_templates_utils.egg-info/PKG-INFO +1 -1
  6. {torizon_templates_utils-0.0.10 → torizon_templates_utils-1.0.0}/README.md +0 -0
  7. {torizon_templates_utils-0.0.10 → torizon_templates_utils-1.0.0}/setup.cfg +0 -0
  8. {torizon_templates_utils-0.0.10 → torizon_templates_utils-1.0.0}/torizon_templates_utils/__init__.py +0 -0
  9. {torizon_templates_utils-0.0.10 → torizon_templates_utils-1.0.0}/torizon_templates_utils/animations.py +0 -0
  10. {torizon_templates_utils-0.0.10 → torizon_templates_utils-1.0.0}/torizon_templates_utils/args.py +0 -0
  11. {torizon_templates_utils-0.0.10 → torizon_templates_utils-1.0.0}/torizon_templates_utils/colors.py +0 -0
  12. {torizon_templates_utils-0.0.10 → torizon_templates_utils-1.0.0}/torizon_templates_utils/debug.py +0 -0
  13. {torizon_templates_utils-0.0.10 → torizon_templates_utils-1.0.0}/torizon_templates_utils/errors.py +0 -0
  14. {torizon_templates_utils-0.0.10 → torizon_templates_utils-1.0.0}/torizon_templates_utils.egg-info/SOURCES.txt +0 -0
  15. {torizon_templates_utils-0.0.10 → torizon_templates_utils-1.0.0}/torizon_templates_utils.egg-info/dependency_links.txt +0 -0
  16. {torizon_templates_utils-0.0.10 → torizon_templates_utils-1.0.0}/torizon_templates_utils.egg-info/requires.txt +0 -0
  17. {torizon_templates_utils-0.0.10 → torizon_templates_utils-1.0.0}/torizon_templates_utils.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: torizon_templates_utils
3
- Version: 0.0.10
3
+ Version: 1.0.0
4
4
  Summary: Package with utilities for Torizon Templates scripts
5
5
  Author-email: Matheus Castello <matheus.castello@toradex.com>
6
6
  Project-URL: Homepage, https://github.com/torizon/vscode-torizon-templates
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "torizon_templates_utils"
7
- version = "0.0.10"
7
+ version = "1.0.0"
8
8
  authors = [
9
9
  { name="Matheus Castello", email="matheus.castello@toradex.com" },
10
10
  ]
@@ -33,3 +33,12 @@ def get_host_ip():
33
33
 
34
34
  result = subprocess.run(command, capture_output=True, text=True)
35
35
  return result.stdout.split()[0]
36
+
37
+
38
+ def is_in_docker_container():
39
+ return os.path.exists("/.dockerenv")
40
+
41
+
42
+ def is_in_gitlab_ci_container():
43
+ return "GITLAB_CI" in os.environ and is_in_docker_container()
44
+
@@ -8,10 +8,17 @@ import mimetypes
8
8
  import subprocess
9
9
  from pathlib import Path
10
10
  from typing import List, Dict, Type, TypeVar, Union, Tuple, Optional, Literal
11
+ from torizon_templates_utils.network import is_in_docker_container
11
12
  from torizon_templates_utils.colors import print, Color
12
13
 
13
14
  T = TypeVar('T')
14
15
 
16
+ REPLACE_WHITELIST = [
17
+ "torizon_",
18
+ "docker_",
19
+ "inputBox-"
20
+ ]
21
+
15
22
  def replace_tasks_input():
16
23
  for file in Path('.').rglob('*.json'):
17
24
  print(file, flush=True)
@@ -22,9 +29,9 @@ def replace_tasks_input():
22
29
  with open(file, 'r') as f:
23
30
  content = f.read()
24
31
 
25
- content = content.replace("input:dockerLogin", "command:docker_login")
26
- content = content.replace("input:dockerImageRegistry", "command:docker_registry")
27
- content = content.replace("input:dockerPsswd", "command:docker_password")
32
+ content = content.replace("input:dockerLogin", "command:docker_login.__change__")
33
+ content = content.replace("input:dockerImageRegistry", "command:inputBox-docker_registry.__change__")
34
+ content = content.replace("input:dockerPsswd", "command:docker_password.__change__")
28
35
 
29
36
  with open(file, 'w') as f:
30
37
  f.write(content)
@@ -397,17 +404,55 @@ def get_tasks_json(file_path: str) -> TaskConfiguration:
397
404
 
398
405
 
399
406
  def get_settings_json(
400
- file_path: str,
401
- custom_file: str | None = None
407
+ file_path: str,
408
+ custom_file: str | None = None
402
409
  ) -> TorizonSettings:
403
410
  _file = custom_file if custom_file else "settings.json"
411
+ local_settings_path = Path(file_path) / ".vscode" / _file
412
+
413
+ try:
414
+ with open(local_settings_path, 'r') as file:
415
+ local_settings = json.load(file)
416
+ except FileNotFoundError:
417
+ print(f"No local settings file found at {local_settings_path}")
418
+ local_settings = {}
419
+ except json.JSONDecodeError as e:
420
+ raise ValueError(f"Invalid JSON in settings file: {e}")
421
+
422
+ workspace_settings = {}
423
+ parent_dir = Path(file_path).parent
424
+ # First check for .code-workspace files directly inside the parent
425
+ for child in parent_dir.glob("*.code-workspace"):
426
+ try:
427
+ with open(child, "r") as ws_file:
428
+ data = json.load(ws_file)
429
+ if "settings" in data:
430
+ print(f"Merging settings from: {child}")
431
+ workspace_settings = data["settings"]
432
+ break
433
+ except Exception as e:
434
+ print(f"Error reading {child}: {e}")
435
+
436
+ # If not found, scan folders in parent_dir
437
+ if not workspace_settings:
438
+ for sub in parent_dir.iterdir():
439
+ if sub.is_dir():
440
+ for child in sub.glob("*.code-workspace"):
441
+ try:
442
+ with open(child, "r") as ws_file:
443
+ data = json.load(ws_file)
444
+ if "settings" in data:
445
+ print(f"Merging settings from: {child}")
446
+ workspace_settings = data["settings"]
447
+ break
448
+ except Exception as e:
449
+ print(f"Error reading {child}: {e}")
450
+ if workspace_settings:
451
+ break
404
452
 
405
- with open(f"{file_path}/.vscode/{_file}", 'r') as file:
406
- _tor_settings = _cast_from_json(json.load(file), TorizonSettings)
407
-
408
-
409
-
410
- return _tor_settings
453
+ # Merge with local settings taking precedence
454
+ combined = {**workspace_settings, **local_settings}
455
+ return _cast_from_json(combined, TorizonSettings)
411
456
 
412
457
 
413
458
  class TaskRunner:
@@ -437,8 +482,8 @@ class TaskRunner:
437
482
  self.__can_receive_interactive_input = True
438
483
 
439
484
  # environment configs
440
- if "DOCKER_PSSWD" in os.environ:
441
- os.environ["config:docker_password"] = os.environ["DOCKER_PSSWD"]
485
+ if "DOCKER_PASSWORD" in os.environ:
486
+ os.environ["config:docker_password"] = os.environ["DOCKER_PASSWORD"]
442
487
 
443
488
  if "GITLAB_CI" in os.environ:
444
489
  self.__gitlab_ci = True
@@ -531,7 +576,42 @@ class TaskRunner:
531
576
 
532
577
  for value in env:
533
578
  if "${command:torizon_" in value:
579
+ # here is not needed to clean the torizon_<prop>.<project_name>
580
+ # because this will be handled on the cmd args check
534
581
  value = value.replace("${command:torizon_", "${config:torizon_")
582
+
583
+ ret.append(value)
584
+
585
+ return ret
586
+
587
+
588
+ def __check_input_boxes(self, env: List[str]) -> List[str]:
589
+ ret: List[str] = []
590
+
591
+ for value in env:
592
+ value = value.replace("${command:inputBox-", "${config:")
593
+ ret.append(value)
594
+
595
+ return ret
596
+
597
+
598
+ def __check_cmd_args(self, env: List[str]) -> List[str]:
599
+ ret: List[str] = []
600
+
601
+ for value in env:
602
+ for whitelisted_start in REPLACE_WHITELIST:
603
+ if value.startswith("${command:" + whitelisted_start) or value.startswith("${config:" + whitelisted_start):
604
+
605
+ if "." in value:
606
+ value_p1, value_p2 = value.split(".", 1)
607
+ ret_p2 = value_p2.split("}", 1)
608
+
609
+ if len(ret_p2) > 1:
610
+ value = f"{value_p1}}}{ret_p2[1]}"
611
+ else:
612
+ value = f"{value_p1}}}"
613
+ break
614
+
535
615
  ret.append(value)
536
616
 
537
617
  return ret
@@ -788,7 +868,9 @@ class TaskRunner:
788
868
 
789
869
  if _env_value:
790
870
  expvalue = [_env_value]
871
+ expvalue = self.__check_cmd_args(expvalue)
791
872
  expvalue = self.__check_workspace_folder(expvalue)
873
+ expvalue = self.__check_input_boxes(expvalue)
792
874
  expvalue = self.__check_torizon_inputs(expvalue)
793
875
  expvalue = self.__check_docker_inputs(expvalue)
794
876
  expvalue = self.__check_tcb_inputs(expvalue)
@@ -806,7 +888,7 @@ class TaskRunner:
806
888
 
807
889
 
808
890
  def __replace_docker_host(self, arg: str) -> str:
809
- if "DOCKER_HOST" in arg:
891
+ if "DOCKER_HOST" in arg and is_in_docker_container():
810
892
  arg = arg.replace("DOCKER_HOST=", "DOCKER_HOST=tcp://docker:2375")
811
893
 
812
894
  return arg
@@ -849,7 +931,9 @@ class TaskRunner:
849
931
  _cmd = _task.command
850
932
 
851
933
  # the cmd itself can use the mechanism to replace stuff
934
+ _cmd = self.__check_cmd_args([_cmd])[0]
852
935
  _cmd = self.__check_workspace_folder([_cmd])[0]
936
+ _cmd = self.__check_input_boxes([_cmd])[0]
853
937
  _cmd = self.__check_torizon_inputs([_cmd])[0]
854
938
  _cmd = self.__check_docker_inputs([_cmd])[0]
855
939
  _cmd = self.__check_tcb_inputs([_cmd])[0]
@@ -877,7 +961,9 @@ class TaskRunner:
877
961
  # FIXME: The scape args was in the powershell implementation
878
962
  # but when used on Python it generates weird behavior
879
963
  # _args = self.__scape_args(_args)
964
+ _args = self.__check_cmd_args(_args)
880
965
  _args = self.__check_workspace_folder(_args)
966
+ _args = self.__check_input_boxes(_args)
881
967
  _args = self.__check_torizon_inputs(_args)
882
968
  _args = self.__check_docker_inputs(_args)
883
969
  _args = self.__check_tcb_inputs(_args)
@@ -885,9 +971,12 @@ class TaskRunner:
885
971
  _args = self.__check_vscode_env(_args)
886
972
  _args = self.__check_config(_args)
887
973
  _args = self.__check_workspace_folder(_args)
974
+
975
+ if _shell:
976
+ _args = self.__check_long_args(_args)
977
+
888
978
  # FIXME: These was in the powershell implementation
889
979
  # but when used on Python it generates weird behavior
890
- # _args = self.__check_long_args(_args)
891
980
  # _args = self.__quoting_special_chars(_args)
892
981
 
893
982
  # if in gitlab ci env we need to replace the DOCKER_HOST
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: torizon_templates_utils
3
- Version: 0.0.10
3
+ Version: 1.0.0
4
4
  Summary: Package with utilities for Torizon Templates scripts
5
5
  Author-email: Matheus Castello <matheus.castello@toradex.com>
6
6
  Project-URL: Homepage, https://github.com/torizon/vscode-torizon-templates