torizon-templates-utils 0.0.10__py3-none-any.whl → 0.0.11__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.
@@ -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,6 +8,7 @@ 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')
@@ -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:
@@ -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
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: torizon_templates_utils
3
- Version: 0.0.10
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
@@ -4,9 +4,9 @@ torizon_templates_utils/args.py,sha256=nN1b9Ts2lEYbpAGzaMWpAcmcYIrTUFJHehM_UqvnC
4
4
  torizon_templates_utils/colors.py,sha256=Y1FZ0HtKvXfLGYTDclsXubtZCQ-epuch5Dgk1DJdjps,1143
5
5
  torizon_templates_utils/debug.py,sha256=OfdKSdN1kypuJnV_WcPa9bvonjyDvXvA3QTmc1iKyjw,556
6
6
  torizon_templates_utils/errors.py,sha256=Wkk0AeCx0KQW-Qlu_5A6GYaGUkaJU79Mok8lZuZKHjM,1425
7
- torizon_templates_utils/network.py,sha256=NpBeJlvpCY0Gvdc8ZzCKfmAk6zGYD_gLx-rTzZn9ZsU,1528
8
- torizon_templates_utils/tasks.py,sha256=9G0SiSO4VEA5XccozNSjYwDsc2RZoAPO_iSwjsE5JDk,32808
9
- torizon_templates_utils-0.0.10.dist-info/METADATA,sha256=aQMMGaOpa5FYhna733e39T0dbzvgpSUe-n2S5_PhZx0,977
10
- torizon_templates_utils-0.0.10.dist-info/WHEEL,sha256=DK49LOLCYiurdXXOXwGJm6U4DkHkg4lcxjhqwRa0CP4,91
11
- torizon_templates_utils-0.0.10.dist-info/top_level.txt,sha256=qlOkS1ASF5C-kSfpbiWbVHJFgmQ0RN6iunmLArNt6zc,24
12
- torizon_templates_utils-0.0.10.dist-info/RECORD,,
7
+ torizon_templates_utils/network.py,sha256=SFZivQumv-pVL0vglYCW3JS6WWCUG8asoMdgljeJZ24,1703
8
+ torizon_templates_utils/tasks.py,sha256=lDRIF9EXA-cjzLqWYmcf717M4pu6LkJYY5fYbuSu80Y,34597
9
+ torizon_templates_utils-0.0.11.dist-info/METADATA,sha256=PmYKN9vm5QHKexPGflu7Jm8fVnZLpK1iKEd-4a8e_Vw,977
10
+ torizon_templates_utils-0.0.11.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
11
+ torizon_templates_utils-0.0.11.dist-info/top_level.txt,sha256=qlOkS1ASF5C-kSfpbiWbVHJFgmQ0RN6iunmLArNt6zc,24
12
+ torizon_templates_utils-0.0.11.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (78.0.2)
2
+ Generator: setuptools (80.9.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5