diff --git a/Dockerfile b/Dockerfile index b27636b1..d980e21e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -25,8 +25,9 @@ COPY $CIBYL_ROOT/setup.py . COPY $CIBYL_ROOT/setup.cfg . COPY $CIBYL_ROOT/requirements.txt . -COPY $CIBYL_ROOT/cibyl ./cibyl +COPY $CIBYL_ROOT/kernel ./kernel COPY $CIBYL_ROOT/tripleo ./tripleo +COPY $CIBYL_ROOT/cibyl ./cibyl RUN python3 -m pip install . diff --git a/cibyl/cli/query.py b/cibyl/cli/query.py index 8cd89463..c5199c3a 100644 --- a/cibyl/cli/query.py +++ b/cibyl/cli/query.py @@ -16,7 +16,7 @@ from enum import IntFlag, auto from typing import Optional -from cibyl.utils.dicts import subset +from kernel.tools.dicts import subset class QueryType(IntFlag): diff --git a/cibyl/config.py b/cibyl/config.py index d2ed4d1c..dd10cb0d 100644 --- a/cibyl/config.py +++ b/cibyl/config.py @@ -28,10 +28,10 @@ from cibyl.exceptions.config import SchemaError from cibyl.models.ci.system_factory import SystemType from cibyl.utils import yaml -from cibyl.utils.files import get_first_available_file, is_file_available -from cibyl.utils.fs import File, cd_context_manager -from cibyl.utils.json import Draft7ValidatorFactory -from cibyl.utils.net import DownloadError, download_file +from kernel.tools.files import get_first_available_file, is_file_available +from kernel.tools.fs import File, cd_context_manager +from kernel.tools.json import Draft7ValidatorFactory +from kernel.tools.net import DownloadError, download_file LOG = logging.getLogger(__name__) @@ -246,7 +246,7 @@ def from_url( host. The definition is accessed and downloaded into the provided path. Supported protocols are defined by - :func:`cibyl.utils.net.download_file`. + :func:`kernel.tools.net.download_file`. Warnings ------- diff --git a/cibyl/features/__init__.py b/cibyl/features/__init__.py index 7d643d99..30932060 100644 --- a/cibyl/features/__init__.py +++ b/cibyl/features/__init__.py @@ -29,8 +29,8 @@ select_source_method, source_information_from_method) from cibyl.utils.colors import Colors -from cibyl.utils.files import FileSearch -from cibyl.utils.reflection import get_classes_in, load_module +from kernel.tools.files import FileSearch +from kernel.tools.reflection import get_classes_in, load_module LOG = logging.getLogger(__name__) diff --git a/cibyl/models/ci/zuul/job.py b/cibyl/models/ci/zuul/job.py index a0445f9b..9ec33c21 100644 --- a/cibyl/models/ci/zuul/job.py +++ b/cibyl/models/ci/zuul/job.py @@ -19,7 +19,7 @@ from cibyl.models.attribute import AttributeDictValue, AttributeListValue from cibyl.models.ci.base.job import Job as BaseJob from cibyl.models.model import Model -from cibyl.utils.dicts import subset +from kernel.tools.dicts import subset class Job(BaseJob): diff --git a/cibyl/orchestrator.py b/cibyl/orchestrator.py index 611f8829..5a4ce03f 100644 --- a/cibyl/orchestrator.py +++ b/cibyl/orchestrator.py @@ -43,10 +43,10 @@ select_source_method, source_information_from_method) from cibyl.sources.source_factory import SourceFactory -from cibyl.utils.dicts import intersect_models -from cibyl.utils.fs import File -from cibyl.utils.paths import resolve_home from cibyl.utils.status_bar import StatusBar +from kernel.tools.dicts import intersect_models +from kernel.tools.fs import File +from kernel.tools.paths import resolve_home LOG = logging.getLogger(__name__) diff --git a/cibyl/outputs/cli/ci/env/impl/colored.py b/cibyl/outputs/cli/ci/env/impl/colored.py index 8869d887..57736603 100644 --- a/cibyl/outputs/cli/ci/env/impl/colored.py +++ b/cibyl/outputs/cli/ci/env/impl/colored.py @@ -28,7 +28,7 @@ from cibyl.outputs.cli.ci.system.impls.zuul.colored import \ ColoredZuulSystemPrinter from cibyl.outputs.cli.printer import ColoredPrinter -from cibyl.utils.strings import IndentedTextBuilder +from kernel.tools.text import IndentedTextBuilder LOG = logging.getLogger(__name__) diff --git a/cibyl/outputs/cli/ci/system/common/builds.py b/cibyl/outputs/cli/ci/system/common/builds.py index 2c019a8a..ccaa9a52 100644 --- a/cibyl/outputs/cli/ci/system/common/builds.py +++ b/cibyl/outputs/cli/ci/system/common/builds.py @@ -16,8 +16,8 @@ from cibyl.models.ci.base.build import Build from cibyl.outputs.cli.ci.system.common.status import get_status_colored from cibyl.utils.colors import ColorPalette -from cibyl.utils.strings import IndentedTextBuilder from cibyl.utils.time import as_minutes +from kernel.tools.text import IndentedTextBuilder def has_status_section(build: Build) -> bool: diff --git a/cibyl/outputs/cli/ci/system/common/models.py b/cibyl/outputs/cli/ci/system/common/models.py index 515fd626..7a44b68f 100644 --- a/cibyl/outputs/cli/ci/system/common/models.py +++ b/cibyl/outputs/cli/ci/system/common/models.py @@ -21,7 +21,7 @@ AttributeValue) from cibyl.models.model import Model from cibyl.outputs.cli.printer import JSON, ColoredPrinter, SerializedPrinter -from cibyl.utils.strings import IndentedTextBuilder +from kernel.tools.text import IndentedTextBuilder LOG = logging.getLogger(__name__) diff --git a/cibyl/outputs/cli/ci/system/common/stages.py b/cibyl/outputs/cli/ci/system/common/stages.py index 5f5d2b7c..d02eebf6 100644 --- a/cibyl/outputs/cli/ci/system/common/stages.py +++ b/cibyl/outputs/cli/ci/system/common/stages.py @@ -16,8 +16,8 @@ from cibyl.models.ci.base.stage import Stage from cibyl.outputs.cli.ci.system.common.status import get_status_colored from cibyl.utils.colors import ColorPalette -from cibyl.utils.strings import IndentedTextBuilder from cibyl.utils.time import as_minutes +from kernel.tools.text import IndentedTextBuilder def print_stage(stage: Stage, palette: ColorPalette, diff --git a/cibyl/outputs/cli/ci/system/impls/base/colored.py b/cibyl/outputs/cli/ci/system/impls/base/colored.py index 2633c654..e1ff5dbf 100644 --- a/cibyl/outputs/cli/ci/system/impls/base/colored.py +++ b/cibyl/outputs/cli/ci/system/impls/base/colored.py @@ -26,8 +26,8 @@ from cibyl.outputs.cli.ci.system.utils.sorting.jobs import SortJobsByName from cibyl.outputs.cli.printer import ColoredPrinter from cibyl.utils.colors import ColorPalette, DefaultPalette -from cibyl.utils.sorting import BubbleSortAlgorithm, SortingAlgorithm -from cibyl.utils.strings import IndentedTextBuilder +from kernel.tools.sorting import BubbleSortAlgorithm, SortingAlgorithm +from kernel.tools.text import IndentedTextBuilder LOG = logging.getLogger(__name__) diff --git a/cibyl/outputs/cli/ci/system/impls/jobs/colored.py b/cibyl/outputs/cli/ci/system/impls/jobs/colored.py index b461b784..bede7b8a 100644 --- a/cibyl/outputs/cli/ci/system/impls/jobs/colored.py +++ b/cibyl/outputs/cli/ci/system/impls/jobs/colored.py @@ -29,9 +29,9 @@ from cibyl.outputs.cli.ci.system.common.stages import print_stage from cibyl.outputs.cli.ci.system.impls.base.colored import \ ColoredBaseSystemPrinter -from cibyl.utils.sorting import nsort, sort -from cibyl.utils.strings import IndentedTextBuilder from cibyl.utils.time import as_minutes +from kernel.tools.sorting import nsort, sort +from kernel.tools.text import IndentedTextBuilder class ColoredJobsSystemPrinter(ColoredBaseSystemPrinter): diff --git a/cibyl/outputs/cli/ci/system/impls/zuul/colored/__init__.py b/cibyl/outputs/cli/ci/system/impls/zuul/colored/__init__.py index 45740f78..373c49ef 100644 --- a/cibyl/outputs/cli/ci/system/impls/zuul/colored/__init__.py +++ b/cibyl/outputs/cli/ci/system/impls/zuul/colored/__init__.py @@ -33,8 +33,8 @@ ProjectCascade from cibyl.outputs.cli.ci.system.impls.zuul.colored.trees.factory import \ HierarchicalTreeFactory -from cibyl.utils.sorting import sort -from cibyl.utils.strings import IndentedTextBuilder +from kernel.tools.sorting import sort +from kernel.tools.text import IndentedTextBuilder LOG = logging.getLogger(__name__) diff --git a/cibyl/outputs/cli/ci/system/impls/zuul/colored/cascades/hierarchy.py b/cibyl/outputs/cli/ci/system/impls/zuul/colored/cascades/hierarchy.py index 1be78290..d46b8960 100644 --- a/cibyl/outputs/cli/ci/system/impls/zuul/colored/cascades/hierarchy.py +++ b/cibyl/outputs/cli/ci/system/impls/zuul/colored/cascades/hierarchy.py @@ -17,8 +17,8 @@ from cibyl.models.ci.zuul.job import Job from cibyl.outputs.cli.printer import ColoredPrinter -from cibyl.utils.strings import IndentedTextBuilder -from cibyl.utils.tree import Tree +from kernel.tools.text import IndentedTextBuilder +from kernel.tools.tree import Tree class HierarchyCascade(ColoredPrinter): diff --git a/cibyl/outputs/cli/ci/system/impls/zuul/colored/cascades/job.py b/cibyl/outputs/cli/ci/system/impls/zuul/colored/cascades/job.py index 79b78b01..fefdbd33 100644 --- a/cibyl/outputs/cli/ci/system/impls/zuul/colored/cascades/job.py +++ b/cibyl/outputs/cli/ci/system/impls/zuul/colored/cascades/job.py @@ -25,8 +25,8 @@ from cibyl.outputs.cli.ci.system.common.models import (get_plugin_section, has_plugin_section) from cibyl.outputs.cli.printer import ColoredPrinter -from cibyl.utils.strings import IndentedTextBuilder from cibyl.utils.time import as_minutes +from kernel.tools.text import IndentedTextBuilder class JobCascade(ColoredPrinter): diff --git a/cibyl/outputs/cli/ci/system/impls/zuul/colored/cascades/project.py b/cibyl/outputs/cli/ci/system/impls/zuul/colored/cascades/project.py index b2a6de96..b4c1d4d0 100644 --- a/cibyl/outputs/cli/ci/system/impls/zuul/colored/cascades/project.py +++ b/cibyl/outputs/cli/ci/system/impls/zuul/colored/cascades/project.py @@ -22,7 +22,7 @@ from cibyl.outputs.cli.ci.system.common.builds import get_status_section from cibyl.outputs.cli.printer import ColoredPrinter from cibyl.utils.filtering import apply_filters -from cibyl.utils.strings import IndentedTextBuilder +from kernel.tools.text import IndentedTextBuilder class ProjectCascade(ColoredPrinter): diff --git a/cibyl/outputs/cli/ci/system/impls/zuul/colored/trees/factory.py b/cibyl/outputs/cli/ci/system/impls/zuul/colored/trees/factory.py index 3871cfc8..0eba165c 100644 --- a/cibyl/outputs/cli/ci/system/impls/zuul/colored/trees/factory.py +++ b/cibyl/outputs/cli/ci/system/impls/zuul/colored/trees/factory.py @@ -20,7 +20,7 @@ from overrides import overrides from cibyl.models.ci.zuul.job import Job -from cibyl.utils.tree import Leaf, Tree +from kernel.tools.tree import Leaf, Tree LOG = logging.getLogger(__name__) diff --git a/cibyl/outputs/cli/ci/system/utils/sorting/builds.py b/cibyl/outputs/cli/ci/system/utils/sorting/builds.py index 175a2be2..10c43ef9 100644 --- a/cibyl/outputs/cli/ci/system/utils/sorting/builds.py +++ b/cibyl/outputs/cli/ci/system/utils/sorting/builds.py @@ -14,7 +14,7 @@ # under the License. """ from cibyl.models.ci.base.build import Build -from cibyl.utils.sorting import Comparator +from kernel.tools.sorting import Comparator class SortBuildsByUUID(Comparator): diff --git a/cibyl/outputs/cli/ci/system/utils/sorting/jobs.py b/cibyl/outputs/cli/ci/system/utils/sorting/jobs.py index 6d54c269..479feb01 100644 --- a/cibyl/outputs/cli/ci/system/utils/sorting/jobs.py +++ b/cibyl/outputs/cli/ci/system/utils/sorting/jobs.py @@ -14,7 +14,7 @@ # under the License. """ from cibyl.models.ci.base.job import Job -from cibyl.utils.sorting import Comparator +from kernel.tools.sorting import Comparator class SortJobsByName(Comparator): diff --git a/cibyl/plugins/__init__.py b/cibyl/plugins/__init__.py index 37ec3dd3..9ad67ac3 100644 --- a/cibyl/plugins/__init__.py +++ b/cibyl/plugins/__init__.py @@ -23,9 +23,9 @@ from cibyl.outputs.cli.printer import JSON, ColoredPrinter, SerializedPrinter from cibyl.sources.plugins import SourceExtension from cibyl.sources.source_factory import SourceFactory -from cibyl.utils.files import FileSearch from cibyl.utils.filtering import apply_filters -from cibyl.utils.reflection import get_classes_in, load_module +from kernel.tools.files import FileSearch +from kernel.tools.reflection import get_classes_in, load_module LOG = logging.getLogger(__name__) diff --git a/cibyl/plugins/openstack/__init__.py b/cibyl/plugins/openstack/__init__.py index 45ed0e8a..e49556b5 100644 --- a/cibyl/plugins/openstack/__init__.py +++ b/cibyl/plugins/openstack/__init__.py @@ -23,7 +23,7 @@ from cibyl.plugins import PluginTemplate from cibyl.plugins.openstack.deployment import Deployment from cibyl.plugins.openstack.printers.router import PrinterRouter -from cibyl.utils.dicts import subset +from kernel.tools.dicts import subset PLUGIN_ARGUMENTS = ('release', 'spec', 'infra_type', 'nodes', 'controllers', 'computes', 'node_name', 'role', 'containers', diff --git a/cibyl/plugins/openstack/printers/colored.py b/cibyl/plugins/openstack/printers/colored.py index 77638c13..86b21ce3 100644 --- a/cibyl/plugins/openstack/printers/colored.py +++ b/cibyl/plugins/openstack/printers/colored.py @@ -19,7 +19,7 @@ from cibyl.plugins.openstack.network import Network from cibyl.plugins.openstack.printers import OSPrinter from cibyl.plugins.openstack.storage import Storage -from cibyl.utils.strings import IndentedTextBuilder +from kernel.tools.text import IndentedTextBuilder class OSColoredPrinter(ColoredPrinter, OSPrinter): diff --git a/cibyl/plugins/openstack/sources/elasticsearch.py b/cibyl/plugins/openstack/sources/elasticsearch.py index 540cbc92..57998c2a 100644 --- a/cibyl/plugins/openstack/sources/elasticsearch.py +++ b/cibyl/plugins/openstack/sources/elasticsearch.py @@ -23,8 +23,8 @@ from cibyl.plugins.openstack.test_collection import TestCollection from cibyl.sources.plugins import SourceExtension from cibyl.sources.source import speed_index -from cibyl.utils.dicts import chunk_dictionary_into_lists from cibyl.utils.filtering import IP_PATTERN +from kernel.tools.dicts import chunk_dictionary_into_lists class ElasticSearch(SourceExtension): diff --git a/cibyl/plugins/openstack/sources/jenkins.py b/cibyl/plugins/openstack/sources/jenkins.py index 35a4c568..847b381b 100644 --- a/cibyl/plugins/openstack/sources/jenkins.py +++ b/cibyl/plugins/openstack/sources/jenkins.py @@ -38,8 +38,6 @@ from cibyl.sources.jenkins import LOG, detect_job_info_regex, filter_jobs from cibyl.sources.plugins import SourceExtension from cibyl.sources.source import speed_index -from cibyl.utils.dicts import subset -from cibyl.utils.files import get_file_name_from_path from cibyl.utils.filtering import (DEPLOYMENT_PATTERN, DVR_PATTERN_NAME, IP_PATTERN, NETWORK_BACKEND_PATTERN, RELEASE_PATTERN, SERVICES_PATTERN, @@ -47,6 +45,8 @@ filter_topology, satisfy_case_insensitive_match, satisfy_exact_match, satisfy_regex_match) +from kernel.tools.dicts import subset +from kernel.tools.files import get_file_name_from_path # shorthand for the type that will hold the job information obtained from the # Jenkins API response diff --git a/cibyl/publisher.py b/cibyl/publisher.py index c46502da..a435eba9 100644 --- a/cibyl/publisher.py +++ b/cibyl/publisher.py @@ -23,7 +23,7 @@ from cibyl.cli.query import QueryType from cibyl.models.ci.base.environment import Environment from cibyl.outputs.cli.ci.env.factory import CIPrinterFactory -from cibyl.utils.fs import File +from kernel.tools.fs import File LOG = logging.getLogger(__name__) diff --git a/cibyl/sources/elasticsearch/api.py b/cibyl/sources/elasticsearch/api.py index 7a264d39..1d7bc513 100644 --- a/cibyl/sources/elasticsearch/api.py +++ b/cibyl/sources/elasticsearch/api.py @@ -32,10 +32,10 @@ from cibyl.sources.elasticsearch.client import ElasticSearchClient from cibyl.sources.server import ServerSource from cibyl.sources.source import speed_index -from cibyl.utils.dicts import chunk_dictionary_into_lists from cibyl.utils.filtering import (apply_filters, matches_regex, satisfy_exact_match, satisfy_regex_match) from cibyl.utils.models import has_builds_job, has_tests_job +from kernel.tools.dicts import chunk_dictionary_into_lists LOG = logging.getLogger(__name__) diff --git a/cibyl/sources/source.py b/cibyl/sources/source.py index e54cd187..50539bf6 100644 --- a/cibyl/sources/source.py +++ b/cibyl/sources/source.py @@ -22,7 +22,7 @@ from cibyl.cli.argument import Argument from cibyl.exceptions.source import NoSupportedSourcesFound, NoValidSources -from cibyl.utils.attrdict import AttrDict +from kernel.tools.attrdict import AttrDict LOG = logging.getLogger(__name__) diff --git a/cibyl/sources/zuul/apis/__init__.py b/cibyl/sources/zuul/apis/__init__.py index d6e8abc8..f608e7ed 100644 --- a/cibyl/sources/zuul/apis/__init__.py +++ b/cibyl/sources/zuul/apis/__init__.py @@ -23,7 +23,7 @@ from cibyl.sources.zuul.apis.providers import JobsProvider, PipelinesProvider from cibyl.sources.zuul.utils.artifacts import Artifact, ArtifactKind from cibyl.sources.zuul.utils.tests.types import TestSuite -from cibyl.utils.io import Closeable +from kernel.tools.io import Closeable class ZuulAPIError(SourceException): diff --git a/cibyl/sources/zuul/apis/http.py b/cibyl/sources/zuul/apis/http.py index b0b54088..d672d459 100644 --- a/cibyl/sources/zuul/apis/http.py +++ b/cibyl/sources/zuul/apis/http.py @@ -21,7 +21,7 @@ from requests import HTTPError, Session from cibyl.sources.zuul.apis import ZuulAPIError, ZuulBuildAPI -from cibyl.utils.io import Closeable +from kernel.tools.io import Closeable class ZuulSession(Closeable): diff --git a/cibyl/sources/zuul/source.py b/cibyl/sources/zuul/source.py index 41261f53..dfd9d912 100644 --- a/cibyl/sources/zuul/source.py +++ b/cibyl/sources/zuul/source.py @@ -29,7 +29,7 @@ from cibyl.sources.zuul.queries.composition.factory import \ AggregatedQueryFactory from cibyl.sources.zuul.queries.modifiers.factory import QueryModifierFactory -from cibyl.utils.dicts import subset +from kernel.tools.dicts import subset class Zuul(ServerSource): diff --git a/cibyl/sources/zuul/transactions/__init__.py b/cibyl/sources/zuul/transactions/__init__.py index 8a4f5156..f971ac61 100644 --- a/cibyl/sources/zuul/transactions/__init__.py +++ b/cibyl/sources/zuul/transactions/__init__.py @@ -30,7 +30,7 @@ from cibyl.sources.zuul.utils.tests.tempest.types import TempestTest from cibyl.sources.zuul.utils.tests.types import Test, TestResult, TestSuite from cibyl.utils.filtering import apply_filters, matches_regex -from cibyl.utils.urls import URL +from kernel.tools.urls import URL class Request(ABC): diff --git a/cibyl/sources/zuul/utils/artifacts/manifest.py b/cibyl/sources/zuul/utils/artifacts/manifest.py index ec64a72b..cf49d8f8 100644 --- a/cibyl/sources/zuul/utils/artifacts/manifest.py +++ b/cibyl/sources/zuul/utils/artifacts/manifest.py @@ -22,7 +22,7 @@ from cibyl.sources.zuul.apis.http import ZuulHTTPBuildAPI as Build from cibyl.sources.zuul.utils.artifacts import ArtifactError from cibyl.utils.filtering import matches_regex -from cibyl.utils.net import download_into_memory +from kernel.tools.net import download_into_memory @dataclass diff --git a/cibyl/sources/zuul/utils/builds/__init__.py b/cibyl/sources/zuul/utils/builds/__init__.py index 736ef6c9..1168922d 100644 --- a/cibyl/sources/zuul/utils/builds/__init__.py +++ b/cibyl/sources/zuul/utils/builds/__init__.py @@ -15,7 +15,7 @@ """ from cibyl.sources.zuul.apis import ZuulBuildAPI as Build from cibyl.sources.zuul.utils.artifacts.manifest import ManifestFile -from cibyl.utils.urls import URL +from kernel.tools.urls import URL def get_url_to_build_file(build: Build, file: ManifestFile) -> URL: diff --git a/cibyl/sources/zuul/utils/tests/tempest/parser.py b/cibyl/sources/zuul/utils/tests/tempest/parser.py index a85c9b6c..5c775424 100644 --- a/cibyl/sources/zuul/utils/tests/tempest/parser.py +++ b/cibyl/sources/zuul/utils/tests/tempest/parser.py @@ -24,8 +24,8 @@ from cibyl.sources.zuul.utils.builds import get_url_to_build_file from cibyl.sources.zuul.utils.tests.tempest.types import TempestTest from cibyl.sources.zuul.utils.tests.types import TestResult, TestSuite -from cibyl.utils.net import download_into_memory -from tripleo.utils.urls import URL +from kernel.tools.net import download_into_memory +from kernel.tools.urls import URL @dataclass diff --git a/cibyl/utils/cache.py b/cibyl/utils/cache.py deleted file mode 100644 index 3d7105fb..00000000 --- a/cibyl/utils/cache.py +++ /dev/null @@ -1,89 +0,0 @@ -""" -# Copyright 2022 Red Hat -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -""" -from typing import Generic, MutableMapping, Optional, TypeVar - -K = TypeVar('K') -"""Type of keys used by the cache.""" -V = TypeVar('V') -"""Type of data used by the cache.""" - - -class Cache(Generic[K, V]): - """A cache is a map-like data structure that provides temporary storage - of application data. - - Like maps, it: - - Stores key -> value pairs. - - Allows use of generics to define data types. - Unlike maps, it: - - Does not allow 'None' values to be stored. - - This implementation follows the Cache-Aside approach to caching. - This means that the cache is a simple container for others to push to and - pull from. It does not have any responsibility regarding the origin of - data and how it is retrieved. Those are up to the user to assume. - """ - - def __init__( - self, - storage: Optional[MutableMapping[K, V]] = None - ): - """Constructor. - - :param storage: Container where the cached data is stored. Be sure - that the structure follows the specifications of this class. - 'None' to let this create its own. - """ - if storage is None: - storage = {} - - self._storage = storage - - @property - def storage(self): - """ - :return: Container where the cached data is stored. Modifications to - this structure can lead to a corrupted cache, use under your own - responsibility. - """ - return self._storage - - def has(self, key: K) -> bool: - """Checks if the cache contains a value for the given key. - - :param key: The key to test. - :return: True if it does, False if not. - """ - return key in self.storage - - def get(self, key: K) -> Optional[V]: - """Gets the value for an entry in the cache. - - :param key: The key to get the value for. - :return: The value associated to the key if is it present on the - cache, 'None' if not. - """ - return self.storage.get(key) - - def put(self, key: K, value: V) -> None: - """Creates a new entry on the cache. If the entry already exists, - then it will be overridden. - - :param key: Key for the entry. - :param value: Data associated to the key. - :return: - """ - self.storage[key] = value diff --git a/cibyl/utils/fs.py b/cibyl/utils/fs.py deleted file mode 100644 index edcff215..00000000 --- a/cibyl/utils/fs.py +++ /dev/null @@ -1,178 +0,0 @@ -""" -# Copyright 2022 Red Hat -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -""" -from abc import ABC, abstractmethod -from contextlib import contextmanager -from os import PathLike, chdir, getcwd -from pathlib import Path -from typing import Generator, Union - -from overrides import overrides - -from tripleo.utils.paths import Preprocessor - -RawPath = Union[bytes, str, PathLike, Path] - - -@contextmanager -def cd_context_manager(path: RawPath) -> Generator: - """Simple context manager that changes the working directory and restores - the previous one on exit""" - old_dir = getcwd() - chdir(path) - try: - yield - finally: - chdir(old_dir) - - -class FSPath(str, ABC): - """Base class for representations of a filesystem path. These are able - to make system calls and are meant to model elements existing on the - filesystem. - """ - - def __new__(cls, value: RawPath, *makeup: Preprocessor): - """Constructor. - - :param value: The path to build this from. - :param makeup: Modifications applied to the path before it is - converted into this type. 'value' is left untouched during this - process. - """ - result = Path(value) - - for cosmetic in makeup: - result = cosmetic(result) - - return super().__new__(cls, str(result)) - - @abstractmethod - def check_exists(self) -> None: - """ - :raises IOError: If the path does not exist or is not in the - correct format. - """ - raise NotImplementedError - - @abstractmethod - def exists(self) -> bool: - """ - :return: True is the path exists on the filesystem, False otherwise. - """ - raise NotImplementedError - - def as_path(self) -> Path: - """ - :return: The path in pathlib format. - """ - return Path(self) - - -class Dir(FSPath): - """Represents a directory on the filesystem. - """ - - @overrides - def check_exists(self) -> None: - if not self.exists(): - msg = f"Path is not a directory or does not exist: '{self}'." - raise IOError(msg) - - @overrides - def exists(self) -> bool: - return self.as_path().is_dir() - - def is_empty(self) -> bool: - """Checks if the directory has any files within. - - If the directory does not exist, this will return False. - - :return: True if the directory has no files within, False otherwise. - """ - if not self.exists(): - return False - - return not any(self.as_path().iterdir()) - - def cd(self, path: RawPath) -> 'Dir': - """Combines this path with the one passed as an argument. Useful to - represent subdirectories. - - :param path: The path to append. - :return: A new directory handler, pointing to the combined path. - """ - return Dir(self.as_path() / path) - - def mkdir(self, recursive: bool = False) -> None: - """Creates the directory on the filesystem. - - :param recursive: Whether to also create missing directories - leading to this one or not. - :raises FileNotFoundError: If the parents on the directory do not - exist. Can only happen if 'recursive" is False. - """ - self.as_path().mkdir(parents=recursive, exist_ok=True) - - -class File(FSPath): - """Represents a file on the filesystem. - """ - - @overrides - def check_exists(self) -> None: - if not self.exists(): - msg = f"Path is not a file or does not exist: '{self}'." - raise IOError(msg) - - @overrides - def exists(self) -> bool: - return self.as_path().is_file() - - def create(self) -> None: - """Creates the file at this path. - """ - self.write('') - - def delete(self) -> None: - """Deletes the file at this path. Will do nothing if the file does - not exist. - """ - self.as_path().unlink(missing_ok=True) - - def append(self, text: str) -> None: - """Appends some text at the end of the file. - - :param text: Text to append. - """ - self._write(text, 'a') - - def write(self, text: str) -> None: - """Overwrites contents of the file with the given text. - - :param text: Text to write. - """ - self._write(text, 'w') - - def _write(self, text: str, mode: str) -> None: - """Writes some text into the file. This makes no checks to verify - that the file exists and is accessible beforehand, it is up to the - caller to ensure this. - - :param text: Text to write. - :param mode: Mode to write on, just like in builtin 'open'. - """ - with open(self, mode) as buffer: - buffer.write(text) diff --git a/cibyl/utils/json.py b/cibyl/utils/json.py deleted file mode 100644 index b5f32c72..00000000 --- a/cibyl/utils/json.py +++ /dev/null @@ -1,53 +0,0 @@ -""" -# Copyright 2022 Red Hat -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -""" -import json -from abc import ABC, abstractmethod - -from jsonschema.validators import Draft7Validator -from overrides import overrides - - -class JSONValidatorFactory(ABC): - """Base factory for all JSON validators. - """ - - @abstractmethod - def from_file(self, file: str): - """Builds a new validator by reading the schema from a file. - - :param file: Path to the file to read. - :return: New validator instance. - :rtype: :class:`jsonschema.IValidator` - :raise IOError: If the file could not be opened or read. - :raise JSONDecodeError: If the file contents are not a valid JSON - structure. - :raise SchemaError: If the file contents are not a valid JSON schema. - """ - raise NotImplementedError - - -class Draft7ValidatorFactory(JSONValidatorFactory): - """Factory that generates validators capable of reading Draft-7 schemas. - """ - - @overrides - def from_file(self, file: str) -> Draft7Validator: - with open(file, 'r') as buffer: - schema = json.loads(buffer.read()) - - Draft7Validator.check_schema(schema) - - return Draft7Validator(schema) diff --git a/cibyl/utils/urls.py b/cibyl/utils/urls.py deleted file mode 100644 index 81d77983..00000000 --- a/cibyl/utils/urls.py +++ /dev/null @@ -1,40 +0,0 @@ -""" -# Copyright 2022 Red Hat -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -""" -from cibyl.utils.strings import is_url - - -class URL(str): - """Extension of a string to exclusively model URLs. - """ - - def __new__(cls, value: str) -> 'URL': - """Constructor. - - The string is preprocessed a bit for convenience’ sake. Some actions - taken are: - - Trimming the string. - - :param value: The string's text. - :raises ValueError: If the string does not follow a URL format. - """ - # Avoid false positives by removing leading and trailing whitespaces - value = value.strip() - - if not is_url(value): - msg = f"String does not represent a valid URL: '{value}'." - raise ValueError(msg) - - return super().__new__(cls, value) diff --git a/tests/cibyl/intr/utils/__init__.py b/kernel/__init__.py similarity index 100% rename from tests/cibyl/intr/utils/__init__.py rename to kernel/__init__.py diff --git a/tests/tripleo/intr/utils/__init__.py b/kernel/tools/__init__.py similarity index 100% rename from tests/tripleo/intr/utils/__init__.py rename to kernel/tools/__init__.py diff --git a/cibyl/utils/attrdict.py b/kernel/tools/attrdict.py similarity index 100% rename from cibyl/utils/attrdict.py rename to kernel/tools/attrdict.py diff --git a/tripleo/utils/cache.py b/kernel/tools/cache.py similarity index 100% rename from tripleo/utils/cache.py rename to kernel/tools/cache.py diff --git a/cibyl/utils/dicts.py b/kernel/tools/dicts.py similarity index 100% rename from cibyl/utils/dicts.py rename to kernel/tools/dicts.py diff --git a/cibyl/utils/files.py b/kernel/tools/files.py similarity index 100% rename from cibyl/utils/files.py rename to kernel/tools/files.py diff --git a/tripleo/utils/fs.py b/kernel/tools/fs.py similarity index 98% rename from tripleo/utils/fs.py rename to kernel/tools/fs.py index 18a7b6b1..1ea7b831 100644 --- a/tripleo/utils/fs.py +++ b/kernel/tools/fs.py @@ -22,7 +22,7 @@ from overrides import overrides -from tripleo.utils.paths import Preprocessor +from kernel.tools.paths import Preprocessor RawPath = Union[bytes, str, PathLike, Path] diff --git a/tripleo/utils/git/__init__.py b/kernel/tools/git/__init__.py similarity index 96% rename from tripleo/utils/git/__init__.py rename to kernel/tools/git/__init__.py index de159e52..235d0920 100644 --- a/tripleo/utils/git/__init__.py +++ b/kernel/tools/git/__init__.py @@ -16,9 +16,9 @@ from abc import ABC, abstractmethod from typing import Iterable -from tripleo.utils.fs import Dir -from tripleo.utils.io import Closeable -from tripleo.utils.urls import URL +from kernel.tools.fs import Dir +from kernel.tools.io import Closeable +from kernel.tools.urls import URL class GitError(Exception): diff --git a/tripleo/utils/git/gitpython.py b/kernel/tools/git/gitpython.py similarity index 94% rename from tripleo/utils/git/gitpython.py rename to kernel/tools/git/gitpython.py index f5e9dea4..aead86d3 100644 --- a/tripleo/utils/git/gitpython.py +++ b/kernel/tools/git/gitpython.py @@ -22,12 +22,12 @@ from git import Repo as RepoAPI from overrides import overrides -from tripleo.utils.fs import Dir, File -from tripleo.utils.git import Git as IGit -from tripleo.utils.git import GitError -from tripleo.utils.git import Remote as IRemote -from tripleo.utils.git import Repository as IRepository -from tripleo.utils.urls import URL +from kernel.tools.fs import Dir, File +from kernel.tools.git import Git as IGit +from kernel.tools.git import GitError +from kernel.tools.git import Remote as IRemote +from kernel.tools.git import Repository as IRepository +from kernel.tools.urls import URL LOG = logging.getLogger(__name__) diff --git a/tripleo/utils/git/utils.py b/kernel/tools/git/utils.py similarity index 97% rename from tripleo/utils/git/utils.py rename to kernel/tools/git/utils.py index 6ec62e29..66b011fd 100644 --- a/tripleo/utils/git/utils.py +++ b/kernel/tools/git/utils.py @@ -15,7 +15,7 @@ """ from urllib.parse import urlparse -from tripleo.utils.urls import URL, is_git +from kernel.tools.urls import URL, is_git def get_repository_fullname(url: URL) -> str: diff --git a/tripleo/utils/github/__init__.py b/kernel/tools/github/__init__.py similarity index 100% rename from tripleo/utils/github/__init__.py rename to kernel/tools/github/__init__.py diff --git a/tripleo/utils/github/pygithub.py b/kernel/tools/github/pygithub.py similarity index 95% rename from tripleo/utils/github/pygithub.py rename to kernel/tools/github/pygithub.py index 9f9bfde6..512e645a 100644 --- a/tripleo/utils/github/pygithub.py +++ b/kernel/tools/github/pygithub.py @@ -18,9 +18,9 @@ from github.Repository import Repository as RepoAPIv3 from overrides import overrides -from tripleo.utils.github import GitHub as IGitHub -from tripleo.utils.github import GitHubError -from tripleo.utils.github import Repository as IRepository +from kernel.tools.github import GitHub as IGitHub +from kernel.tools.github import GitHubError +from kernel.tools.github import Repository as IRepository class Repository(IRepository): diff --git a/cibyl/utils/io.py b/kernel/tools/io.py similarity index 100% rename from cibyl/utils/io.py rename to kernel/tools/io.py diff --git a/tripleo/utils/json.py b/kernel/tools/json.py similarity index 98% rename from tripleo/utils/json.py rename to kernel/tools/json.py index 1fe0293a..9efb64b4 100644 --- a/tripleo/utils/json.py +++ b/kernel/tools/json.py @@ -20,7 +20,7 @@ from jsonschema.validators import Draft7Validator from overrides import overrides -from tripleo.utils.fs import File +from kernel.tools.fs import File JSONValidator = Union[Draft7Validator] """Possible validators returned by the factory.""" diff --git a/cibyl/utils/net.py b/kernel/tools/net.py similarity index 100% rename from cibyl/utils/net.py rename to kernel/tools/net.py diff --git a/cibyl/utils/paths.py b/kernel/tools/paths.py similarity index 100% rename from cibyl/utils/paths.py rename to kernel/tools/paths.py diff --git a/cibyl/utils/reflection.py b/kernel/tools/reflection.py similarity index 97% rename from cibyl/utils/reflection.py rename to kernel/tools/reflection.py index 6b8da183..3ed47557 100644 --- a/cibyl/utils/reflection.py +++ b/kernel/tools/reflection.py @@ -18,7 +18,7 @@ from types import ModuleType from typing import Callable, List, Optional -from cibyl.utils.files import get_file_name_from_path +from kernel.tools.files import get_file_name_from_path def load_module(path: str) -> ModuleType: diff --git a/tripleo/utils/rng.py b/kernel/tools/rng.py similarity index 100% rename from tripleo/utils/rng.py rename to kernel/tools/rng.py diff --git a/cibyl/utils/sorting.py b/kernel/tools/sorting.py similarity index 100% rename from cibyl/utils/sorting.py rename to kernel/tools/sorting.py diff --git a/tripleo/utils/strings.py b/kernel/tools/strings.py similarity index 100% rename from tripleo/utils/strings.py rename to kernel/tools/strings.py diff --git a/cibyl/utils/strings.py b/kernel/tools/text.py similarity index 92% rename from cibyl/utils/strings.py rename to kernel/tools/text.py index 78fc93d6..d9ae08ff 100644 --- a/cibyl/utils/strings.py +++ b/kernel/tools/text.py @@ -13,20 +13,6 @@ # License for the specific language governing permissions and limitations # under the License. """ -import validators - - -def is_url(string: str) -> bool: - """ - :param string: The string to test. - :return: True if the string follows a URL format, False if not. - """ - result = validators.url(string) - - if isinstance(result, bool): - return result - - return False class IndentedTextBuilder: diff --git a/cibyl/utils/tree.py b/kernel/tools/tree.py similarity index 100% rename from cibyl/utils/tree.py rename to kernel/tools/tree.py diff --git a/tripleo/utils/urls.py b/kernel/tools/urls.py similarity index 97% rename from tripleo/utils/urls.py rename to kernel/tools/urls.py index 7b48a934..685d5624 100644 --- a/tripleo/utils/urls.py +++ b/kernel/tools/urls.py @@ -15,7 +15,7 @@ """ from urllib.parse import urlparse -from tripleo.utils.strings import is_url +from kernel.tools.strings import is_url class URL(str): diff --git a/tripleo/utils/yaml.py b/kernel/tools/yaml.py similarity index 100% rename from tripleo/utils/yaml.py rename to kernel/tools/yaml.py diff --git a/setup.cfg b/setup.cfg index f6c4f2b1..78e88041 100644 --- a/setup.cfg +++ b/setup.cfg @@ -18,8 +18,9 @@ classifier = [files] packages = - cibyl + kernel tripleo + cibyl [entry_points] console_scripts = diff --git a/tests/cibyl/e2e/test_jenkins.py b/tests/cibyl/e2e/test_jenkins.py index 710c3324..ef6db6b9 100644 --- a/tests/cibyl/e2e/test_jenkins.py +++ b/tests/cibyl/e2e/test_jenkins.py @@ -17,7 +17,7 @@ from cibyl.cli.main import main from cibyl.utils.colors import Colors -from cibyl.utils.strings import IndentedTextBuilder +from kernel.tools.text import IndentedTextBuilder from tests.cibyl.e2e.containers.jenkins import JenkinsContainer from tests.cibyl.e2e.fixtures import EndToEndTest diff --git a/tests/cibyl/e2e/test_zuul.py b/tests/cibyl/e2e/test_zuul.py index 6088c020..912e91a6 100644 --- a/tests/cibyl/e2e/test_zuul.py +++ b/tests/cibyl/e2e/test_zuul.py @@ -17,7 +17,7 @@ from unittest import skip from cibyl.cli.main import main -from cibyl.utils.strings import IndentedTextBuilder +from kernel.tools.text import IndentedTextBuilder from tests.cibyl.e2e.containers.zuul import OpenDevZuulContainer from tests.cibyl.e2e.fixtures import EndToEndTest diff --git a/tests/cibyl/intr/utils/test_json.py b/tests/cibyl/intr/utils/test_json.py deleted file mode 100644 index 31870e49..00000000 --- a/tests/cibyl/intr/utils/test_json.py +++ /dev/null @@ -1,85 +0,0 @@ -""" -# Copyright 2022 Red Hat -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -""" -import json -from json import JSONDecodeError -from tempfile import NamedTemporaryFile -from unittest import TestCase - -from jsonschema.exceptions import SchemaError -from jsonschema.validators import Draft7Validator - -from cibyl.utils.json import Draft7ValidatorFactory - - -class TestDraft7ValidatorFactory(TestCase): - """Tests for :class:`Draft7ValidatorFactory`. - """ - - def test_io_error(self): - """Checks that an error is thrown if the file cannot be opened. - """ - factory = Draft7ValidatorFactory() - - with self.assertRaises(IOError): - factory.from_file('') - - def test_json_error(self): - """Checks that an error is thrown if the file is not formatted as a - JSON. - """ - with NamedTemporaryFile('w') as file: - file.write('some-text') - - factory = Draft7ValidatorFactory() - - with self.assertRaises(JSONDecodeError): - factory.from_file(file.name) - - def test_schema_error(self): - """Checks that an error is thrown if the file is a JSON, but not a - schema. - """ - data = { - 'type': 'some-type' - } - - with NamedTemporaryFile(mode='w') as file: - file.write(json.dumps(data)) - file.flush() - - factory = Draft7ValidatorFactory() - - with self.assertRaises(SchemaError): - factory.from_file(file.name) - - def test_validator_is_build(self): - """Checks that if all conditions meet, the validator is built. - """ - data = { - '$schema': 'some-url', - 'type': 'string' - } - - with NamedTemporaryFile(mode='w') as file: - file.write(json.dumps(data)) - file.flush() - - factory = Draft7ValidatorFactory() - - result = factory.from_file(file.name) - - self.assertIsInstance(result, Draft7Validator) - self.assertEqual(result.schema, data) diff --git a/tests/cibyl/unit/config/test_config.py b/tests/cibyl/unit/config/test_config.py index 45d462fd..211dcf10 100644 --- a/tests/cibyl/unit/config/test_config.py +++ b/tests/cibyl/unit/config/test_config.py @@ -23,8 +23,8 @@ from cibyl.config import Config, ConfigFactory from cibyl.exceptions.cli import AbortedByUserError from cibyl.exceptions.config import ConfigurationNotFound, EmptyConfiguration -from cibyl.utils.net import DownloadError from cibyl.utils.yaml import encrypted_constructor, get_loader +from kernel.tools.net import DownloadError class TestConfig(TestCase): diff --git a/tests/cibyl/unit/utils/test_cache.py b/tests/cibyl/unit/utils/test_cache.py deleted file mode 100644 index d7a90373..00000000 --- a/tests/cibyl/unit/utils/test_cache.py +++ /dev/null @@ -1,69 +0,0 @@ -""" -# Copyright 2022 Red Hat -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -""" -from unittest import TestCase - -from cibyl.utils.cache import Cache - - -class TestCache(TestCase): - """Tests for :class:`Cache`. - """ - - def test_none_if_unknown(self): - """Checks that 'None' is returned if a key is not on the cache. - """ - key = 1 - - cache = Cache[int, str]() - - self.assertFalse(cache.has(key)) - self.assertIsNone(cache.get(key)) - - def test_adds_key(self): - """Checks that the cache is able to create a new entry within. - """ - key = 1 - value = 'some_text' - - cache = Cache[int, str]() - - self.assertFalse(cache.has(key)) - - cache.put(key, value) - - self.assertTrue(cache.has(key)) - self.assertEqual(value, cache.get(key)) - - def test_overrides_data(self): - """Checks that if I add something new to a known key, the data for - that key will be overridden. - """ - key = 1 - - val1 = 'text1' - val2 = 'text2' - - cache = Cache[int, str]( - storage={ - key: val1 - } - ) - - self.assertEqual(val1, cache.get(key)) - - cache.put(key, val2) - - self.assertEqual(val2, cache.get(key)) diff --git a/tests/tripleo/intr/utils/git/__init__.py b/tests/kernel/__init__.py similarity index 100% rename from tests/tripleo/intr/utils/git/__init__.py rename to tests/kernel/__init__.py diff --git a/tests/tripleo/intr/utils/github/__init__.py b/tests/kernel/intr/__init__.py similarity index 100% rename from tests/tripleo/intr/utils/github/__init__.py rename to tests/kernel/intr/__init__.py diff --git a/tests/tripleo/unit/utils/__init__.py b/tests/kernel/intr/tools/__init__.py similarity index 100% rename from tests/tripleo/unit/utils/__init__.py rename to tests/kernel/intr/tools/__init__.py diff --git a/tests/tripleo/unit/utils/git/__init__.py b/tests/kernel/intr/tools/git/__init__.py similarity index 100% rename from tests/tripleo/unit/utils/git/__init__.py rename to tests/kernel/intr/tools/git/__init__.py diff --git a/tests/tripleo/intr/utils/git/test_gitpython.py b/tests/kernel/intr/tools/git/test_gitpython.py similarity index 95% rename from tests/tripleo/intr/utils/git/test_gitpython.py rename to tests/kernel/intr/tools/git/test_gitpython.py index c63a5a02..fe877292 100644 --- a/tests/tripleo/intr/utils/git/test_gitpython.py +++ b/tests/kernel/intr/tools/git/test_gitpython.py @@ -16,9 +16,9 @@ from tempfile import TemporaryDirectory from unittest import TestCase -from tripleo.utils.fs import Dir -from tripleo.utils.git.gitpython import GitPython -from tripleo.utils.urls import URL +from kernel.tools.fs import Dir +from kernel.tools.git.gitpython import GitPython +from kernel.tools.urls import URL class TestGitPython(TestCase): diff --git a/tests/tripleo/intr/utils/git/test_utils.py b/tests/kernel/intr/tools/git/test_utils.py similarity index 93% rename from tests/tripleo/intr/utils/git/test_utils.py rename to tests/kernel/intr/tools/git/test_utils.py index d4cd462b..10d5ab7c 100644 --- a/tests/tripleo/intr/utils/git/test_utils.py +++ b/tests/kernel/intr/tools/git/test_utils.py @@ -15,8 +15,8 @@ """ from unittest import TestCase -from tripleo.utils.git.utils import get_repository_fullname -from tripleo.utils.urls import URL +from kernel.tools.git.utils import get_repository_fullname +from kernel.tools.urls import URL class TestGetRepositoryFullname(TestCase): diff --git a/tests/tripleo/unit/utils/github/__init__.py b/tests/kernel/intr/tools/github/__init__.py similarity index 100% rename from tests/tripleo/unit/utils/github/__init__.py rename to tests/kernel/intr/tools/github/__init__.py diff --git a/tests/tripleo/intr/utils/github/test_pygithub.py b/tests/kernel/intr/tools/github/test_pygithub.py similarity index 94% rename from tests/tripleo/intr/utils/github/test_pygithub.py rename to tests/kernel/intr/tools/github/test_pygithub.py index 503e9c67..2550d089 100644 --- a/tests/tripleo/intr/utils/github/test_pygithub.py +++ b/tests/kernel/intr/tools/github/test_pygithub.py @@ -15,8 +15,8 @@ """ from unittest import TestCase -from tripleo.utils.github import GitHubError -from tripleo.utils.github.pygithub import PyGitHub +from kernel.tools.github import GitHubError +from kernel.tools.github.pygithub import PyGitHub class TestPyGitHub(TestCase): diff --git a/tests/tripleo/intr/utils/test_fs.py b/tests/kernel/intr/tools/test_fs.py similarity index 99% rename from tests/tripleo/intr/utils/test_fs.py rename to tests/kernel/intr/tools/test_fs.py index 9438fddc..05afd831 100644 --- a/tests/tripleo/intr/utils/test_fs.py +++ b/tests/kernel/intr/tools/test_fs.py @@ -17,7 +17,7 @@ from tempfile import NamedTemporaryFile, TemporaryDirectory from unittest import TestCase, skip -from tripleo.utils.fs import Dir, File +from kernel.tools.fs import Dir, File class TestDir(TestCase): diff --git a/tests/tripleo/intr/utils/test_json.py b/tests/kernel/intr/tools/test_json.py similarity index 96% rename from tests/tripleo/intr/utils/test_json.py rename to tests/kernel/intr/tools/test_json.py index dfa0b147..83032f0f 100644 --- a/tests/tripleo/intr/utils/test_json.py +++ b/tests/kernel/intr/tools/test_json.py @@ -21,8 +21,8 @@ from jsonschema.exceptions import SchemaError from jsonschema.validators import Draft7Validator -from tripleo.utils.fs import File -from tripleo.utils.json import Draft7ValidatorFactory +from kernel.tools.fs import File +from kernel.tools.json import Draft7ValidatorFactory class TestDraft7ValidatorFactory(TestCase): diff --git a/tests/cibyl/intr/utils/test_net.py b/tests/kernel/intr/tools/test_net.py similarity index 96% rename from tests/cibyl/intr/utils/test_net.py rename to tests/kernel/intr/tools/test_net.py index 062c3001..559a6cad 100644 --- a/tests/cibyl/intr/utils/test_net.py +++ b/tests/kernel/intr/tools/test_net.py @@ -15,7 +15,7 @@ """ from unittest import TestCase, skip -from cibyl.utils.net import download_into_memory +from kernel.tools.net import download_into_memory from tests.cibyl.e2e.containers.httpd import HTTPDContainer diff --git a/tests/cibyl/intr/utils/test_sorting.py b/tests/kernel/intr/tools/test_sorting.py similarity index 96% rename from tests/cibyl/intr/utils/test_sorting.py rename to tests/kernel/intr/tools/test_sorting.py index 6410aee7..c2d731ca 100644 --- a/tests/cibyl/intr/utils/test_sorting.py +++ b/tests/kernel/intr/tools/test_sorting.py @@ -15,8 +15,8 @@ """ from unittest import TestCase -from cibyl.utils.sorting import (BubbleSortAlgorithm, NativeComparator, nsort, - sort) +from kernel.tools.sorting import (BubbleSortAlgorithm, NativeComparator, nsort, + sort) class TestNativeComparator(TestCase): diff --git a/tests/tripleo/intr/utils/test_strings.py b/tests/kernel/intr/tools/test_strings.py similarity index 96% rename from tests/tripleo/intr/utils/test_strings.py rename to tests/kernel/intr/tools/test_strings.py index 46c90fd4..59c0a1a0 100644 --- a/tests/tripleo/intr/utils/test_strings.py +++ b/tests/kernel/intr/tools/test_strings.py @@ -15,7 +15,7 @@ """ from unittest import TestCase -from tripleo.utils.strings import is_url +from kernel.tools.strings import is_url class TestIsURL(TestCase): diff --git a/tests/tripleo/intr/utils/test_urls.py b/tests/kernel/intr/tools/test_urls.py similarity index 96% rename from tests/tripleo/intr/utils/test_urls.py rename to tests/kernel/intr/tools/test_urls.py index e14ba0eb..54242a71 100644 --- a/tests/tripleo/intr/utils/test_urls.py +++ b/tests/kernel/intr/tools/test_urls.py @@ -15,7 +15,7 @@ """ from unittest import TestCase -from tripleo.utils.urls import URL, is_git, is_github +from kernel.tools.urls import URL, is_git, is_github class TestIsGit(TestCase): diff --git a/tripleo/utils/io.py b/tests/kernel/unit/__init__.py similarity index 68% rename from tripleo/utils/io.py rename to tests/kernel/unit/__init__.py index 315a78a7..992af0fd 100644 --- a/tripleo/utils/io.py +++ b/tests/kernel/unit/__init__.py @@ -13,15 +13,3 @@ # License for the specific language governing permissions and limitations # under the License. """ -from abc import ABC, abstractmethod - - -class Closeable(ABC): - """Interface meant to release the resources hold by the object. - """ - - @abstractmethod - def close(self): - """Releases any resources associated to this object. - """ - raise NotImplementedError diff --git a/tests/kernel/unit/tools/__init__.py b/tests/kernel/unit/tools/__init__.py new file mode 100644 index 00000000..992af0fd --- /dev/null +++ b/tests/kernel/unit/tools/__init__.py @@ -0,0 +1,15 @@ +""" +# Copyright 2022 Red Hat +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +""" diff --git a/tests/kernel/unit/tools/git/__init__.py b/tests/kernel/unit/tools/git/__init__.py new file mode 100644 index 00000000..992af0fd --- /dev/null +++ b/tests/kernel/unit/tools/git/__init__.py @@ -0,0 +1,15 @@ +""" +# Copyright 2022 Red Hat +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +""" diff --git a/tests/tripleo/unit/utils/git/test_gitpython.py b/tests/kernel/unit/tools/git/test_gitpython.py similarity index 96% rename from tests/tripleo/unit/utils/git/test_gitpython.py rename to tests/kernel/unit/tools/git/test_gitpython.py index 6bd3f086..f31424ed 100644 --- a/tests/tripleo/unit/utils/git/test_gitpython.py +++ b/tests/kernel/unit/tools/git/test_gitpython.py @@ -16,7 +16,7 @@ from unittest import TestCase from unittest.mock import Mock -from tripleo.utils.git.gitpython import Repository +from kernel.tools.git.gitpython import Repository class TestRepository(TestCase): diff --git a/tests/kernel/unit/tools/github/__init__.py b/tests/kernel/unit/tools/github/__init__.py new file mode 100644 index 00000000..992af0fd --- /dev/null +++ b/tests/kernel/unit/tools/github/__init__.py @@ -0,0 +1,15 @@ +""" +# Copyright 2022 Red Hat +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +""" diff --git a/tests/tripleo/unit/utils/github/test_pygithub.py b/tests/kernel/unit/tools/github/test_pygithub.py similarity index 97% rename from tests/tripleo/unit/utils/github/test_pygithub.py rename to tests/kernel/unit/tools/github/test_pygithub.py index bb8564fa..b25f0c27 100644 --- a/tests/tripleo/unit/utils/github/test_pygithub.py +++ b/tests/kernel/unit/tools/github/test_pygithub.py @@ -16,7 +16,7 @@ from unittest import TestCase from unittest.mock import Mock -from tripleo.utils.github.pygithub import PyGitHub, Repository +from kernel.tools.github.pygithub import PyGitHub, Repository class TestPyGitHub(TestCase): diff --git a/tests/tripleo/unit/utils/test_cache.py b/tests/kernel/unit/tools/test_cache.py similarity index 97% rename from tests/tripleo/unit/utils/test_cache.py rename to tests/kernel/unit/tools/test_cache.py index 0a6afc5c..1031aceb 100644 --- a/tests/tripleo/unit/utils/test_cache.py +++ b/tests/kernel/unit/tools/test_cache.py @@ -16,7 +16,7 @@ from unittest import TestCase from unittest.mock import Mock -from tripleo.utils.cache import Cache, CacheError +from kernel.tools.cache import Cache, CacheError class TestCache(TestCase): diff --git a/tests/cibyl/unit/utils/test_dicts.py b/tests/kernel/unit/tools/test_dicts.py similarity index 98% rename from tests/cibyl/unit/utils/test_dicts.py rename to tests/kernel/unit/tools/test_dicts.py index 34aef99d..d9a1d9fd 100644 --- a/tests/cibyl/unit/utils/test_dicts.py +++ b/tests/kernel/unit/tools/test_dicts.py @@ -20,8 +20,8 @@ from cibyl.models.ci.base.job import Job from cibyl.models.ci.zuul.project import Project from cibyl.models.ci.zuul.tenant import Tenant -from cibyl.utils.dicts import (chunk_dictionary_into_lists, intersect_models, - nsubset, subset) +from kernel.tools.dicts import (chunk_dictionary_into_lists, intersect_models, + nsubset, subset) class TestSubset(TestCase): diff --git a/tests/cibyl/unit/utils/test_files.py b/tests/kernel/unit/tools/test_files.py similarity index 98% rename from tests/cibyl/unit/utils/test_files.py rename to tests/kernel/unit/tools/test_files.py index ee0a947d..0ba8d454 100644 --- a/tests/cibyl/unit/utils/test_files.py +++ b/tests/kernel/unit/tools/test_files.py @@ -18,8 +18,8 @@ from unittest import TestCase from unittest.mock import Mock, call -from cibyl.utils.files import (FileSearch, get_file_name_from_path, - get_first_available_file) +from kernel.tools.files import (FileSearch, get_file_name_from_path, + get_first_available_file) class TestFileSearch(TestCase): diff --git a/tests/cibyl/unit/utils/test_net.py b/tests/kernel/unit/tools/test_net.py similarity index 96% rename from tests/cibyl/unit/utils/test_net.py rename to tests/kernel/unit/tools/test_net.py index a16672c1..e8fb138f 100644 --- a/tests/cibyl/unit/utils/test_net.py +++ b/tests/kernel/unit/tools/test_net.py @@ -16,7 +16,7 @@ from unittest import TestCase from unittest.mock import Mock -from cibyl.utils.net import DownloadError, download_into_memory, requests +from kernel.tools.net import DownloadError, download_into_memory, requests class TestDownloadIntoMemory(TestCase): diff --git a/tests/tripleo/unit/utils/test_paths.py b/tests/kernel/unit/tools/test_paths.py similarity index 96% rename from tests/tripleo/unit/utils/test_paths.py rename to tests/kernel/unit/tools/test_paths.py index 49ff470d..2048e4e9 100644 --- a/tests/tripleo/unit/utils/test_paths.py +++ b/tests/kernel/unit/tools/test_paths.py @@ -17,7 +17,7 @@ from unittest import TestCase from unittest.mock import Mock -from tripleo.utils.paths import resolve_home +from kernel.tools.paths import resolve_home class TestResolveHome(TestCase): diff --git a/tests/cibyl/unit/utils/test_reflection.py b/tests/kernel/unit/tools/test_reflection.py similarity index 88% rename from tests/cibyl/unit/utils/test_reflection.py rename to tests/kernel/unit/tools/test_reflection.py index 16e5529e..bf338124 100644 --- a/tests/cibyl/unit/utils/test_reflection.py +++ b/tests/kernel/unit/tools/test_reflection.py @@ -17,8 +17,8 @@ from unittest import TestCase from unittest.mock import Mock -import cibyl.utils.files -from cibyl.utils.reflection import get_classes_in, load_module +import kernel.tools.reflection as reflection +from kernel.tools.reflection import get_classes_in, load_module class TestLoadModule(TestCase): @@ -33,8 +33,8 @@ def test_three_steps_are_made(self): name = 'module' path = 'some/path' - cibyl.utils.reflection.get_file_name_from_path = Mock() - cibyl.utils.reflection.get_file_name_from_path.return_value = name + reflection.get_file_name_from_path = Mock() + reflection.get_file_name_from_path.return_value = name importlib.util.spec_from_file_location = Mock() importlib.util.spec_from_file_location.return_value = spec @@ -46,7 +46,7 @@ def test_three_steps_are_made(self): self.assertEqual(module, result) - cibyl.utils.reflection.get_file_name_from_path.assert_called_once_with( + reflection.get_file_name_from_path.assert_called_once_with( path ) diff --git a/tests/cibyl/unit/utils/test_strings.py b/tests/kernel/unit/tools/test_text.py similarity index 97% rename from tests/cibyl/unit/utils/test_strings.py rename to tests/kernel/unit/tools/test_text.py index af5bf9d9..fb72073d 100644 --- a/tests/cibyl/unit/utils/test_strings.py +++ b/tests/kernel/unit/tools/test_text.py @@ -15,7 +15,7 @@ """ from unittest import TestCase -from cibyl.utils.strings import IndentedTextBuilder +from kernel.tools.text import IndentedTextBuilder class TestIndentedTextBuilder(TestCase): diff --git a/tests/cibyl/unit/utils/test_tree.py b/tests/kernel/unit/tools/test_tree.py similarity index 98% rename from tests/cibyl/unit/utils/test_tree.py rename to tests/kernel/unit/tools/test_tree.py index 8760212f..4ed0158f 100644 --- a/tests/cibyl/unit/utils/test_tree.py +++ b/tests/kernel/unit/tools/test_tree.py @@ -16,7 +16,7 @@ from unittest import TestCase from unittest.mock import Mock -from cibyl.utils.tree import Leaf, Tree +from kernel.tools.tree import Leaf, Tree class TestLeaf(TestCase): diff --git a/tests/tripleo/unit/utils/test_urls.py b/tests/kernel/unit/tools/test_urls.py similarity index 92% rename from tests/tripleo/unit/utils/test_urls.py rename to tests/kernel/unit/tools/test_urls.py index d46f493b..b278ec6e 100644 --- a/tests/tripleo/unit/utils/test_urls.py +++ b/tests/kernel/unit/tools/test_urls.py @@ -16,14 +16,14 @@ from unittest import TestCase from unittest.mock import Mock, patch -from tripleo.utils.urls import URL +from kernel.tools.urls import URL class TestURL(TestCase): """Tests for :class:`URL`. """ - @patch('tripleo.utils.urls.is_url') + @patch('kernel.tools.urls.is_url') def test_new_on_valid_url(self, check_mock: Mock): """Checks that if the string is a URL, the string is created. """ @@ -35,7 +35,7 @@ def test_new_on_valid_url(self, check_mock: Mock): check_mock.assert_called_once_with(string) - @patch('tripleo.utils.urls.is_url') + @patch('kernel.tools.urls.is_url') def test_error_on_invalid_url(self, check_mock: Mock): """Checks that if the string is not a URL, an error is thrown. """ @@ -48,7 +48,7 @@ def test_error_on_invalid_url(self, check_mock: Mock): check_mock.assert_called_once_with(string) - @patch('tripleo.utils.urls.is_url') + @patch('kernel.tools.urls.is_url') def test_trims_string(self, check_mock: Mock): """Checks that before verifying the string, it is trimmed first. """ diff --git a/tests/tripleo/e2e/test_git.py b/tests/tripleo/e2e/test_git.py index a9e4f55e..1e2aa6a8 100644 --- a/tests/tripleo/e2e/test_git.py +++ b/tests/tripleo/e2e/test_git.py @@ -15,9 +15,9 @@ """ from unittest import TestCase +from kernel.tools.git import GitError +from kernel.tools.urls import URL from tripleo.insights import DeploymentLookUp, DeploymentOutline -from tripleo.utils.git import GitError -from tripleo.utils.urls import URL class TestOpenDev(TestCase): diff --git a/tests/tripleo/e2e/test_insights.py b/tests/tripleo/e2e/test_insights.py index 4677ff71..d3c9b000 100644 --- a/tests/tripleo/e2e/test_insights.py +++ b/tests/tripleo/e2e/test_insights.py @@ -38,7 +38,7 @@ def test_tls_everywhere(self): lookup = DeploymentLookUp() result = lookup.run(outline) - self.assertEqual('On', result.tls_everywhere) + self.assertEqual('On', result.components.neutron.tls_everywhere) def test_cinder_backend(self): """Checks that the cinder backend is extracted from a scenario @@ -48,7 +48,7 @@ def test_cinder_backend(self): lookup = DeploymentLookUp() result = lookup.run(outline) - self.assertEqual('rbd', result.cinder_backend) + self.assertEqual('rbd', result.components.cinder.backend) def test_neutron_backend(self): """Checks that the neutron backend is extracted from a scenario @@ -58,4 +58,4 @@ def test_neutron_backend(self): lookup = DeploymentLookUp() result = lookup.run(outline) - self.assertEqual('vxlan', result.neutron_backend) + self.assertEqual('vxlan', result.components.neutron.backend) diff --git a/tests/tripleo/intr/insights/test_git.py b/tests/tripleo/intr/insights/test_git.py index 60cc1a21..5809f4b7 100644 --- a/tests/tripleo/intr/insights/test_git.py +++ b/tests/tripleo/intr/insights/test_git.py @@ -15,8 +15,8 @@ """ from unittest import TestCase +from kernel.tools.urls import URL from tripleo.insights.git import GitCLIDownloader, GitDownloaderFetcher -from tripleo.utils.urls import URL class TestGitDownloaderFetcher(TestCase): diff --git a/tests/tripleo/intr/insights/test_interpreters.py b/tests/tripleo/intr/insights/test_interpreters.py index 6af2f92c..1374c476 100644 --- a/tests/tripleo/intr/insights/test_interpreters.py +++ b/tests/tripleo/intr/insights/test_interpreters.py @@ -16,12 +16,12 @@ from tempfile import TemporaryDirectory from unittest import TestCase +from kernel.tools.fs import cd_context_manager from tripleo.insights.exceptions import IllegibleData from tripleo.insights.interpreters import (EnvironmentInterpreter, FeatureSetInterpreter, NodesInterpreter, ReleaseInterpreter) -from tripleo.utils.fs import cd_context_manager class TestEnvironmentInterpreter(TestCase): diff --git a/tests/tripleo/unit/insights/test_git.py b/tests/tripleo/unit/insights/test_git.py index ac506a7f..36883678 100644 --- a/tests/tripleo/unit/insights/test_git.py +++ b/tests/tripleo/unit/insights/test_git.py @@ -16,10 +16,10 @@ from unittest import TestCase from unittest.mock import Mock, call, patch +from kernel.tools.yaml import YAMLError from tripleo.insights.exceptions import DownloadError from tripleo.insights.git import (GitCLIDownloader, GitDownload, GitDownloaderFetcher, GitHubDownloader) -from tripleo.utils.yaml import YAMLError class TestGitCLIDownloader(TestCase): diff --git a/tox.ini b/tox.ini index ec473538..7f291c3c 100644 --- a/tox.ini +++ b/tox.ini @@ -29,16 +29,18 @@ deps = -r {toxinidir}/requirements.txt -r {toxinidir}/test-requirements.txt commands = - python -m unittest discover tests/cibyl/unit + python -m unittest discover tests/kernel/unit python -m unittest discover tests/tripleo/unit + python -m unittest discover tests/cibyl/unit [testenv:intr] deps = -r {toxinidir}/requirements.txt -r {toxinidir}/test-requirements.txt commands = - python -m unittest discover tests/cibyl/intr + python -m unittest discover tests/kernel/intr python -m unittest discover tests/tripleo/intr + python -m unittest discover tests/cibyl/intr [testenv:e2e] @@ -51,6 +53,7 @@ deps = -r {toxinidir}/requirements.txt -r {toxinidir}/test-requirements.txt commands = + python -m unittest discover tests/tripleo/e2e python -m unittest discover tests/cibyl/e2e [testenv:coverage] @@ -59,8 +62,9 @@ deps = -r {toxinidir}/test-requirements.txt commands = coverage erase - coverage run -a -m unittest discover tests/cibyl/unit + coverage run -a -m unittest discover tests/kernel/unit coverage run -a -m unittest discover tests/tripleo/unit + coverage run -a -m unittest discover tests/cibyl/unit coverage report -m --fail-under=85 [testenv:docs] diff --git a/tripleo/insights/defaults.py b/tripleo/insights/defaults.py index 7214b144..a913c36d 100644 --- a/tripleo/insights/defaults.py +++ b/tripleo/insights/defaults.py @@ -13,7 +13,7 @@ # License for the specific language governing permissions and limitations # under the License. """ -from tripleo.utils.urls import URL +from kernel.tools.urls import URL DEFAULT_QUICKSTART = URL('https://github.com/openstack/tripleo-quickstart.git') """Default URL for TripleO QuickStart repository.""" diff --git a/tripleo/insights/git.py b/tripleo/insights/git.py index 772f2bc9..c9f0a105 100644 --- a/tripleo/insights/git.py +++ b/tripleo/insights/git.py @@ -20,19 +20,19 @@ from cached_property import cached_property from overrides import overrides +from kernel.tools.fs import Dir +from kernel.tools.git import Git, GitError +from kernel.tools.git import Repository as GitRepo +from kernel.tools.git.gitpython import GitPython +from kernel.tools.git.utils import get_repository_fullname +from kernel.tools.github import GitHub, GitHubError +from kernel.tools.github import Repository as GitHubRepo +from kernel.tools.github.pygithub import PyGitHub +from kernel.tools.paths import resolve_home +from kernel.tools.rng import get_new_uuid +from kernel.tools.urls import URL, is_git, is_github +from kernel.tools.yaml import YAML, StandardYAMLParser, YAMLError, YAMLParser from tripleo.insights.exceptions import DownloadError, InvalidURL -from tripleo.utils.fs import Dir -from tripleo.utils.git import Git, GitError -from tripleo.utils.git import Repository as GitRepo -from tripleo.utils.git.gitpython import GitPython -from tripleo.utils.git.utils import get_repository_fullname -from tripleo.utils.github import GitHub, GitHubError -from tripleo.utils.github import Repository as GitHubRepo -from tripleo.utils.github.pygithub import PyGitHub -from tripleo.utils.paths import resolve_home -from tripleo.utils.rng import get_new_uuid -from tripleo.utils.urls import URL, is_git, is_github -from tripleo.utils.yaml import YAML, StandardYAMLParser, YAMLError, YAMLParser LOG = logging.getLogger(__name__) diff --git a/tripleo/insights/interpreters.py b/tripleo/insights/interpreters.py index 2b399dde..a5af400c 100644 --- a/tripleo/insights/interpreters.py +++ b/tripleo/insights/interpreters.py @@ -17,13 +17,13 @@ from enum import Enum from typing import Dict, Iterable, NamedTuple, Optional, Sequence +from kernel.tools.fs import File, cd_context_manager +from kernel.tools.json import Draft7ValidatorFactory, JSONValidatorFactory +from kernel.tools.yaml import YAML from tripleo import __path__ as tripleo_package_path from tripleo.insights.exceptions import IllegibleData from tripleo.insights.io import Topology from tripleo.insights.topology import Node -from tripleo.utils.fs import File, cd_context_manager -from tripleo.utils.json import Draft7ValidatorFactory, JSONValidatorFactory -from tripleo.utils.yaml import YAML class FileInterpreter(ABC): diff --git a/tripleo/insights/io.py b/tripleo/insights/io.py index 536339e4..f69e4cb1 100644 --- a/tripleo/insights/io.py +++ b/tripleo/insights/io.py @@ -16,12 +16,12 @@ from dataclasses import dataclass, field from typing import Optional +from kernel.tools.urls import URL from tripleo.insights.defaults import (DEFAULT_ENVIRONMENT_FILE, DEFAULT_FEATURESET_FILE, DEFAULT_NODES_FILE, DEFAULT_QUICKSTART, DEFAULT_RELEASE_FILE, DEFAULT_THT) from tripleo.insights.topology import Topology -from tripleo.utils.urls import URL @dataclass diff --git a/tripleo/insights/lookup.py b/tripleo/insights/lookup.py index 0e905eb2..4d9982fd 100644 --- a/tripleo/insights/lookup.py +++ b/tripleo/insights/lookup.py @@ -17,6 +17,9 @@ from dataclasses import dataclass from typing import NamedTuple, Optional +from kernel.tools.cache import Cache +from kernel.tools.urls import URL +from kernel.tools.yaml import YAML from tripleo.insights.git import GitDownload from tripleo.insights.interpreters import (EnvironmentInterpreter, FeatureSetInterpreter, @@ -26,9 +29,6 @@ from tripleo.insights.io import DeploymentOutline, DeploymentSummary from tripleo.insights.tripleo import THTBranchCreator, THTPathCreator from tripleo.insights.validation import OutlineValidator -from tripleo.utils.cache import Cache -from tripleo.utils.urls import URL -from tripleo.utils.yaml import YAML LOG = logging.getLogger(__name__) diff --git a/tripleo/insights/validation.py b/tripleo/insights/validation.py index d87ec7b4..e439969e 100644 --- a/tripleo/insights/validation.py +++ b/tripleo/insights/validation.py @@ -15,9 +15,9 @@ """ from typing import Callable, Iterable, Optional +from kernel.tools.urls import is_git from tripleo.insights.exceptions import InsightsError, InvalidURL from tripleo.insights.io import DeploymentOutline -from tripleo.utils.urls import is_git Outline = DeploymentOutline Validation = Callable[[Outline], Optional[InsightsError]] diff --git a/tripleo/utils/logging.py b/tripleo/utils/logging.py index 11ca4f81..a932e7c7 100644 --- a/tripleo/utils/logging.py +++ b/tripleo/utils/logging.py @@ -20,7 +20,7 @@ import colorlog -from tripleo.utils.fs import File +from kernel.tools.fs import File GENERIC_LOG_FORMAT = '{}%(levelname)-8s %(name)-20s %(message)s' """Base format for logging messages.""" diff --git a/tripleo/utils/paths.py b/tripleo/utils/paths.py deleted file mode 100644 index 0bbb8df8..00000000 --- a/tripleo/utils/paths.py +++ /dev/null @@ -1,42 +0,0 @@ -""" -# Copyright 2022 Red Hat -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -""" -from pathlib import Path -from typing import Callable - -Preprocessor = Callable[[Path], Path] - - -def resolve_home(path: Path) -> Path: - """Resolves the '~' shortcut used to indicate that a path starts from - the home directory. - - The symbol will only be treated if it is the first character of the path, - anywhere else will be ignored. - - If the symbol does not appear, then everything is returned as is. - - The original path is not modified. A copy of it is returned instead. - - :param path: The path to resolve. - :return: The same path, with the '~' replaced to the absolute path of the - home directory. - """ - raw = str(path) - - if raw.startswith('~'): - raw = raw.replace('~', str(path.home())) - - return Path(raw)