From 9e136e532d4eea77609ef59eb590022066d2165d Mon Sep 17 00:00:00 2001 From: Jan Kiszka Date: Tue, 26 Sep 2017 13:30:00 +0200 Subject: [PATCH] config: Remove dynamic configuration variant We no longer see an urging use case for it. All field scenarios can perfectly be modeled with the static format. Signed-off-by: Jan Kiszka --- docs/userguide.rst | 87 ++-------------------------- kas/config.py | 138 +-------------------------------------------- 2 files changed, 5 insertions(+), 220 deletions(-) diff --git a/docs/userguide.rst b/docs/userguide.rst index 7c15c56..6b15518 100644 --- a/docs/userguide.rst +++ b/docs/userguide.rst @@ -122,15 +122,6 @@ Use Cases Project Configuration --------------------- -Two types of configuration file formats are supported. - -For most purposes the static configuration should be used. -In case this static configuration file does not provide enough options for -customization, the dynamic configuration file format can be used. - -Static project configuration -~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - Currently JSON and YAML is supported as the base file format. Since YAML is arguable easier to read, this documentation focuses on the YAML format. @@ -189,7 +180,7 @@ append entries in files that include this configuration by naming an entry the same (overwriting) or using a unused name (appending). Including in-tree configuration files -..................................... +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Its currently possible to include kas configuration files from the same repository/layer like this: @@ -206,7 +197,7 @@ repository/layer like this: The specified files are addressed relative to your current configuration file. Including configuration files from other repos -.............................................. +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Its also possible to include configuration files from other repos like this: @@ -253,8 +244,8 @@ different include files. Note that the order of the configuration file entries is not preserved within one include file, because the parser creates normal unordered dictionaries. -Static configuration reference -.............................. +Configuration reference +~~~~~~~~~~~~~~~~~~~~~~~ * ``header``: dict [required] The header of every kas configuration file. It contains information about @@ -370,73 +361,3 @@ Static configuration reference * ``http_proxy``: string [optional] * ``https_proxy``: string [optional] * ``no_proxy``: string [optional] - -Dynamic project configuration -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -**NOTE: Dynamic project configuration is experimental. The API may change or -even be obsoleted in future versions. Please provide feedback if you consider -it useful.** - -The dynamic project configuration is plain Python with following -mandatory functions which need to be provided: - -.. code-block:: python - - def get_machine(config): - return 'qemu' - - - def get_distro(config): - return 'poky' - - - def get_repos(target): - repos = [] - - repos.append(Repo( - url='URL', - refspec='REFSPEC')) - - repos.append(Repo( - url='https://git.yoctoproject.org/git/poky', - refspec='krogoth', - layers=['meta', 'meta-poky', 'meta-yocto-bsp']))) - - return repos - -Additionally, ``get_bblayers_conf_header()``, ``get_local_conf_header()`` can -be added. - -.. code-block:: python - - def get_bblayers_conf_header(): - return """POKY_BBLAYERS_CONF_VERSION = "2" - BBPATH = "${TOPDIR}" - BBFILES ?= "" - """ - - - def get_local_conf_header(): - return """PATCHRESOLVE = "noop" - CONF_VERSION = "1" - IMAGE_FSTYPES = "tar" - """ - -Furthermore, you can add pre and post hooks (``*_prepend``, ``*_append``) for -the exection steps in kas core, e.g. - -.. code-block:: python - - def build_prepend(config): - # disable distro check - with open(config.build_dir + '/conf/sanity.conf', 'w') as f: - f.write('\n') - - - def build_append(config): - if 'CI' in os.environ: - build_native_package(config) - run_wic(config) - -TODO: Document the complete configuration API. diff --git a/kas/config.py b/kas/config.py index c6944a5..e1d87b9 100644 --- a/kas/config.py +++ b/kas/config.py @@ -25,7 +25,6 @@ import os import logging -import errno try: from distro import id as get_distro_id @@ -198,135 +197,6 @@ class Config: return self._config.get('gitlabci_config', '') -class ConfigPython(Config): - """ - Implementation of a configuration that uses a Python script. - """ - def __init__(self, filename, target, task): - # pylint: disable=exec-used - - super().__init__() - self.filename = os.path.abspath(filename) - try: - with open(self.filename) as fds: - env = {} - data = fds.read() - exec(data, env) - self._config = env - except IOError: - raise IOError(errno.ENOENT, os.strerror(errno.ENOENT), - self.filename) - - self.create_config(target, task) - self.setup_environ() - - def __str__(self): - output = 'target: {}\n'.format(self.target) - output = 'task: {}\n'.format(self.task) - output += 'repos:\n' - for repo in self.get_repos(): - output += ' {}\n'.format(repo.__str__()) - output += 'environ:\n' - for key, value in self.environ.items(): - output += ' {} = {}\n'.format(key, value) - output += 'proxy:\n' - for key, value in self.get_proxy_config().items(): - output += ' {} = {}\n'.format(key, value) - return output - - def pre_hook(self, fname): - try: - self._config[fname + '_prepend'](self) - except KeyError: - pass - - def post_hook(self, fname): - try: - self._config[fname + '_append'](self) - except KeyError: - pass - - def get_hook(self, fname): - try: - return self._config[fname] - except KeyError: - return None - - def create_config(self, target, task): - """ - Sets the configuration for `target` - """ - self.target = 'core-image-minimal' if target is None else target - self.task = 'build' if task is None else task - self.repos = self._config['get_repos'](self, target) - - def get_proxy_config(self): - return self._config['get_proxy_config']() - - def get_repos(self): - return iter(self.repos) - - def get_target(self): - """ - Returns the target - """ - return self.target - - def get_bitbake_target(self): - """ - Return the bitbake target - """ - try: - return self._config['get_bitbake_target'](self) - except KeyError: - return self.target - - def get_bblayers_conf_header(self): - """ - Returns the bblayers.conf header - """ - try: - return self._config['get_bblayers_conf_header']() - except KeyError: - return '' - - def get_local_conf_header(self): - """ - Returns the local.conf header - """ - try: - return self._config['get_local_conf_header']() - except KeyError: - return '' - - def get_machine(self): - """ - Returns the machine - """ - try: - return self._config['get_machine'](self) - except KeyError: - return 'qemu' - - def get_distro(self): - """ - Returns the distro - """ - try: - return self._config['get_distro'](self) - except KeyError: - return 'poky' - - def get_gitlabci_config(self): - """ - Returns the GitlabCI configuration - """ - try: - return self._config['get_gitlabci_config'](self) - except KeyError: - return '' - - class ConfigStatic(Config): """ Implements the static kas configuration based on config files. @@ -437,10 +307,4 @@ def load_config(filename, target, task): Return configuration generated from `filename`. """ - (_, ext) = os.path.splitext(filename) - if ext == '.py': - cfg = ConfigPython(filename, target, task) - else: - cfg = ConfigStatic(filename, target, task) - - return cfg + return ConfigStatic(filename, target, task)