From 5a1b0e19b2b534d6faedb827bffc7ddb3f33479d Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Thu, 29 Oct 2020 22:59:48 +0200 Subject: [PATCH] Initialize a new project or update existing passing working environment name and its options // Resolve #3686 --- HISTORY.rst | 1 + docs | 2 +- platformio/commands/project.py | 28 +++++++++++++++++++++++++--- platformio/project/config.py | 6 ------ 4 files changed, 27 insertions(+), 10 deletions(-) diff --git a/HISTORY.rst b/HISTORY.rst index 47104ec3..7d498c78 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -11,6 +11,7 @@ PlatformIO Core 5 5.0.2 (2020-09-??) ~~~~~~~~~~~~~~~~~~ +- Initialize a new project or update existing passing working environment name and its options (`issue #3686 `_) - Automatically build PlatformIO Core extra Python dependencies on a host machine if they are missed in the registry (`issue #3700 `_) - Improved "core.call" RPC for PlatformIO Home (`issue #3671 `_) - Fixed a "PermissionError: [WinError 5]" on Windows when external repository is used with `lib_deps `__ option (`issue #3664 `_) diff --git a/docs b/docs index 500b8268..bc6c9b2e 160000 --- a/docs +++ b/docs @@ -1 +1 @@ -Subproject commit 500b826845400c7ceff4c787920087ba683239fe +Subproject commit bc6c9b2e4cc2dd06da7da942aa9d13494c6e3941 diff --git a/platformio/commands/project.py b/platformio/commands/project.py index f861b5b1..592f3a48 100644 --- a/platformio/commands/project.py +++ b/platformio/commands/project.py @@ -174,8 +174,10 @@ def project_init( if is_new_project: init_base_project(project_dir) - if board: - fill_project_envs( + if environment: + update_project_env(project_dir, environment, project_option) + elif board: + update_board_envs( ctx, project_dir, board, project_option, env_prefix, ide is not None ) @@ -358,7 +360,7 @@ def init_cvs_ignore(project_dir): fp.write(".pio\n") -def fill_project_envs( +def update_board_envs( ctx, project_dir, board_ids, project_option, env_prefix, force_download ): config = ProjectConfig( @@ -417,6 +419,26 @@ def _install_dependent_platforms(ctx, platforms): ) +def update_project_env(project_dir, environment, project_option): + if not project_option: + return + config = ProjectConfig( + os.path.join(project_dir, "platformio.ini"), parse_extra=False + ) + + section = "env:%s" % environment + if not config.has_section(section): + config.add_section(section) + + for item in project_option: + if "=" not in item: + continue + _name, _value = item.split("=", 1) + config.set(section, _name.strip(), _value.strip()) + + config.save() + + def get_best_envname(config, board_ids=None): envname = None default_envs = config.default_envs() diff --git a/platformio/project/config.py b/platformio/project/config.py index 2d841b39..786f080a 100644 --- a/platformio/project/config.py +++ b/platformio/project/config.py @@ -358,12 +358,6 @@ class ProjectConfigBase(object): click.secho("Warning! %s" % warning, fg="yellow") return True - def remove_option(self, section, option): - return self._parser.remove_option(section, option) - - def remove_section(self, section): - return self._parser.remove_section(section) - class ProjectConfigDirsMixin(object): def _get_core_dir(self, exists=False):