Coverage for src/features/configurations.py: 100.00%
43 statements
« prev ^ index » next coverage.py v7.15.4, created at 2026-10-18 15:02 +0000
« prev ^ index » next coverage.py v7.15.4, created at 2026-10-18 15:02 +0000
1#!/usr/bin/env python3
3# Standard libraries
4from argparse import Namespace
5from copy import deepcopy
6from typing import Any, Dict
8# Components
9from ..models.pipelines import Pipeline
10from ..system.platform import Platform
11from ..types.lists import Lists
12from ..types.yaml import YAML
14# ConfigurationsFeature class, pylint: disable=too-few-public-methods
15class ConfigurationsFeature:
17 # Members
18 __configuration: Dict[str, Any]
20 # Constructor
21 def __init__(
22 self,
23 pipeline: Pipeline,
24 options: Namespace,
25 ) -> None:
27 # Prepare configuration
28 self.__configuration = {}
29 if options.pipeline and options.names:
30 for job in pipeline.jobs:
31 if Lists.match(
32 options.names,
33 pipeline.jobs[job].stage,
34 ignore_case=options.ignore_case,
35 no_regex=options.no_regex,
36 ):
37 self.__configuration[job] = deepcopy(pipeline.jobs[job].__dict__)
38 self.__cleanup(job)
39 elif options.names:
40 for job in pipeline.jobs:
41 if Lists.match(
42 options.names,
43 job,
44 ignore_case=options.ignore_case,
45 no_regex=options.no_regex,
46 ):
47 self.__configuration[job] = deepcopy(pipeline.jobs[job].__dict__)
48 self.__cleanup(job)
49 else:
50 for job in pipeline.jobs:
51 self.__configuration[job] = deepcopy(pipeline.jobs[job].__dict__)
52 self.__cleanup(job)
54 # Cleanup
55 def __cleanup(
56 self,
57 job: str,
58 ) -> None:
60 # Cleanup job configurations
61 if job in self.__configuration:
62 if self.__configuration[job]['entrypoint'] is None:
63 del self.__configuration[job]['entrypoint']
64 if self.__configuration[job]['retry'] == 0:
65 del self.__configuration[job]['retry']
66 if not self.__configuration[job]['services']:
67 del self.__configuration[job]['services']
68 if self.__configuration[job]['tags'] is None:
69 del self.__configuration[job]['tags']
70 if self.__configuration[job]['trigger'] is None:
71 del self.__configuration[job]['trigger']
72 if not self.__configuration[job]['variables']:
73 del self.__configuration[job]['variables']
74 del self.__configuration[job]['options']
76 # Dump
77 def dump(self) -> bool:
79 # Dump configuration results
80 print(YAML.dump(self.__configuration))
81 print(' ')
82 Platform.flush()
84 # Result
85 return bool(self.__configuration)