mirror of
https://github.com/platformio/platformio-core.git
synced 2025-07-30 18:17:13 +02:00
Implement "silent" mode for config.validate()
This commit is contained in:
@ -102,6 +102,7 @@ for key in list(clivars.keys()):
|
|||||||
if isinstance(env[key], bytes):
|
if isinstance(env[key], bytes):
|
||||||
env[key] = env[key].decode()
|
env[key] = env[key].decode()
|
||||||
|
|
||||||
|
env.GetProjectConfig().validate([env['PIOENV']], silent=True)
|
||||||
env.LoadProjectOptions()
|
env.LoadProjectOptions()
|
||||||
env.LoadPioPlatform()
|
env.LoadPioPlatform()
|
||||||
|
|
||||||
|
@ -41,7 +41,7 @@ class ProjectRPC(object):
|
|||||||
def _get_project_data(project_dir):
|
def _get_project_data(project_dir):
|
||||||
data = {"boards": [], "envLibdepsDirs": [], "libExtraDirs": []}
|
data = {"boards": [], "envLibdepsDirs": [], "libExtraDirs": []}
|
||||||
config = ProjectConfig(join(project_dir, "platformio.ini"))
|
config = ProjectConfig(join(project_dir, "platformio.ini"))
|
||||||
config.validate(validate_options=False)
|
config.validate(silent=True)
|
||||||
libdeps_dir = get_project_libdeps_dir()
|
libdeps_dir = get_project_libdeps_dir()
|
||||||
|
|
||||||
data['libExtraDirs'].extend(
|
data['libExtraDirs'].extend(
|
||||||
@ -229,7 +229,7 @@ class ProjectRPC(object):
|
|||||||
project_description = None
|
project_description = None
|
||||||
try:
|
try:
|
||||||
config = ProjectConfig(join(project_dir, "platformio.ini"))
|
config = ProjectConfig(join(project_dir, "platformio.ini"))
|
||||||
config.validate(validate_options=False)
|
config.validate(silent=True)
|
||||||
project_description = config.get("platformio",
|
project_description = config.get("platformio",
|
||||||
"description")
|
"description")
|
||||||
except exception.PlatformIOProjectException:
|
except exception.PlatformIOProjectException:
|
||||||
|
@ -229,7 +229,7 @@ class ProjectConfig(object):
|
|||||||
def default_envs(self):
|
def default_envs(self):
|
||||||
return self.get("platformio", "env_default", [])
|
return self.get("platformio", "env_default", [])
|
||||||
|
|
||||||
def validate(self, envs=None, validate_options=True):
|
def validate(self, envs=None, silent=False):
|
||||||
if not isfile(self.path):
|
if not isfile(self.path):
|
||||||
raise exception.NotPlatformIOProject(self.path)
|
raise exception.NotPlatformIOProject(self.path)
|
||||||
# check envs
|
# check envs
|
||||||
@ -241,9 +241,10 @@ class ProjectConfig(object):
|
|||||||
if unknown:
|
if unknown:
|
||||||
raise exception.UnknownEnvNames(", ".join(unknown),
|
raise exception.UnknownEnvNames(", ".join(unknown),
|
||||||
", ".join(known))
|
", ".join(known))
|
||||||
return self.validate_options() if validate_options else True
|
return self.validate_options(silent)
|
||||||
|
|
||||||
def validate_options(self):
|
def validate_options(self, silent=False):
|
||||||
|
warnings = []
|
||||||
# legacy `lib_extra_dirs` in [platformio]
|
# legacy `lib_extra_dirs` in [platformio]
|
||||||
if (self._parser.has_section("platformio")
|
if (self._parser.has_section("platformio")
|
||||||
and self._parser.has_option("platformio", "lib_extra_dirs")):
|
and self._parser.has_option("platformio", "lib_extra_dirs")):
|
||||||
@ -252,15 +253,20 @@ class ProjectConfig(object):
|
|||||||
self._parser.set("env", "lib_extra_dirs",
|
self._parser.set("env", "lib_extra_dirs",
|
||||||
self._parser.get("platformio", "lib_extra_dirs"))
|
self._parser.get("platformio", "lib_extra_dirs"))
|
||||||
self._parser.remove_option("platformio", "lib_extra_dirs")
|
self._parser.remove_option("platformio", "lib_extra_dirs")
|
||||||
click.secho(
|
warnings.append(
|
||||||
"Warning! `lib_extra_dirs` option is deprecated in section "
|
"`lib_extra_dirs` configuration option is deprecated in "
|
||||||
"[platformio]! Please move it to global `env` section",
|
"section [platformio]! Please move it to global `env` section")
|
||||||
fg="yellow")
|
|
||||||
|
|
||||||
return self._validate_unknown_options()
|
warnings.extend(self._validate_unknown_options())
|
||||||
|
|
||||||
|
if not silent:
|
||||||
|
for warning in warnings:
|
||||||
|
click.secho("Warning! %s" % warning, fg="yellow")
|
||||||
|
|
||||||
|
return warnings
|
||||||
|
|
||||||
def _validate_unknown_options(self):
|
def _validate_unknown_options(self):
|
||||||
warnings = set()
|
warnings = []
|
||||||
renamed_options = {}
|
renamed_options = {}
|
||||||
for option in ProjectOptions.values():
|
for option in ProjectOptions.values():
|
||||||
if option.oldnames:
|
if option.oldnames:
|
||||||
@ -272,10 +278,11 @@ class ProjectConfig(object):
|
|||||||
for option in self._parser.options(section):
|
for option in self._parser.options(section):
|
||||||
# obsolete
|
# obsolete
|
||||||
if option in renamed_options:
|
if option in renamed_options:
|
||||||
warnings.add(
|
warnings.append(
|
||||||
"`%s` option in section `[%s]` is deprecated and will "
|
"`%s` configuration option in section [%s] is "
|
||||||
"be removed in the next release! Please use `%s` "
|
"deprecated and will be removed in the next release! "
|
||||||
"instead" % (option, section, renamed_options[option]))
|
"Please use `%s` instead" % (option, section,
|
||||||
|
renamed_options[option]))
|
||||||
# rename on-the-fly
|
# rename on-the-fly
|
||||||
self._parser.set(section, renamed_options[option],
|
self._parser.set(section, renamed_options[option],
|
||||||
self._parser.get(section, option))
|
self._parser.get(section, option))
|
||||||
@ -290,13 +297,9 @@ class ProjectConfig(object):
|
|||||||
not option.startswith(("custom_", "board_"))
|
not option.startswith(("custom_", "board_"))
|
||||||
] # yapf: disable
|
] # yapf: disable
|
||||||
if all(unknown_conditions):
|
if all(unknown_conditions):
|
||||||
warnings.add("Ignore unknown option `%s` in section `[%s]`"
|
warnings.append("Ignore unknown configuration option `%s` "
|
||||||
% (option, section))
|
"in section [%s]" % (option, section))
|
||||||
|
return warnings
|
||||||
for warning in warnings:
|
|
||||||
click.secho("Warning! %s" % warning, fg="yellow")
|
|
||||||
|
|
||||||
return True
|
|
||||||
|
|
||||||
def to_json(self):
|
def to_json(self):
|
||||||
result = {}
|
result = {}
|
||||||
|
Reference in New Issue
Block a user