torizon-templates-utils 0.0.9__tar.gz → 0.0.11__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 (18) hide show
  1. {torizon_templates_utils-0.0.9 → torizon_templates_utils-0.0.11}/PKG-INFO +4 -4
  2. {torizon_templates_utils-0.0.9 → torizon_templates_utils-0.0.11}/pyproject.toml +8 -4
  3. {torizon_templates_utils-0.0.9 → torizon_templates_utils-0.0.11}/torizon_templates_utils/network.py +11 -2
  4. {torizon_templates_utils-0.0.9 → torizon_templates_utils-0.0.11}/torizon_templates_utils/tasks.py +85 -49
  5. {torizon_templates_utils-0.0.9 → torizon_templates_utils-0.0.11}/torizon_templates_utils.egg-info/PKG-INFO +4 -4
  6. {torizon_templates_utils-0.0.9 → torizon_templates_utils-0.0.11}/torizon_templates_utils.egg-info/SOURCES.txt +0 -1
  7. {torizon_templates_utils-0.0.9 → torizon_templates_utils-0.0.11}/torizon_templates_utils.egg-info/requires.txt +1 -0
  8. torizon_templates_utils-0.0.9/LICENSE +0 -23
  9. {torizon_templates_utils-0.0.9 → torizon_templates_utils-0.0.11}/README.md +0 -0
  10. {torizon_templates_utils-0.0.9 → torizon_templates_utils-0.0.11}/setup.cfg +0 -0
  11. {torizon_templates_utils-0.0.9 → torizon_templates_utils-0.0.11}/torizon_templates_utils/__init__.py +0 -0
  12. {torizon_templates_utils-0.0.9 → torizon_templates_utils-0.0.11}/torizon_templates_utils/animations.py +0 -0
  13. {torizon_templates_utils-0.0.9 → torizon_templates_utils-0.0.11}/torizon_templates_utils/args.py +0 -0
  14. {torizon_templates_utils-0.0.9 → torizon_templates_utils-0.0.11}/torizon_templates_utils/colors.py +0 -0
  15. {torizon_templates_utils-0.0.9 → torizon_templates_utils-0.0.11}/torizon_templates_utils/debug.py +0 -0
  16. {torizon_templates_utils-0.0.9 → torizon_templates_utils-0.0.11}/torizon_templates_utils/errors.py +0 -0
  17. {torizon_templates_utils-0.0.9 → torizon_templates_utils-0.0.11}/torizon_templates_utils.egg-info/dependency_links.txt +0 -0
  18. {torizon_templates_utils-0.0.9 → torizon_templates_utils-0.0.11}/torizon_templates_utils.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.2
1
+ Metadata-Version: 2.4
2
2
  Name: torizon_templates_utils
3
- Version: 0.0.9
3
+ Version: 0.0.11
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
@@ -8,13 +8,13 @@ Project-URL: Issues, https://github.com/torizon/vscode-torizon-templates/issues
8
8
  Classifier: Programming Language :: Python :: 3
9
9
  Classifier: License :: OSI Approved :: MIT License
10
10
  Classifier: Operating System :: POSIX :: Linux
11
- Requires-Python: >=3.8
11
+ Requires-Python: >=3.10
12
12
  Description-Content-Type: text/markdown
13
- License-File: LICENSE
14
13
  Requires-Dist: torizon-io-api
15
14
  Requires-Dist: requests
16
15
  Requires-Dist: pyyaml
17
16
  Requires-Dist: debugpy
17
+ Requires-Dist: pkginfo>=1.12
18
18
 
19
19
  # Torizon Templates Utils
20
20
 
@@ -1,16 +1,16 @@
1
1
  [build-system]
2
- requires = ["setuptools>=61.0"]
2
+ requires = ["setuptools>=70.0", "pkginfo>=1.12"]
3
3
  build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "torizon_templates_utils"
