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 10, 2022
1 parent 9096a94 commit 7d8fab6
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 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 @@ -399,6 +400,11 @@ def _cf_to_dict(cf: Optional[_InternalCF]) -> Dict[str, Any]:
# tests).
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 +432,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 +459,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 +504,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 7d8fab6

Please sign in to comment.