Skip to content

Commit 3cc4af1

Browse files
committed
Refactor project config options
1 parent 8d05903 commit 3cc4af1

File tree

14 files changed

+401
-258
lines changed

14 files changed

+401
-258
lines changed

Diff for: .vscode/settings.json

-15
This file was deleted.

Diff for: Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ yapf:
1010
yapf --recursive --in-place platformio/
1111

1212
test:
13-
py.test -v -s -n 3 --dist=loadscope tests --ignore tests/test_examples.py --ignore tests/test_pkgmanifest.py
13+
py.test --verbose --capture=no --exitfirst -n 3 --dist=loadscope tests --ignore tests/test_examples.py --ignore tests/test_pkgmanifest.py
1414

1515
before-commit: isort yapf lint test
1616

Diff for: platformio/commands/device.py

+10-15
Original file line numberDiff line numberDiff line change
@@ -163,22 +163,17 @@ def device_list( # pylint: disable=too-many-branches
163163
"--environment",
164164
help="Load configuration from `platformio.ini` and specified environment")
165165
def device_monitor(**kwargs): # pylint: disable=too-many-branches
166-
custom_monitor_flags = []
167166
try:
168167
env_options = get_project_options(kwargs['project_dir'],
169168
kwargs['environment'])
170-
if "monitor_flags" in env_options:
171-
custom_monitor_flags = ProjectConfig.parse_multi_values(
172-
env_options['monitor_flags'])
173-
if env_options:
174-
for k in ("port", "speed", "rts", "dtr"):
175-
k2 = "monitor_%s" % k
176-
if k == "speed":
177-
k = "baud"
178-
if kwargs[k] is None and k2 in env_options:
179-
kwargs[k] = env_options[k2]
180-
if k != "port":
181-
kwargs[k] = int(kwargs[k])
169+
for k in ("port", "speed", "rts", "dtr"):
170+
k2 = "monitor_%s" % k
171+
if k == "speed":
172+
k = "baud"
173+
if kwargs[k] is None and k2 in env_options:
174+
kwargs[k] = env_options[k2]
175+
if k != "port":
176+
kwargs[k] = int(kwargs[k])
182177
except exception.NotPlatformIOProject:
183178
pass
184179

@@ -187,12 +182,12 @@ def device_monitor(**kwargs): # pylint: disable=too-many-branches
187182
if len(ports) == 1:
188183
kwargs['port'] = ports[0]['port']
189184

190-
sys.argv = ["monitor"] + custom_monitor_flags
185+
sys.argv = ["monitor"] + env_options.get("monitor_flags", [])
191186
for k, v in kwargs.items():
192187
if k in ("port", "baud", "rts", "dtr", "environment", "project_dir"):
193188
continue
194189
k = "--" + k.replace("_", "-")
195-
if k in custom_monitor_flags:
190+
if k in env_options.get("monitor_flags", []):
196191
continue
197192
if isinstance(v, bool):
198193
if v:

Diff for: platformio/commands/home/rpc/handlers/project.py

+6-11
Original file line numberDiff line numberDiff line change
@@ -44,20 +44,17 @@ def _get_project_data(project_dir):
4444
config.validate(validate_options=False)
4545
libdeps_dir = get_project_libdeps_dir()
4646

47-
if config.has_section("platformio") and \
48-
config.has_option("platformio", "lib_extra_dirs"):
49-
data['libExtraDirs'].extend(
50-
config.getlist("platformio", "lib_extra_dirs"))
47+
data['libExtraDirs'].extend(
48+
config.get("platformio", "lib_extra_dirs", []))
5149

5250
for section in config.sections():
5351
if not section.startswith("env:"):
5452
continue
5553
data['envLibdepsDirs'].append(join(libdeps_dir, section[4:]))
5654
if config.has_option(section, "board"):
5755
data['boards'].append(config.get(section, "board"))
58-
if config.has_option(section, "lib_extra_dirs"):
59-
data['libExtraDirs'].extend(
60-
config.getlist(section, "lib_extra_dirs"))
56+
data['libExtraDirs'].extend(
57+
config.get(section, "lib_extra_dirs", []))
6158

6259
# skip non existing folders and resolve full path
6360
for key in ("envLibdepsDirs", "libExtraDirs"):
@@ -233,10 +230,8 @@ def get_project_examples():
233230
try:
234231
config = ProjectConfig(join(project_dir, "platformio.ini"))
235232
config.validate(validate_options=False)
236-
if config.has_section("platformio") and \
237-
config.has_option("platformio", "description"):
238-
project_description = config.get(
239-
"platformio", "description")
233+
project_description = config.get("platformio",
234+
"description")
240235
except exception.PlatformIOProjectException:
241236
continue
242237

Diff for: platformio/commands/init.py

-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ def cli(
7070
project_option,
7171
env_prefix,
7272
silent):
73-
7473
if not silent:
7574
if project_dir == getcwd():
7675
click.secho(

Diff for: platformio/commands/lib.py

+3-5
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,8 @@ def cli(ctx, **options):
109109
continue
110110
storage_dir = join(libdeps_dir, env)
111111
ctx.meta[CTX_META_STORAGE_DIRS_KEY].append(storage_dir)
112-
if config.has_option("env:" + env, "lib_deps"):
113-
ctx.meta[CTX_META_STORAGE_LIBDEPS_KEY][
114-
storage_dir] = config.getlist("env:" + env, "lib_deps")
112+
ctx.meta[CTX_META_STORAGE_LIBDEPS_KEY][storage_dir] = config.get(
113+
"env:" + env, "lib_deps", [])
115114

116115

117116
@cli.command("install", short_help="Install library")
@@ -175,8 +174,7 @@ def lib_install( # pylint: disable=too-many-arguments
175174
if project_environments and env not in project_environments:
176175
continue
177176
config.expand_interpolations = False
178-
lib_deps = (config.getlist("env:" + env, "lib_deps")
179-
if config.has_option("env:" + env, "lib_deps") else [])
177+
lib_deps = config.get("env:" + env, "lib_deps", [])
180178
for library in libraries:
181179
if library in lib_deps:
182180
continue

Diff for: platformio/commands/test/command.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,8 @@ def cli( # pylint: disable=redefined-builtin
107107
# filter and ignore patterns
108108
patterns = dict(filter=list(filter), ignore=list(ignore))
109109
for key in patterns:
110-
if config.has_option(section, "test_%s" % key):
111-
patterns[key].extend(
112-
config.getlist(section, "test_%s" % key))
110+
patterns[key].extend(
111+
config.get(section, "test_%s" % key, []))
113112

114113
skip_conditions = [
115114
environment and envname not in environment,

Diff for: platformio/commands/test/processor.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,10 @@ def __init__(self, cmd_ctx, testname, envname, options):
9292
self._outputcpp_generated = False
9393

9494
def get_transport(self):
95-
transport = self.env_options.get("framework")
9695
if self.env_options.get("platform") == "native":
9796
transport = "native"
97+
elif "framework" in self.env_options:
98+
transport = self.env_options.get("framework")[0]
9899
if "test_transport" in self.env_options:
99100
transport = self.env_options['test_transport']
100101
if transport not in TRANSPORT_OPTIONS:

0 commit comments

Comments
 (0)