torizon-templates-utils 0.0.8__tar.gz → 0.0.10__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.8 → torizon_templates_utils-0.0.10}/PKG-INFO +4 -4
  2. {torizon_templates_utils-0.0.8 → torizon_templates_utils-0.0.10}/pyproject.toml +8 -4
  3. {torizon_templates_utils-0.0.8 → torizon_templates_utils-0.0.10}/torizon_templates_utils/errors.py +5 -1
  4. {torizon_templates_utils-0.0.8 → torizon_templates_utils-0.0.10}/torizon_templates_utils/network.py +2 -2
  5. {torizon_templates_utils-0.0.8 → torizon_templates_utils-0.0.10}/torizon_templates_utils/tasks.py +56 -48
  6. {torizon_templates_utils-0.0.8 → torizon_templates_utils-0.0.10}/torizon_templates_utils.egg-info/PKG-INFO +4 -4
  7. {torizon_templates_utils-0.0.8 → torizon_templates_utils-0.0.10}/torizon_templates_utils.egg-info/SOURCES.txt +0 -1
  8. {torizon_templates_utils-0.0.8 → torizon_templates_utils-0.0.10}/torizon_templates_utils.egg-info/requires.txt +1 -0
  9. torizon_templates_utils-0.0.8/LICENSE +0 -23
  10. {torizon_templates_utils-0.0.8 → torizon_templates_utils-0.0.10}/README.md +0 -0
  11. {torizon_templates_utils-0.0.8 → torizon_templates_utils-0.0.10}/setup.cfg +0 -0
  12. {torizon_templates_utils-0.0.8 → torizon_templates_utils-0.0.10}/torizon_templates_utils/__init__.py +0 -0
  13. {torizon_templates_utils-0.0.8 → torizon_templates_utils-0.0.10}/torizon_templates_utils/animations.py +0 -0
  14. {torizon_templates_utils-0.0.8 → torizon_templates_utils-0.0.10}/torizon_templates_utils/args.py +0 -0
  15. {torizon_templates_utils-0.0.8 → torizon_templates_utils-0.0.10}/torizon_templates_utils/colors.py +0 -0
  16. {torizon_templates_utils-0.0.8 → torizon_templates_utils-0.0.10}/torizon_templates_utils/debug.py +0 -0
  17. {torizon_templates_utils-0.0.8 → torizon_templates_utils-0.0.10}/torizon_templates_utils.egg-info/dependency_links.txt +0 -0
  18. {torizon_templates_utils-0.0.8 → torizon_templates_utils-0.0.10}/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.8
3
+ Version: 0.0.10
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.8"
7
+ version = "0.0.10"
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"
@@ -11,7 +11,8 @@ class _error_struct:
11
11
  self.code = code
12
12
  self.message = message
13
13
 
14
-
14
+ # Standard Unix errors. There may be other standard error codes also:
15
+ # https://github.com/kaushalparikh/nuttx/blob/master/include/errno.h
15
16
  class Error(Enum):
16
17
  ENOCONF = _error_struct(
17
18
  1, "Not configured"
@@ -28,6 +29,9 @@ class Error(Enum):
28
29
  EABORT = _error_struct(
29
30
  170, "Abort"
30
31
  )
32
+ ETASKEXEC = _error_struct(
33
+ 310, "Task execution error"
34
+ )
31
35
  ENOFOUND = _error_struct(
32
36
  404, "Not found"
33
37
  )
@@ -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)
@@ -14,7 +14,7 @@ T = TypeVar('T')
14
14
 
15
15
  def replace_tasks_input():
16
16
  for file in Path('.').rglob('*.json'):
17
- print(file)
17
+ print(file, flush=True)
18
18
  mime_type, _ = mimetypes.guess_type(file)
19
19
 
20
20
  if mime_type is None or mime_type.startswith("application/octet-stream"):
@@ -428,12 +428,12 @@ class TaskRunner:
428
428
  self.__settings = settings
429
429
  self.__debug = debug
430
430
  self.__gitlab_ci = False
431
- self.__override_env = True
431
+ self.__tasks_override_env = False
432
432
  self.__cli_inputs: Dict[str, str] = {}
433
433
  self.__can_receive_interactive_input = False
434
434
 
435
435
  # check if we have stdin
436
- if os.isatty(0) and ("TASKS_DISABLE_INTERACTIVE_INPUT" not in os.environ):
436
+ if os.isatty(0) and (("TASKS_DISABLE_INTERACTIVE_INPUT" not in os.environ) or (os.environ["TASKS_DISABLE_INTERACTIVE_INPUT"] != "True")):
437
437
  self.__can_receive_interactive_input = True
