Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions src/west/configuration.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Copyright (c) 2018, 2019, Nordic Semiconductor ASA
#
# SPDX-License-Identifier: Apache-2.0
Expand Down Expand Up @@ -58,6 +58,8 @@
# For internal use only; convenience interface for reading and
# writing INI-style [section] key = value configuration files,
# but presenting a west-style section.key = value style API.
# Unlike the higher level and public "Configuration" class, there is
# one _InternalCF object for each location: LOCAL, GLOBAL,...

@staticmethod
def parse_key(dotted_name: str):
Expand Down Expand Up @@ -225,8 +227,9 @@
'''
return self._get(lambda cf: cf.getfloat(option), default, configfile)

def _get(self, getter, default, configfile):
for cf in self._whence(configfile):
def _get(self, getter, default, locations: ConfigFile):
# Search requested location(s) from higher to lower precedence
for cf in self._whence(locations):
if cf is None:
continue
try:
Expand All @@ -236,21 +239,21 @@

return default

def _whence(self, configfile):
if configfile == ConfigFile.ALL:
def _whence(self, locations: ConfigFile) -> list[_InternalCF | None]:
if locations == ConfigFile.ALL:
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think a large part of the readability issue is: ConfigFile is not a configuration file but an Enum. This is one way to mitigate this problem (without the massive churn of renaming the Enum)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The name config for a ConfigFile object is used at many more places. It is always this enum.
So I would prefer if the naming is consistent.
Would do you think about changing the variable name (and maybe also the type name) at all places?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think local variables of a given type have to be named the same across the board.

I submitted a change in this particular place because I found it especially confusing. I had a very quick look at other places and while the name configfile is still not good, they generally did not seem as confusing. So not worth the git churn IMHO. If you find some other confusing places then by all means submit another PR.

if self._local is not None:
return [self._local, self._global, self._system]
return [self._global, self._system]
elif configfile == ConfigFile.SYSTEM:
elif locations == ConfigFile.SYSTEM:
return [self._system]
elif configfile == ConfigFile.GLOBAL:
elif locations == ConfigFile.GLOBAL:
return [self._global]
elif configfile == ConfigFile.LOCAL:
elif locations == ConfigFile.LOCAL:
if self._local is None:
raise MalformedConfig('local configuration file not found')
return [self._local]
else:
raise ValueError(configfile)
raise ValueError(locations)

def set(self, option: str, value: Any,
configfile: ConfigFile = ConfigFile.LOCAL) -> None:
Expand Down
Loading