From 05bbd4a7f8b10b3f6d74fd0c86a7af16a3dd851b Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Tue, 13 Sep 2016 19:22:19 +0300 Subject: [PATCH] Improve Project Generator when custom ``--project-option`` is passed to `platformio init` command --- HISTORY.rst | 3 +++ docs/userguide/cmd_ci.rst | 6 ++--- docs/userguide/cmd_init.rst | 45 +++++++++++++++++-------------------- platformio/commands/init.py | 23 ++++++++++++------- tests/commands/test_init.py | 17 ++++++++++++++ 5 files changed, 59 insertions(+), 35 deletions(-) diff --git a/HISTORY.rst b/HISTORY.rst index 5c95a239..315e5f7b 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -7,6 +7,9 @@ PlatformIO 3.0 3.0.2 (2016-09-??) ~~~~~~~~~~~~~~~~~~ +* Improved Project Generator when custom ``--project-option`` is passed to + `platformio init `_ + command * Disable SSL Server-Name-Indication for Python < 2.7.9 * Return valid exit code from ``plaformio test`` command diff --git a/docs/userguide/cmd_ci.rst b/docs/userguide/cmd_ci.rst index 87c3735b..c218373d 100644 --- a/docs/userguide/cmd_ci.rst +++ b/docs/userguide/cmd_ci.rst @@ -118,9 +118,9 @@ Buid project using pre-configured :ref:`projectconf`. .. option:: -O, --project-option -Pass additional options from :ref:`projectconf` to -:option:`platformio init --project-option` command. For example, -automatically install dependent libraries +Pass additional options from :ref:`projectconf` to :ref:`cmd_init` command. +Use multiple ``--project-option`` options to pass multiple options to +:ref:`cmd_init` command. For example, automatically install dependent libraries ``platformio ci --project-option="lib_deps=ArduinoJSON"`` or ignore specific library ``platformio ci --project-option="lib_ignore=SomeLib"``. diff --git a/docs/userguide/cmd_init.rst b/docs/userguide/cmd_init.rst index c3c4ab87..b365b779 100644 --- a/docs/userguide/cmd_init.rst +++ b/docs/userguide/cmd_init.rst @@ -89,11 +89,11 @@ be ``[env:teensy_31]``. Examples -------- -1. Create new project in the current working directory +1. Initialize new project in a current working directory -.. code-block:: bash +.. code:: - $ platformio init + > platformio init The current working directory *** will be used for the new project. You can specify another project directory via @@ -110,38 +110,35 @@ Examples `platformio run --target clean` - clean project (remove compiled files) -2. Create new project in the specified directory +2. Initialize new project in a specified directory -.. code-block:: bash +.. code:: - $ platformio init -d %PATH_TO_DIR% + > platformio init -d %PATH_TO_DIR% The next files/directories will be created in *** platformio.ini - Project Configuration File. |-> PLEASE EDIT ME <-| - src - Put your source files here - lib - Put here project specific (private) libraries - Project has been successfully initialized! - Useful commands: - `platformio run` - process/build project from the current directory - `platformio run --target upload` or `platformio run -t upload` - upload firmware to embedded board - `platformio run --target clean` - clean project (remove compiled files) + ... 3. Initialize project for Arduino Uno -.. code-block:: bash +.. code:: - $ platformio init --board uno + > platformio init --board uno + + The current working directory *** will be used for the new project. + You can specify another project directory via + `platformio init -d %PATH_TO_THE_PROJECT_DIR%` command. + ... + +4. Initialize project for Teensy 3.1 board with custom :ref:`framework_mbed` + +.. code:: + + > platformio init --board teensy31 --project-option "framework=mbed" The current working directory *** will be used for the new project. You can specify another project directory via `platformio init -d %PATH_TO_THE_PROJECT_DIR%` command. - The next files/directories will be created in *** - platformio.ini - Project Configuration File. |-> PLEASE EDIT ME <-| - src - Put your source files here - lib - Put here project specific (private) libraries - Project has been successfully initialized! - Useful commands: - `platformio run` - process/build project from the current directory - `platformio run --target upload` or `platformio run -t upload` - upload firmware to embedded board - `platformio run --target clean` - clean project (remove compiled files) + ... \ No newline at end of file diff --git a/platformio/commands/init.py b/platformio/commands/init.py index d7eee985..6318678e 100644 --- a/platformio/commands/init.py +++ b/platformio/commands/init.py @@ -317,18 +317,25 @@ def fill_project_envs( # pylint: disable=too-many-arguments,too-many-locals continue used_boards.append(id_) - content.append("") - content.append("[env:%s%s]" % (env_prefix, id_)) - content.append("platform = %s" % manifest['platform']) - + envopts = { + "platform": manifest['platform'], + "board": id_ + } # find default framework for board frameworks = manifest.get("frameworks") if frameworks: - content.append("framework = %s" % frameworks[0]) + envopts['framework'] = frameworks[0] - content.append("board = %s" % id_) - if project_option: - content.extend(project_option) + for item in project_option: + if "=" not in item: + continue + _name, _value = item.split("=", 1) + envopts[_name.strip()] = _value.strip() + + content.append("") + content.append("[env:%s%s]" % (env_prefix, id_)) + for name, value in envopts.items(): + content.append("%s = %s" % (name, value)) if force_download and used_platforms: _install_dependent_platforms(ctx, used_platforms) diff --git a/tests/commands/test_init.py b/tests/commands/test_init.py index 5f08c336..3f0cb3d7 100644 --- a/tests/commands/test_init.py +++ b/tests/commands/test_init.py @@ -132,6 +132,23 @@ def test_init_enable_auto_uploading(clirunner, validate_cliresult): set(config.items("env:uno")))) == 0 +def test_init_custom_framework(clirunner, validate_cliresult): + with clirunner.isolated_filesystem(): + result = clirunner.invoke( + cmd_init, ["-b", "teensy31", "--project-option", "framework=mbed"]) + validate_cliresult(result) + validate_pioproject(getcwd()) + config = util.load_project_config() + expected_result = [ + ("platform", "teensy"), ("framework", "mbed"), + ("board", "teensy31") + ] + assert config.has_section("env:teensy31") + assert len( + set(expected_result).symmetric_difference( + set(config.items("env:teensy31")))) == 0 + + def test_init_incorrect_board(clirunner): result = clirunner.invoke(cmd_init, ["-b", "missed_board"]) assert result.exit_code == 2