438
438
 
439
439
  # environment configs
@@ -443,10 +443,10 @@ class TaskRunner:
443
443
  if "GITLAB_CI" in os.environ:
444
444
  self.__gitlab_ci = True
445
445
 
446
- if "TASKS_OVERRIDE_ENV" in os.environ:
447
- self.__override_env = False
446
+ if "TASKS_OVERRIDE_ENV" in os.environ and os.environ["TASKS_OVERRIDE_ENV"] == "True":
447
+ self.__tasks_override_env = True
448
448
 
449
- if "TASKS_DEBUG" in os.environ:
449
+ if "TASKS_DEBUG" in os.environ and os.environ["TASKS_DEBUG"] == "True":
450
450
  self.__debug = True
451
451
 
452
452
  self.__settings_to_env()
@@ -473,10 +473,10 @@ class TaskRunner:
473
473
  for task in self.__tasks:
474
474
  if no_index:
475
475
  if show_hidden or not task.hide:
476
- print(task.label)
476
+ print(task.label, flush=True)
477
477
  else:
478
478
  if show_hidden or not task.hide:
479
- print(f"{i}. \t{task.label}")
479
+ print(f"{i}. \t{task.label}", flush=True)
480
480
 
481
481
  i += 1
482
482
 
@@ -503,7 +503,7 @@ class TaskRunner:
503
503
 
504
504
  if task is not None:
505
505
  task_txt = json.dumps(task.to_dict(), indent=4)
506
- print(task_txt)
506
+ print(task_txt, flush=True)
507
507
  else:
508
508
  raise ReferenceError(f"Task with index [{label}] not found")
509
509
 
@@ -558,25 +558,36 @@ class TaskRunner:
558
558
  _p_ret = subprocess.run(
559
559
  [
560
560
  "xonsh",
561
- "./conf/torizon-io.xsh",
561
+ "./.conf/torizon-io.xsh",
562
562
  "package", "latest", "version",
563
563
  os.environ["config:tcb_packageName"]
564
564
  ],
565
565
  capture_output=True,
566
- text=True
566
+ text=True,
567
+ env=os.environ
567
568
  )
568
569
 
569
570
  if _p_ret.returncode != 0:
570
- raise RuntimeError(f"Error running torizon-io.xsh: {_p_ret.stderr}")
571
-
572
- _next = int(_p_ret.stdout.strip()) +1
571
+ # Sometimes the error is presented on stdout and not stderr
572
+ raise RuntimeError(f"Error running torizon-io.xsh: {_p_ret}")
573
+
574
+ # TODO: Maybe not use this and instead disable colors on the terminal
575
+ # Remove ANSI escape sequences. Regex from this thread:
576
+ # https://stackoverflow.com/questions/14693701/how-can-i-remove-the-ansi-escape-sequences-from-a-string-in-python
577
+ ansi_escape = re.compile(r'\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])')
578
+ _latest_ver = ansi_escape.sub('', _p_ret.stdout.strip())
579
+
580
+ _latest_ver_number = _latest_ver.rsplit('-', 1)[-1]
581
+ _latest_ver_last_number = _latest_ver_number.rsplit('.', 1)[-1]
582
+ try:
583
+ _next = int(_latest_ver_last_number) +1
584
+ except:
585
+ 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")
573
586
 
574
587
  if self.__debug:
575
- print(f"Next package version: {_next}")
588
+ print(f"Next package version: {_next}", flush=True)
576
589
 
577
- ret.append(
578
- value.replace("${{command:tcb.getNextPackageVersion}}", f"{_next}")
579
- )
590
+ value = value.replace(f"${{command:tcb.getNextPackageVersion}}", f"{_next}")
580
591
 
581
592
  elif "tcb.outputTEZIFolder" in value:
582
593
  # load the tcbuild.yaml
@@ -589,7 +600,7 @@ class TaskRunner:
589
600
  except KeyError:
590
601
  raise RuntimeError("Error replacing variable tcb.outputTEZIFolder, make sure the tcbuild.yaml has the output.easy-installer.local property")
591
602
 
592
- value = value.replace("${{command:tcb.outputTEZIFolder}}", _tezi_folder)
603
+ value = value.replace(f"${{command:tcb.outputTEZIFolder}}", _tezi_folder)
593
604
 
594
605
  # for all the items we need to replace ${command:tcb. with ${config:tcb.
595
606
  _pattern = r"(?<=\$\{command:tcb\.).*?(?=\s*})"
@@ -786,8 +797,8 @@ class TaskRunner:
786
797
  exp_value_str = " ".join(expvalue)
787
798
 
788
799
  if self.__debug:
789
- print(f"Env: {env}={_env_value}", color=Color.YELLOW)
790
- print(f"Parsed Env: {env}={exp_value_str}", color=Color.YELLOW)
800
+ print(f"Env: {env}={_env_value}", color=Color.YELLOW, flush=True)
801
+ print(f"Parsed Env: {env}={exp_value_str}", color=Color.YELLOW, flush=True)
791
802
 
792
803
  return exp_value_str
793
804
 
@@ -824,6 +835,16 @@ class TaskRunner:
824
835
  if _task is None:
825
836
  raise ReferenceError(f"Task with label [{label}] not found")
826
837
 
838
+ _depends = []
839
+ if _task.dependsOn is not None:
840
+ _depends = _task.dependsOn
841
+
842
+ # first we need to run the dependencies
843
+ for dep in _depends:
844
+ self.run_task(dep)
845
+
846
+ print(f"> Executing task: {label} <", color=Color.GREEN, flush=True)
847
+
827
848
  # prepare the command
828
849
  _cmd = _task.command
829
850
 
@@ -847,16 +868,6 @@ class TaskRunner:
847
868
  _env = _task.options.env
848
869
  _cwd = _task.options.cwd
849
870
 
850
- _depends = []
851
- if _task.dependsOn is not None:
852
- _depends = _task.dependsOn
853
-
854
- # first we need to run the dependencies
855
- for dep in _depends:
856
- self.run_task(dep)
857
-
858
- print(f"> Executing task: {label} <", color=Color.GREEN)
859
-
860
871
  _is_background = ""
861
872
  if _task.isBackground:
862
873
  _is_background = " &"
@@ -883,18 +894,15 @@ class TaskRunner:
883
894
  if self.__gitlab_ci:
884
895
  _cmd = self.__replace_docker_host(_cmd)
885
896
 
886
- # inject env
897
+ task_env = os.environ.copy()
898
+ # If TASKS_OVERRIDE_ENV is true, override the env vars with the
899
+ # env var values present on the task. If false, set just the env vars
900
+ # present on the task that doesn't already exist on the env var
887
901
  if _env is not None:
888
- for env, value in _env.items():
889
- if self.__override_env:
890
- __env = self.__parse_envs(env, _task)
891
- if __env:
892
- os.environ[env] = __env
893
- else:
894
- if env not in os.environ:
895
- __env = self.__parse_envs(env, _task)
896
- if __env:
897
- os.environ[env] = __env
902
+ for env, _ in _env.items():
903
+ if self.__tasks_override_env == True or env not in os.environ:
904
+ __parsed_env_value = self.__parse_envs(env, _task)
905
+ task_env[env] = __parsed_env_value
898
906
 
899
907
  # we need to change the cwd if it's set
900
908
  if _cwd is not None:
@@ -908,10 +916,10 @@ class TaskRunner:
908
916
  _cmd_join = f"{_cmd} {' '.join(_args)}{_is_background}"
909
917
 
910
918
  if self.__debug:
911
- print(f"Command: {_task.command}", color=Color.YELLOW)
912
- print(f"Args: {_task.args}", color=Color.YELLOW)
913
- print(f"Parsed Args: {_args}", color=Color.YELLOW)
914
- print(f"Parsed Command: {_cmd_join}", color=Color.YELLOW)
919
+ print(f"Command: {_task.command}", color=Color.YELLOW, flush=True)
920
+ print(f"Args: {_task.args}", color=Color.YELLOW, flush=True)
921
+ print(f"Parsed Args: {_args}", color=Color.YELLOW, flush=True)
922
+ print(f"Parsed Command: {_cmd_join}", color=Color.YELLOW, flush=True)
915
923
 
916
924
  # use bash to execute the VSCode tasks commands and scripts, as they
917
925
  # are written and tested in bash. Valid just for commands of shell
@@ -920,7 +928,7 @@ class TaskRunner:
920
928
  [_cmd, *_args] if not _shell else _cmd_join,
921
929
  stdout=None,
922
930
  stderr=None,
923
- env=os.environ,
931
+ env=task_env,
924
932
  shell=_shell,
925
933
  executable="/bin/bash" if _shell else None
926
934
  )
@@ -929,5 +937,5 @@ class TaskRunner:
929
937
  os.chdir(_last_cwd)
930
938
 
931
939
  if _ret.returncode != 0:
932
- print(f"> TASK [{label}] exited with error code [{_ret.returncode}] <", color=Color.RED)
940
+ print(f"> TASK [{label}] exited with error code [{_ret.returncode}] <", color=Color.RED, flush=True)
933
941
  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.8
3
+ Version: 0.0.10
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.