Skip to content
Merged
Show file tree
Hide file tree
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
75 changes: 0 additions & 75 deletions .github/workflows/format.yml

This file was deleted.

5 changes: 4 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ jobs:
# Run linter/type checks only on 1 combination
- os: ubuntu-latest
python-version: '3.13'
task: lint
task: gh-lint
- os: ubuntu-latest
python-version: '3.13'
task: gh-format
- os: ubuntu-latest
python-version: '3.13'
task: types
Expand Down
9 changes: 8 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ extend-select = [
[tool.ruff.format]
quote-style = "preserve"
line-ending = "lf"
# Enable preview mode for Github Annotations added in 0.13.3
preview = true

[tool.mypy]
mypy_path = "src"
Expand All @@ -114,5 +116,10 @@ env = {PYTHONIOENCODING = "utf-8"}

[tool.poe.tasks]
lint = "ruff check ."
format = "ruff format"
types = "mypy --package west"
all = ["test", "lint", "types"]
all = ["test", "lint", "format", "types"]

# Github specific tasks
gh-lint = "ruff check --output-format=github ."
gh-format = "ruff format --check --output-format=github"
88 changes: 50 additions & 38 deletions src/west/app/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,49 +83,67 @@
class Config(WestCommand):
def __init__(self):
super().__init__(
'config',
'get or set config file values',
CONFIG_DESCRIPTION,
requires_workspace=False)
'config', 'get or set config file values', CONFIG_DESCRIPTION, requires_workspace=False
)

def do_add_parser(self, parser_adder):
parser = parser_adder.add_parser(
self.name,
help=self.help,
formatter_class=argparse.RawDescriptionHelpFormatter,
description=self.description,
epilog=CONFIG_EPILOG)
epilog=CONFIG_EPILOG,
)

group = parser.add_argument_group(
"action to perform (give at most one)"
).add_mutually_exclusive_group()

group.add_argument('-l', '--list', action='store_true',
help='list all options and their values')
group.add_argument('-d', '--delete', action='store_true',
help='delete an option in one config file')
group.add_argument('-D', '--delete-all', action='store_true',
help="delete an option everywhere it's set")
group.add_argument('-a', '--append', action='store_true',
help='append to an existing value')
group.add_argument(
'-l', '--list', action='store_true', help='list all options and their values'
)
group.add_argument(
'-d', '--delete', action='store_true', help='delete an option in one config file'
)
group.add_argument(
'-D', '--delete-all', action='store_true', help="delete an option everywhere it's set"
)
group.add_argument(
'-a', '--append', action='store_true', help='append to an existing value'
)

group = parser.add_argument_group(
"configuration file to use (give at most one)"
).add_mutually_exclusive_group()

group.add_argument('--system', dest='configfile',
action='store_const', const=SYSTEM,
help='system-wide file')
group.add_argument('--global', dest='configfile',
action='store_const', const=GLOBAL,
help='global (user-wide) file')
group.add_argument('--local', dest='configfile',
action='store_const', const=LOCAL,
help="this workspace's file")

parser.add_argument('name', nargs='?',
help='''config option in section.key format;
e.g. "foo.bar" is section "foo", key "bar"''')
group.add_argument(
'--system',
dest='configfile',
action='store_const',
const=SYSTEM,
help='system-wide file',
)
group.add_argument(
'--global',
dest='configfile',
action='store_const',
const=GLOBAL,
help='global (user-wide) file',
)
group.add_argument(
'--local',
dest='configfile',
action='store_const',
const=LOCAL,
help="this workspace's file",
)

parser.add_argument(
'name',
nargs='?',
help='''config option in section.key format;
e.g. "foo.bar" is section "foo", key "bar"''',
)
parser.add_argument('value', nargs='?', help='value to set "name" to')

return parser
Expand All @@ -136,8 +154,7 @@ def do_run(self, args, user_args):
if args.name:
self.parser.error('-l cannot be combined with name argument')
elif not args.name:
self.parser.error('missing argument name '
'(to list all options and values, use -l)')
self.parser.error('missing argument name (to list all options and values, use -l)')
elif args.append:
if args.value is None:
self.parser.error('-a requires both name and value')
Expand Down Expand Up @@ -174,16 +191,14 @@ def delete(self, args):
return
except KeyError as err:
if i == len(configfiles) - 1:
self.dbg(
f'{args.name} was not set in requested location(s)')
self.dbg(f'{args.name} was not set in requested location(s)')
raise CommandError(returncode=1) from err
except PermissionError as pe:
self._perm_error(pe, configfile, args.name)

def check_config(self, option):
if '.' not in option:
self.die(f'invalid configuration option "{option}"; '
'expected "section.key" format')
self.die(f'invalid configuration option "{option}"; expected "section.key" format')

def read(self, args):
self.check_config(args.name)
Expand All @@ -199,8 +214,7 @@ def append(self, args):
where = args.configfile or LOCAL
value = self.config.get(args.name, configfile=where)
if value is None:
self.die(f'option {args.name} not found in the {where.name.lower()} '
'configuration file')
self.die(f'option {args.name} not found in the {where.name.lower()} configuration file')
args.value = value + args.value
self.write(args)

Expand All @@ -213,7 +227,5 @@ def write(self, args):
self._perm_error(pe, what, args.name)

def _perm_error(self, pe, what, name):
rootp = ('; are you root/administrator?' if what in [SYSTEM, ALL]
else '')
self.die(f"can't update {name}: "
f"permission denied when writing {pe.filename}{rootp}")
rootp = '; are you root/administrator?' if what in [SYSTEM, ALL] else ''
self.die(f"can't update {name}: permission denied when writing {pe.filename}{rootp}")
Loading