Check for default core dir in run-time (solves issue with tests)

This commit is contained in:
Ivan Kravets
2021-12-02 15:06:58 +02:00
parent 90972e9ce0
commit 04e9f38e0e
3 changed files with 13 additions and 5 deletions

View File

@ -276,6 +276,8 @@ class ProjectConfigBase(object):
if value == MISSING: if value == MISSING:
value = default if default != MISSING else option_meta.default value = default if default != MISSING else option_meta.default
if callable(value):
value = value()
if value == MISSING: if value == MISSING:
return None return None

View File

@ -60,7 +60,7 @@ class ConfigOption(object): # pylint: disable=too-many-instance-attributes
type="string", type="string",
multiple=self.multiple, multiple=self.multiple,
sysenvvar=self.sysenvvar, sysenvvar=self.sysenvvar,
default=self.default, default=self.default() if callable(self.default) else self.default,
) )
if isinstance(self.type, click.ParamType): if isinstance(self.type, click.ParamType):
result["type"] = self.type.name result["type"] = self.type.name
@ -168,7 +168,7 @@ ProjectOptions = OrderedDict(
), ),
oldnames=["home_dir"], oldnames=["home_dir"],
sysenvvar="PLATFORMIO_CORE_DIR", sysenvvar="PLATFORMIO_CORE_DIR",
default=get_default_core_dir(), default=get_default_core_dir,
validate=validate_dir, validate=validate_dir,
), ),
ConfigPlatformioOption( ConfigPlatformioOption(

View File

@ -254,9 +254,15 @@ def test_sysenv_options(config):
os.environ["PLATFORMIO_HOME_DIR"] = custom_core_dir os.environ["PLATFORMIO_HOME_DIR"] = custom_core_dir
os.environ["PLATFORMIO_SRC_DIR"] = custom_src_dir os.environ["PLATFORMIO_SRC_DIR"] = custom_src_dir
os.environ["PLATFORMIO_BUILD_DIR"] = custom_build_dir os.environ["PLATFORMIO_BUILD_DIR"] = custom_build_dir
assert config.get("platformio", "core_dir") == os.path.realpath(custom_core_dir) assert os.path.realpath(config.get("platformio", "core_dir")) == os.path.realpath(
assert config.get("platformio", "src_dir") == os.path.realpath(custom_src_dir) custom_core_dir
assert config.get("platformio", "build_dir") == os.path.realpath(custom_build_dir) )
assert os.path.realpath(config.get("platformio", "src_dir")) == os.path.realpath(
custom_src_dir
)
assert os.path.realpath(config.get("platformio", "build_dir")) == os.path.realpath(
custom_build_dir
)
# cleanup system environment variables # cleanup system environment variables
del os.environ["PLATFORMIO_BUILD_FLAGS"] del os.environ["PLATFORMIO_BUILD_FLAGS"]