7
- version = "0.0.9"
7
+ version = "0.0.11"
8
8
  authors = [
9
9
  { name="Matheus Castello", email="matheus.castello@toradex.com" },
10
10
  ]
11
11
  description = "Package with utilities for Torizon Templates scripts"
12
12
  readme = "README.md"
13
- requires-python = ">=3.8"
13
+ requires-python = ">=3.10"
14
14
  classifiers = [
15
15
  "Programming Language :: Python :: 3",
16
16
  "License :: OSI Approved :: MIT License",
@@ -20,9 +20,13 @@ dependencies = [
20
20
  "torizon-io-api",
21
21
  "requests",
22
22
  "pyyaml",
23
- "debugpy"
23
+ "debugpy",
24
+ "pkginfo>=1.12"
24
25
  ]
25
26
 
27
+ [tool.setuptools]
28
+ license-files = []
29
+
26
30
  [project.urls]
27
31
  Homepage = "https://github.com/torizon/vscode-torizon-templates"
28
32
  Issues = "https://github.com/torizon/vscode-torizon-templates/issues"
@@ -6,14 +6,14 @@ import subprocess
6
6
 
7
7
  def get_host_ip():
8
8
  if 'WSL_DISTRO_NAME' in os.environ and os.environ['WSL_DISTRO_NAME'] != '':
9
- command = ["/mnt/c/Windows/System32/Wbem/WMIC.exe", "NICCONFIG", "WHERE", "IPEnabled=true", "GET", "IPAddress"]
9
+ command = ["/mnt/c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe", "-c", '(Get-NetIPAddress -AddressFamily IPv4 -InterfaceAlias (Get-NetRoute -DestinationPrefix "0.0.0.0/0").InterfaceAlias).IPAddress']
10
10
 
11
11
  # if inside a container we need to run the command in the host
12
12
  if "APOLLOX_CONTAINER" in os.environ:
13
13
  command = [
14
14
  "sudo", "nsenter", "-t", "1", "-m", "-u", "-n", "-i",
15
15
  "--",
16
- "/mnt/c/Windows/System32/Wbem/WMIC.exe", "NICCONFIG", "WHERE", "IPEnabled=true", "GET", "IPAddress"
16
+ "/mnt/c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe", "-c", '(Get-NetIPAddress -AddressFamily IPv4 -InterfaceAlias (Get-NetRoute -DestinationPrefix "0.0.0.0/0").InterfaceAlias).IPAddress'
17
17
  ]
18
18
 
19
19
  result = subprocess.run(command, capture_output=True, text=True)
@@ -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,13 +8,14 @@ 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
 
15
16
  def replace_tasks_input():
16
17
  for file in Path('.').rglob('*.json'):
17
- print(file)
18
+ print(file, flush=True)
18
19
  mime_type, _ = mimetypes.guess_type(file)
19
20
 
20
21
  if mime_type is None or mime_type.startswith("application/octet-stream"):
@@ -397,17 +398,55 @@ def get_tasks_json(file_path: str) -> TaskConfiguration:
397
398
 
398
399
 
399
400
  def get_settings_json(
400
- file_path: str,
401
- custom_file: str | None = None
401
+ file_path: str,
402
+ custom_file: str | None = None
402
403
  ) -> TorizonSettings:
403
404
  _file = custom_file if custom_file else "settings.json"
405
+ local_settings_path = Path(file_path) / ".vscode" / _file
406
+
407
+ try:
408
+ with open(local_settings_path, 'r') as file:
409
+ local_settings = json.load(file)
410
+ except FileNotFoundError:
411
+ print(f"No local settings file found at {local_settings_path}")
412
+ local_settings = {}
413
+ except json.JSONDecodeError as e:
414
+ raise ValueError(f"Invalid JSON in settings file: {e}")
415
+
416
+ workspace_settings = {}
417
+ parent_dir = Path(file_path).parent
418
+ # First check for .code-workspace files directly inside the parent
419
+ for child in parent_dir.glob("*.code-workspace"):
420
+ try:
421
+ with open(child, "r") as ws_file:
422
+ data = json.load(ws_file)
423
+ if "settings" in data:
424
+ print(f"Merging settings from: {child}")
425
+ workspace_settings = data["settings"]
426
+ break
427
+ except Exception as e:
428
+ print(f"Error reading {child}: {e}")
429
+
430
+ # If not found, scan folders in parent_dir
431
+ if not workspace_settings:
432
+ for sub in parent_dir.iterdir():
433
+ if sub.is_dir():
434
+ for child in sub.glob("*.code-workspace"):
435
+ try:
436
+ with open(child, "r") as ws_file:
437
+ data = json.load(ws_file)
438
+ if "settings" in data:
439
+ print(f"Merging settings from: {child}")
440
+ workspace_settings = data["settings"]
441
+ break
442
+ except Exception as e:
443
+ print(f"Error reading {child}: {e}")
444
+ if workspace_settings:
445
+ break
404
446
 
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
447
+ # Merge with local settings taking precedence
448
+ combined = {**workspace_settings, **local_settings}
449
+ return _cast_from_json(combined, TorizonSettings)
411
450
 
412
451
 
413
452
  class TaskRunner:
@@ -428,12 +467,12 @@ class TaskRunner:
428
467
  self.__settings = settings
429
468
  self.__debug = debug
430
469
  self.__gitlab_ci = False
431
- self.__override_env = False
470
+ self.__tasks_override_env = False
432
471
  self.__cli_inputs: Dict[str, str] = {}
433
472
  self.__can_receive_interactive_input = False
434
473
 
435
474
  # check if we have stdin
436
- if os.isatty(0) and ("TASKS_DISABLE_INTERACTIVE_INPUT" not in os.environ):
475
+ if os.isatty(0) and (("TASKS_DISABLE_INTERACTIVE_INPUT" not in os.environ) or (os.environ["TASKS_DISABLE_INTERACTIVE_INPUT"] != "True")):
437
476
  self.__can_receive_interactive_input = True
438
477
 
439
478
  # environment configs
@@ -443,10 +482,10 @@ class TaskRunner:
443
482
  if "GITLAB_CI" in os.environ:
444
483
  self.__gitlab_ci = True
445
484
 
446
- if "TASKS_OVERRIDE_ENV" in os.environ:
447
- self.__override_env = True
485
+ if "TASKS_OVERRIDE_ENV" in os.environ and os.environ["TASKS_OVERRIDE_ENV"] == "True":
486
+ self.__tasks_override_env = True
448
487
 
449
- if "TASKS_DEBUG" in os.environ:
488
+ if "TASKS_DEBUG" in os.environ and os.environ["TASKS_DEBUG"] == "True":
450
489
  self.__debug = True
451
490
 
452
491
  self.__settings_to_env()
@@ -473,10 +512,10 @@ class TaskRunner:
473
512
  for task in self.__tasks:
474
513
  if no_index:
475
514
  if show_hidden or not task.hide:
476
- print(task.label)
515
+ print(task.label, flush=True)
477
516
  else:
478
517
  if show_hidden or not task.hide:
479
- print(f"{i}. \t{task.label}")
518
+ print(f"{i}. \t{task.label}", flush=True)
480
519
 
481
520
  i += 1
482
521
 
@@ -503,7 +542,7 @@ class TaskRunner:
503
542
 
504
543
  if task is not None:
505
544
  task_txt = json.dumps(task.to_dict(), indent=4)
506
- print(task_txt)
545
+ print(task_txt, flush=True)
507
546
  else:
508
547
  raise ReferenceError(f"Task with index [{label}] not found")
509
548
 
@@ -558,7 +597,7 @@ class TaskRunner:
558
597
  _p_ret = subprocess.run(
559
598
  [
560
599
  "xonsh",
561
- "./conf/torizon-io.xsh",
600
+ "./.conf/torizon-io.xsh",
562
601
  "package", "latest", "version",
563
602
  os.environ["config:tcb_packageName"]
564
603
  ],
@@ -585,7 +624,7 @@ class TaskRunner:
585
624
  raise ValueError(f"Package version should be in one of the following formats: <int>, <string-int>, <major.minor.patch>, or <string-major.minor.patch>. Depending on format, int or patch value will be incremented")
586
625
 
587
626
  if self.__debug:
588
- print(f"Next package version: {_next}")
627
+ print(f"Next package version: {_next}", flush=True)
589
628
 
590
629
  value = value.replace(f"${{command:tcb.getNextPackageVersion}}", f"{_next}")
591
630
 
@@ -797,8 +836,8 @@ class TaskRunner:
797
836
  exp_value_str = " ".join(expvalue)
798
837
 
799
838
  if self.__debug:
800
- print(f"Env: {env}={_env_value}", color=Color.YELLOW)
801
- print(f"Parsed Env: {env}={exp_value_str}", color=Color.YELLOW)
839
+ print(f"Env: {env}={_env_value}", color=Color.YELLOW, flush=True)
840
+ print(f"Parsed Env: {env}={exp_value_str}", color=Color.YELLOW, flush=True)
802
841
 
803
842
  return exp_value_str
804
843
 
@@ -806,7 +845,7 @@ class TaskRunner:
806
845
 
807
846
 
808
847
  def __replace_docker_host(self, arg: str) -> str:
809
- if "DOCKER_HOST" in arg:
848
+ if "DOCKER_HOST" in arg and is_in_docker_container():
810
849
  arg = arg.replace("DOCKER_HOST=", "DOCKER_HOST=tcp://docker:2375")
811
850
 
812
851
  return arg
@@ -835,6 +874,16 @@ class TaskRunner:
835
874
  if _task is None:
836
875
  raise ReferenceError(f"Task with label [{label}] not found")
837
876
 
877
+ _depends = []
878
+ if _task.dependsOn is not None:
879
+ _depends = _task.dependsOn
880
+
881
+ # first we need to run the dependencies
882
+ for dep in _depends:
883
+ self.run_task(dep)
884
+
885
+ print(f"> Executing task: {label} <", color=Color.GREEN, flush=True)
886
+
838
887
  # prepare the command
839
888
  _cmd = _task.command
840
889
 
@@ -858,16 +907,6 @@ class TaskRunner:
858
907
  _env = _task.options.env
859
908
  _cwd = _task.options.cwd
860
909
 
861
- _depends = []
862
- if _task.dependsOn is not None:
863
- _depends = _task.dependsOn
864
-
865
- # first we need to run the dependencies
866
- for dep in _depends:
867
- self.run_task(dep)
868
-
869
- print(f"> Executing task: {label} <", color=Color.GREEN)
870
-
871
910
  _is_background = ""
872
911
  if _task.isBackground:
873
912
  _is_background = " &"
@@ -894,18 +933,15 @@ class TaskRunner:
894
933
  if self.__gitlab_ci:
895
934
  _cmd = self.__replace_docker_host(_cmd)
896
935
 
897
- # inject env
936
+ task_env = os.environ.copy()
937
+ # If TASKS_OVERRIDE_ENV is true, override the env vars with the
938
+ # env var values present on the task. If false, set just the env vars
939
+ # present on the task that doesn't already exist on the env var
898
940
  if _env is not None:
899
- for env, value in _env.items():
900
- if self.__override_env:
901
- if env not in os.environ:
902
- __env = self.__parse_envs(env, _task)
903
- if __env:
904
- os.environ[env] = __env
905
- else:
906
- __env = self.__parse_envs(env, _task)
907
- if __env:
908
- os.environ[env] = __env
941
+ for env, _ in _env.items():
942
+ if self.__tasks_override_env == True or env not in os.environ:
943
+ __parsed_env_value = self.__parse_envs(env, _task)
944
+ task_env[env] = __parsed_env_value
909
945
 
910
946
  # we need to change the cwd if it's set
911
947
  if _cwd is not None:
@@ -919,10 +955,10 @@ class TaskRunner:
919
955
  _cmd_join = f"{_cmd} {' '.join(_args)}{_is_background}"
920
956
 
921
957
  if self.__debug:
922
- print(f"Command: {_task.command}", color=Color.YELLOW)
923
- print(f"Args: {_task.args}", color=Color.YELLOW)
924
- print(f"Parsed Args: {_args}", color=Color.YELLOW)
925
- print(f"Parsed Command: {_cmd_join}", color=Color.YELLOW)
958
+ print(f"Command: {_task.command}", color=Color.YELLOW, flush=True)
959
+ print(f"Args: {_task.args}", color=Color.YELLOW, flush=True)
960
+ print(f"Parsed Args: {_args}", color=Color.YELLOW, flush=True)
961
+ print(f"Parsed Command: {_cmd_join}", color=Color.YELLOW, flush=True)
926
962
 
927
963
  # use bash to execute the VSCode tasks commands and scripts, as they
928
964
  # are written and tested in bash. Valid just for commands of shell
@@ -931,7 +967,7 @@ class TaskRunner:
931
967
  [_cmd, *_args] if not _shell else _cmd_join,
932
968
  stdout=None,
933
969
  stderr=None,
934
- env=os.environ,
970
+ env=task_env,
935
971
  shell=_shell,
936
972
  executable="/bin/bash" if _shell else None
937
973
  )
@@ -940,5 +976,5 @@ class TaskRunner:
940
976
  os.chdir(_last_cwd)
941
977
 
942
978
  if _ret.returncode != 0:
943
- print(f"> TASK [{label}] exited with error code [{_ret.returncode}] <", color=Color.RED)
979
+ print(f"> TASK [{label}] exited with error code [{_ret.returncode}] <", color=Color.RED, flush=True)
944
980
  raise RuntimeError(f"Error running task: {label}")
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.2
1
+ Metadata-Version: 2.4
2
2
  Name: torizon_templates_utils
3
- Version: 0.0.9
3
+ Version: 0.0.11
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
@@ -8,13 +8,13 @@ Project-URL: Issues, https://github.com/torizon/vscode-torizon-templates/issues
8
8
  Classifier: Programming Language :: Python :: 3
9
9
  Classifier: License :: OSI Approved :: MIT License
10
10
  Classifier: Operating System :: POSIX :: Linux
11
- Requires-Python: >=3.8
11
+ Requires-Python: >=3.10
12
12
  Description-Content-Type: text/markdown
13
- License-File: LICENSE
14
13
  Requires-Dist: torizon-io-api
15
14
  Requires-Dist: requests
16
15
  Requires-Dist: pyyaml
17
16
  Requires-Dist: debugpy
17
+ Requires-Dist: pkginfo>=1.12
18
18
 
19
19
  # Torizon Templates Utils
20
20
 
@@ -1,4 +1,3 @@
1
- LICENSE
2
1
  README.md
3
2
  pyproject.toml
4
3
  torizon_templates_utils/__init__.py
@@ -2,3 +2,4 @@ torizon-io-api
2
2
  requests
3
3
  pyyaml
4
4
  debugpy
5
+ pkginfo>=1.12
@@ -1,23 +0,0 @@
1
- The MIT License (MIT)
2
-
3
- Copyright (c) Toradex AG 2024
4
-
5
- All rights reserved.
6
-
7
- Permission is hereby granted, free of charge, to any person obtaining a copy
8
- of this software and associated documentation files (the "Software"), to deal
9
- in the Software without restriction, including without limitation the rights
10
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
- copies of the Software, and to permit persons to whom the Software is
12
- furnished to do so, subject to the following conditions:
13
-
14
- The above copyright notice and this permission notice shall be included in all
15
- copies or substantial portions of the Software.
16
-
17
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
- SOFTWARE.