Skip to content

Commit 6a3593f

Browse files
carlescuficfriedt
authored andcommitted
west: runners: Add a deprecation action to the core code
In order to allow for further options to be deprecated with minimal impact, add a deprecation argparse Action and a callable instantiator that can be used to deprecate options in favor of new ones. Signed-off-by: Carles Cufi <[email protected]>
1 parent 2ccfd22 commit 6a3593f

File tree

4 files changed

+23
-3
lines changed

4 files changed

+23
-3
lines changed

scripts/west_commands/runners/core.py

+11
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,17 @@ class _ToggleAction(argparse.Action):
288288
def __call__(self, parser, args, ignored, option):
289289
setattr(args, self.dest, not option.startswith('--no-'))
290290

291+
class DeprecatedAction(argparse.Action):
292+
293+
def __call__(self, parser, namespace, values, option_string=None):
294+
_logger.warning(f'Argument {self.option_strings[0]} is deprecated, '
295+
f'use {self._replacement} instead.')
296+
setattr(namespace, self.dest, values)
297+
298+
def depr_action(*args, replacement=None, **kwargs):
299+
action = DeprecatedAction(*args, **kwargs)
300+
setattr(action, '_replacement', replacement)
301+
return action
291302

292303
class ZephyrBinaryRunner(abc.ABC):
293304
'''Abstract superclass for binary runners (flashers, debuggers).

scripts/west_commands/runners/jlink.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
'''Runner for debugging with J-Link.'''
66

77
import argparse
8+
from functools import partial
89
import logging
910
import os
1011
from pathlib import Path
@@ -13,7 +14,7 @@
1314
import sys
1415
import tempfile
1516

16-
from runners.core import ZephyrBinaryRunner, RunnerCaps
17+
from runners.core import ZephyrBinaryRunner, RunnerCaps, depr_action
1718

1819
try:
1920
from pylink.library import Library
@@ -83,6 +84,8 @@ def do_add_parser(cls, parser):
8384

8485
# Optional:
8586
parser.add_argument('--id', required=False, dest='dev_id',
87+
action=partial(depr_action,
88+
replacement='-i/--dev-id'),
8689
help='Deprecated: use -i/--dev-id instead')
8790
parser.add_argument('--iface', default='swd',
8891
help='interface to use, default is swd')

scripts/west_commands/runners/nrfjprog.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@
55

66
'''Runner for flashing with nrfjprog.'''
77

8+
from functools import partial
89
import os
910
from pathlib import Path
1011
import shlex
1112
import subprocess
1213
import sys
1314
from re import fullmatch, escape
1415

15-
from runners.core import ZephyrBinaryRunner, RunnerCaps
16+
from runners.core import ZephyrBinaryRunner, RunnerCaps, depr_action
1617

1718
try:
1819
from intelhex import IntelHex
@@ -80,6 +81,8 @@ def do_add_parser(cls, parser):
8081
action='store_true',
8182
help='use reset instead of pinreset')
8283
parser.add_argument('--snr', required=False, dest='dev_id',
84+
action=partial(depr_action,
85+
replacement='-i/--dev-id'),
8386
help='Deprecated: use -i/--dev-id instead')
8487
parser.add_argument('--tool-opt', default=[], action='append',
8588
help='''Additional options for nrfjprog,

scripts/west_commands/runners/pyocd.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@
44

55
'''Runner for pyOCD .'''
66

7+
from functools import partial
78
import os
89
from os import path
910

1011
from runners.core import ZephyrBinaryRunner, RunnerCaps, \
11-
BuildConfiguration
12+
BuildConfiguration, depr_action
1213

1314
DEFAULT_PYOCD_GDB_PORT = 3333
1415
DEFAULT_PYOCD_TELNET_PORT = 4444
@@ -111,6 +112,8 @@ def do_add_parser(cls, parser):
111112
parser.add_argument('--tui', default=False, action='store_true',
112113
help='if given, GDB uses -tui')
113114
parser.add_argument('--board-id', dest='dev_id',
115+
action=partial(depr_action,
116+
replacement='-i/--dev-id'),
114117
help='Deprecated: use -i/--dev-id instead')
115118
parser.add_argument('--tool-opt',
116119
help='''Additional options for pyocd Commander,

0 commit comments

Comments
 (0)