Skip to content

Commit

Permalink
configuration: deprecate old style global state interface
Browse files Browse the repository at this point in the history
All built-in west commands are using the new WestCommand.config state
to access the configuration values. Extension commands which are
reading configuration values should migrate to using this interface as
well, as should any other out of tree users of the west.configuration
API.

Deprecation, rather than removal, is necessary since 'west build' and
other important Zephyr extensions rely on the existing API.

Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
  • Loading branch information
mbolivar-nordic committed Mar 18, 2022
1 parent ae7bf7b commit d8853a4
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions src/west/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import platform
from enum import Enum
from typing import Any, Dict, Iterable, List, Optional, Tuple, TYPE_CHECKING
import warnings

from west.util import west_dir, WestNotFound, PathType

Expand Down Expand Up @@ -391,14 +392,16 @@ def _cf_to_dict(cf: Optional[_InternalCF]) -> Dict[str, Any]:
return ret


# Configuration values.
#
# Initially empty, populated in read_config(). Always having this available is
# nice in case something checks configuration values before the configuration
# file has been read (e.g. the log.py functions, to check color settings, and
# tests).
# Global parser containing configuration values, for backwards
# compatibility. Populated in main.py to keep legacy extensions
# working following the deprecation of this API.
config = _configparser()

def _deprecated(old_function):
warnings.warn(f'{old_function} is deprecated; '
'use a west.configuration.Configuration object',
DeprecationWarning, stacklevel=2)

def read_config(configfile: Optional[ConfigFile] = None,
config: configparser.ConfigParser = config,
topdir: Optional[PathType] = None) -> None:
Expand Down Expand Up @@ -426,6 +429,8 @@ def read_config(configfile: Optional[ConfigFile] = None,
:param config: configuration object to read into
:param topdir: west workspace root to read local options from
'''
_deprecated('read_config')

if configfile is None:
configfile = ConfigFile.ALL
config.read(_gather_configs(configfile, topdir), encoding='utf-8')
Expand All @@ -451,6 +456,8 @@ def update_config(section: str, key: str, value: Any,
found by searching the file system (raising WestNotFound if
one is not found).
'''
_deprecated('update_config')

if configfile == ConfigFile.ALL:
# Not possible to update ConfigFile.ALL, needs specific conf file here.
raise ValueError(f'invalid configfile: {configfile}')
Expand Down Expand Up @@ -494,6 +501,8 @@ def delete_config(section: str, key: str,
found by searching the file system (raising WestNotFound if
one is not found).
'''
_deprecated('delete_config')

stop = False
if configfile is None:
to_check = [_location(x, topdir=topdir) for x in
Expand Down

0 comments on commit d8853a4

Please sign in to comment.