Commit 11674c5e authored by Adrian DC's avatar Adrian DC
Browse files

fix(src): refactor jobs parsers into models with Python typings

Resolves: #170
---

Signed-off-by: default avatarAdrian DC <radian.dc@gmail.com>
parent 6aa9d70e
Loading
Loading
Loading
Loading
+45 −12
Changes for src/cli/entrypoint.py: 45 added lines, 12 removed lines.
Original line number Diff line number Diff line
@@ -15,6 +15,7 @@ from ..features.configurations import ConfigurationsFeature
from ..features.images import ImagesFeature
from ..features.menus import MenusFeature
from ..features.pipelines import PipelinesFeature
from ..models.pipelines import Pipeline
from ..package.bundle import Bundle
from ..package.settings import Settings
from ..parsers.parsers import Parsers
@@ -26,7 +27,12 @@ from ..types.files import Files
class Entrypoint:

    # Enumerations
    Result = Enum('Result', ['SUCCESS', 'FINALIZE', 'ERROR', 'CRITICAL'])
    Result = Enum('Result', [
        'SUCCESS',
        'FINALIZE',
        'ERROR',
        'CRITICAL',
    ])

    # CLI, pylint: disable=too-many-branches,too-many-locals,too-many-return-statements
    @staticmethod
@@ -99,8 +105,8 @@ class Entrypoint:
            options.tags_default = True

        # Read configuration
        jobs = Parsers(options).read()
        if not jobs:
        pipeline: Optional[Pipeline] = Parsers(options).read()
        if not pipeline:
            return Entrypoint.Result.CRITICAL

        # Header
@@ -109,44 +115,71 @@ class Entrypoint:

        # Dump configuration
        if options.dump:
            result = ConfigurationsFeature(jobs=jobs, options=options).dump()
            result = ConfigurationsFeature(
                pipeline=pipeline,
                options=options,
            ).dump()

        # Pull jobs images
        elif options.pull:
            result = ImagesFeature(jobs=jobs, options=options).pull()
            result = ImagesFeature(
                pipeline=pipeline,
                options=options,
            ).pull()

        # Remove jobs images
        elif options.rmi:
            result = ImagesFeature(jobs=jobs, options=options).rmi()
            result = ImagesFeature(
                pipeline=pipeline,
                options=options,
            ).rmi()

        # Select job
        elif options.list and interactive:
            options.manual = True
            options.no_regex = True
            result = MenusFeature(jobs=jobs, options=options).select()
            result = MenusFeature(
                pipeline=pipeline,
                options=options,
            ).select()

        # Select jobs
        elif options.select and interactive:
            options.no_regex = True
            result = MenusFeature(jobs=jobs, options=options).select()
            result = MenusFeature(
                pipeline=pipeline,
                options=options,
            ).select()

        # Launch pipeline
        elif options.pipeline:
            result = PipelinesFeature(jobs=jobs, options=options).launch()
            result = PipelinesFeature(
                pipeline=pipeline,
                options=options,
            ).launch()

        # Launch jobs
        elif options.names:
            result = PipelinesFeature(jobs=jobs, options=options).launch()
            result = PipelinesFeature(
                pipeline=pipeline,
                options=options,
            ).launch()

        # Select jobs
        elif interactive:
            options.no_regex = True
            result = MenusFeature(jobs=jobs, options=options).select()
            result = MenusFeature(
                pipeline=pipeline,
                options=options,
            ).select()

        # Launch all jobs
        elif options.all:
            options.pipeline = True
            result = PipelinesFeature(jobs=jobs, options=options).launch()
            result = PipelinesFeature(
                pipeline=pipeline,
                options=options,
            ).launch()

        # Unsupported case
        else:
+3 −2
Changes for src/engines/base.py: 3 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -2,9 +2,10 @@

# Standard libraries
from abc import ABC, abstractmethod
from typing import Any, Dict, Iterator, List, NamedTuple
from typing import Dict, Iterator, List, NamedTuple

# Components
from ..models.images import Entrypoint
from ..types.volumes import Volumes

# Commands type
@@ -80,7 +81,7 @@ class BaseEngine(ABC): # pragma: no cover
        self,
        image: str,
        commands: Commands,
        entrypoint: Any,
        entrypoint: Entrypoint,
        variables: Dict[str, str],
        network: str,
        option_sockets: bool,
+3 −2
Changes for src/engines/docker.py: 3 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -2,7 +2,7 @@

# Standard libraries
from os import environ
from typing import Any, cast, Dict, Optional
from typing import cast, Dict, Optional

# Modules libraries
from docker import DockerClient, from_env
@@ -11,6 +11,7 @@ from docker.models.containers import Container

# Components
from ..jobs.outputs import Outputs
from ..models.images import Entrypoint
from ..system.platform import Platform
from ..types.volumes import Volumes
from .base import _ExecResult, _LogsResult, BaseEngine, Commands, ContainerName
@@ -211,7 +212,7 @@ class DockerEngine(BaseEngine):
        self,
        image: str,
        commands: Commands,
        entrypoint: Any,
        entrypoint: Entrypoint,
        variables: Dict[str, str],
        network: str,
        option_sockets: bool,
+3 −2
Changes for src/engines/engine.py: 3 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -3,9 +3,10 @@
# Standard libraries
from argparse import Namespace
from enum import Enum
from typing import Any, Dict, List
from typing import Dict, List

# Components
from ..models.images import Entrypoint
from ..package.bundle import Bundle
from ..types.volumes import Volumes
from .base import _ExecResult, _LogsResult, BaseEngine, Commands, ContainerName
@@ -161,7 +162,7 @@ class Engine:
        self,
        image: str,
        commands: Commands,
        entrypoint: Any,
        entrypoint: Entrypoint,
        variables: Dict[str, str],
        network: str,
        option_sockets: bool,
+3 −2
Changes for src/engines/podman.py: 3 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -4,9 +4,10 @@
from __future__ import annotations
from os import environ
from subprocess import CompletedProcess, DEVNULL, PIPE, Popen, run
from typing import Any, Dict, Iterator, List, Optional
from typing import Dict, Iterator, List, Optional

# Components
from ..models.images import Entrypoint
from ..package.bundle import Bundle
from ..system.platform import Platform
from ..types.volumes import Volumes
@@ -219,7 +220,7 @@ class PodmanEngine(BaseEngine):
        self,
        image: str,
        commands: Commands,
        entrypoint: Any,
        entrypoint: Entrypoint,
        variables: Dict[str, str],
        network: str,
        option_sockets: bool,
Loading