From 8d751948844a466173080a9d6fc27fd2a87d1b3b Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Thu, 16 Apr 2015 17:04:45 +0100 Subject: [PATCH 01/49] Add global -f, --force option which will force to accept any confirmation prompts // Resolve #152 --- platformio/__init__.py | 2 +- platformio/__main__.py | 10 ++++++---- platformio/app.py | 23 ++++++++++++++++++++--- platformio/maintenance.py | 3 ++- 4 files changed, 29 insertions(+), 9 deletions(-) diff --git a/platformio/__init__.py b/platformio/__init__.py index 2aa935d0..1f49e63a 100644 --- a/platformio/__init__.py +++ b/platformio/__init__.py @@ -1,7 +1,7 @@ # Copyright (C) Ivan Kravets # See LICENSE for details. -VERSION = (1, 4, 0) +VERSION = (2, 0, "0.dev0") __version__ = ".".join([str(s) for s in VERSION]) __title__ = "platformio" diff --git a/platformio/__main__.py b/platformio/__main__.py index fbd34974..a3de3544 100644 --- a/platformio/__main__.py +++ b/platformio/__main__.py @@ -37,14 +37,16 @@ class PlatformioCLI(click.MultiCommand): # pylint: disable=R0904 @click.command(cls=PlatformioCLI) @click.version_option(__version__, prog_name="PlatformIO") +@click.option("--force", "-f", is_flag=True, + help="Force to accept any confirmation prompts") @click.pass_context -def cli(ctx): - maintenance.on_platformio_start(ctx) +def cli(ctx, force): + maintenance.on_platformio_start(ctx, force) @cli.resultcallback() @click.pass_context -def process_result(ctx, result): +def process_result(ctx, result, force): # pylint: disable=W0613 maintenance.on_platformio_end(ctx, result) @@ -54,7 +56,7 @@ def main(): # /en/latest/security.html#insecureplatformwarning requests.packages.urllib3.disable_warnings() - cli(None) + cli(None, None) except Exception as e: # pylint: disable=W0703 if not isinstance(e, exception.ReturnErrorCode): maintenance.on_platformio_exception(e) diff --git a/platformio/app.py b/platformio/app.py index fe299d6a..2060d552 100644 --- a/platformio/app.py +++ b/platformio/app.py @@ -47,6 +47,11 @@ DEFAULT_SETTINGS = { } +SESSION_VARS = { + "force_option": False +} + + class State(object): def __init__(self, path=None): @@ -101,9 +106,12 @@ def set_state_item(name, value): def get_setting(name): - # disable prompts for Continuous Integration systems - if name == "enable_prompts" and getenv("CI", "").lower() == "true": - return False + if name == "enable_prompts": + # disable prompts for Continuous Integration systems + # and when global "--force" option is set + if any([getenv("CI", "").lower() == "true", + get_session_var("force_option")]): + return False _env_name = "PLATFORMIO_SETTING_%s" % name.upper() if _env_name in environ: @@ -127,3 +135,12 @@ def reset_settings(): with State() as data: if "settings" in data: del data['settings'] + + +def get_session_var(name, default=None): + return SESSION_VARS.get(name, default) + + +def set_session_var(name, value): + assert name in SESSION_VARS + SESSION_VARS[name] = value diff --git a/platformio/maintenance.py b/platformio/maintenance.py index 87d673d4..4a00efe9 100644 --- a/platformio/maintenance.py +++ b/platformio/maintenance.py @@ -20,7 +20,8 @@ from platformio.platforms.base import PlatformFactory from platformio.util import get_home_dir, get_lib_dir -def on_platformio_start(ctx): +def on_platformio_start(ctx, force): + app.set_session_var("force_option", force) telemetry.on_command(ctx) after_upgrade(ctx) From a9942e675f1ea6d7e9ba6a302f1cdbb41965c68b Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Thu, 16 Apr 2015 17:34:22 +0100 Subject: [PATCH 02/49] Allow to choose which library to update // Resolve #168 --- HISTORY.rst | 9 +++++++++ docs/userguide/lib/cmd_update.rst | 21 +++++++++++++++++++-- platformio/commands/lib.py | 9 +++++++-- 3 files changed, 35 insertions(+), 4 deletions(-) diff --git a/HISTORY.rst b/HISTORY.rst index 9bbcf11f..41d4c90c 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -1,6 +1,15 @@ Release History =============== +2.0.0 (2015-??-??) +------------------ + +* Added global ``-f, --force`` option which will force to accept any + confirmation prompts (`issue #152 `_) +* Allowed to choose which library to update + (`issue #168 `_) + + 1.4.0 (2015-04-11) ------------------ diff --git a/docs/userguide/lib/cmd_update.rst b/docs/userguide/lib/cmd_update.rst index f719fa13..f58fab4c 100644 --- a/docs/userguide/lib/cmd_update.rst +++ b/docs/userguide/lib/cmd_update.rst @@ -10,7 +10,7 @@ Usage .. code-block:: bash - platformio lib update + platformio lib update [LIBRARY_ID] Description @@ -22,6 +22,8 @@ Check or update installed libraries Examples -------- +1. Update all installed libraries + .. code-block:: bash $ platformio lib update @@ -36,8 +38,23 @@ Examples # Updating [ 13 ] Adafruit-GFX library: # Versions: Current=a9e5bc4707, Latest=a9e5bc4707 [Up-to-date] # Updating [ 1 ] OneWire library: - # Versions: Current=2.2, Latest=2.2 [Up-to-date] + # Versions: Current=2.2, Latest=2.2 [Up-to-date] # Updating [ 4 ] IRremote library: # Versions: Current=f2dafe5030, Latest=f2dafe5030 [Up-to-date] # Updating [ 14 ] Adafruit-9DOF-Unified library: # Versions: Current=b2f07242ac, Latest=b2f07242ac [Up-to-date] + +2. Update specified libraries + +.. code-block:: bash + + $ platformio lib update 1 59 + # Updating [ 1 ] OneWire library: + # Versions: Current=2.2, Latest=2.2 [Up-to-date] + # Updating [ 59 ] USB-Host-Shield-20 library: + # Versions: Current=fcab83dcb3, Latest=c61f9ce1c2 [Out-of-date] + # The library #59 'USB-Host-Shield-20' has been successfully uninstalled! + # Installing library [ 59 ]: + # Downloading [####################################] 100% + # Unpacking [####################################] 100% + # The library #59 'USB-Host-Shield-20' has been successfully installed! diff --git a/platformio/commands/lib.py b/platformio/commands/lib.py index 91c8dced..da3d2b19 100644 --- a/platformio/commands/lib.py +++ b/platformio/commands/lib.py @@ -209,13 +209,18 @@ def lib_show(libid): @cli.command("update", short_help="Update installed libraries") +@click.argument("libid", type=click.INT, nargs=-1, required=False, + metavar="[LIBRARY_ID]") @click.pass_context -def lib_update(ctx): +def lib_update(ctx, libid): lm = LibraryManager(get_lib_dir()) for id_, latest_version in (lm.get_latest_versions() or {}).items(): + if libid and int(id_) not in libid: + continue + info = lm.get_info(int(id_)) - click.echo("Updating [ %s ] %s library:" % ( + click.echo("Updating [ %s ] %s library:" % ( click.style(id_, fg="yellow"), click.style(info['name'], fg="cyan"))) From b52ff11d3c3b5a057988c20cc3633d2a3287095c Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Fri, 17 Apr 2015 12:28:10 +0100 Subject: [PATCH 03/49] Disabled automatic updates by default for platforms, packages and libraries // Resolve #171 --- HISTORY.rst | 2 ++ platformio/app.py | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/HISTORY.rst b/HISTORY.rst index 41d4c90c..cbcf528d 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -8,6 +8,8 @@ Release History confirmation prompts (`issue #152 `_) * Allowed to choose which library to update (`issue #168 `_) +* Disabled automatic updates by default for platforms, packages and libraries + (`issue #171 `_) 1.4.0 (2015-04-11) diff --git a/platformio/app.py b/platformio/app.py index 2060d552..c7776827 100644 --- a/platformio/app.py +++ b/platformio/app.py @@ -24,11 +24,11 @@ DEFAULT_SETTINGS = { }, "auto_update_platforms": { "description": "Automatically update platforms (Yes/No)", - "value": True + "value": False }, "auto_update_libraries": { "description": "Automatically update libraries (Yes/No)", - "value": True + "value": False }, "enable_telemetry": { "description": ("Shares commands, platforms and libraries usage" From 07022bb3be88055a1a00488aae73564563ad5723 Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Fri, 17 Apr 2015 12:37:03 +0100 Subject: [PATCH 04/49] Implement PlatformIO CLI 2.0 // Resolve #158 --- HISTORY.rst | 3 + platformio/__init__.py | 2 +- platformio/commands/install.py | 20 ---- platformio/commands/list.py | 34 ------- platformio/commands/platforms.py | 154 +++++++++++++++++++++++++++++++ platformio/commands/run.py | 5 +- platformio/commands/search.py | 46 --------- platformio/commands/show.py | 46 --------- platformio/commands/uninstall.py | 17 ---- platformio/commands/update.py | 22 ++--- platformio/maintenance.py | 19 ++-- tests/commands/test_boards.py | 16 ++-- 12 files changed, 190 insertions(+), 194 deletions(-) delete mode 100644 platformio/commands/install.py delete mode 100644 platformio/commands/list.py create mode 100644 platformio/commands/platforms.py delete mode 100644 platformio/commands/search.py delete mode 100644 platformio/commands/show.py delete mode 100644 platformio/commands/uninstall.py diff --git a/HISTORY.rst b/HISTORY.rst index cbcf528d..f2fc641a 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -4,6 +4,9 @@ Release History 2.0.0 (2015-??-??) ------------------ +* Implemented PlatformIO CLI 2.0: "platform" related commands have been + moved to ``platformio platforms`` subcommand + (`issue #158 `_) * Added global ``-f, --force`` option which will force to accept any confirmation prompts (`issue #152 `_) * Allowed to choose which library to update diff --git a/platformio/__init__.py b/platformio/__init__.py index 1f49e63a..c6851e7e 100644 --- a/platformio/__init__.py +++ b/platformio/__init__.py @@ -1,7 +1,7 @@ # Copyright (C) Ivan Kravets # See LICENSE for details. -VERSION = (2, 0, "0.dev0") +VERSION = (2, 0, "0.dev1") __version__ = ".".join([str(s) for s in VERSION]) __title__ = "platformio" diff --git a/platformio/commands/install.py b/platformio/commands/install.py deleted file mode 100644 index af476f43..00000000 --- a/platformio/commands/install.py +++ /dev/null @@ -1,20 +0,0 @@ -# Copyright (C) Ivan Kravets -# See LICENSE for details. - -import click - -from platformio.platforms.base import PlatformFactory - - -@click.command("install", short_help="Install new platforms") -@click.argument("platforms", nargs=-1) -@click.option("--with-package", multiple=True, metavar="") -@click.option("--without-package", multiple=True, metavar="") -@click.option("--skip-default-package", is_flag=True) -def cli(platforms, with_package, without_package, skip_default_package): - - for platform in platforms: - p = PlatformFactory.newPlatform(platform) - if p.install(with_package, without_package, skip_default_package): - click.secho("The platform '%s' has been successfully installed!" % - platform, fg="green") diff --git a/platformio/commands/list.py b/platformio/commands/list.py deleted file mode 100644 index c47a95b8..00000000 --- a/platformio/commands/list.py +++ /dev/null @@ -1,34 +0,0 @@ -# Copyright (C) Ivan Kravets -# See LICENSE for details. - -import json - -import click - -from platformio.platforms.base import PlatformFactory - - -@click.command("list", short_help="List installed platforms") -@click.option("--json-output", is_flag=True) -def cli(json_output): - - installed_platforms = PlatformFactory.get_platforms( - installed=True).keys() - installed_platforms.sort() - - data = [] - for platform in installed_platforms: - p = PlatformFactory.newPlatform(platform) - data.append({ - "name": platform, - "packages": p.get_installed_packages() - }) - - if json_output: - click.echo(json.dumps(data)) - else: - for item in data: - click.echo("{name:<20} with packages: {pkgs}".format( - name=click.style(item['name'], fg="cyan"), - pkgs=", ".join(item['packages']) - )) diff --git a/platformio/commands/platforms.py b/platformio/commands/platforms.py new file mode 100644 index 00000000..b3781074 --- /dev/null +++ b/platformio/commands/platforms.py @@ -0,0 +1,154 @@ +# Copyright (C) Ivan Kravets +# See LICENSE for details. + +import json +from datetime import datetime + +import click + +from platformio import app +from platformio.exception import PlatformNotInstalledYet +from platformio.pkgmanager import PackageManager +from platformio.platforms.base import PlatformFactory + + +@click.group(short_help="Platforms and Packages Manager") +def cli(): + pass + + +@cli.command("install", short_help="Install new platforms") +@click.argument("platforms", nargs=-1) +@click.option("--with-package", multiple=True, metavar="") +@click.option("--without-package", multiple=True, metavar="") +@click.option("--skip-default-package", is_flag=True) +def platforms_install(platforms, with_package, without_package, + skip_default_package): + for platform in platforms: + p = PlatformFactory.newPlatform(platform) + if p.install(with_package, without_package, skip_default_package): + click.secho("The platform '%s' has been successfully installed!" % + platform, fg="green") + + +@cli.command("list", short_help="List installed platforms") +@click.option("--json-output", is_flag=True) +def platforms_list(json_output): + + installed_platforms = PlatformFactory.get_platforms( + installed=True).keys() + installed_platforms.sort() + + data = [] + for platform in installed_platforms: + p = PlatformFactory.newPlatform(platform) + data.append({ + "name": platform, + "packages": p.get_installed_packages() + }) + + if json_output: + click.echo(json.dumps(data)) + else: + for item in data: + click.echo("{name:<20} with packages: {pkgs}".format( + name=click.style(item['name'], fg="cyan"), + pkgs=", ".join(item['packages']) + )) + + +@cli.command("search", short_help="Search for development platforms") +@click.argument("query", required=False) +@click.option("--json-output", is_flag=True) +def platforms_search(query, json_output): + + data = [] + platforms = PlatformFactory.get_platforms().keys() + platforms.sort() + for platform in platforms: + p = PlatformFactory.newPlatform(platform) + type_ = p.get_type() + description = p.get_description() + + if query == "all": + query = "" + + search_data = "%s %s %s" % (type_, description, p.get_packages()) + if query and query.lower() not in search_data.lower(): + continue + + data.append({ + "type": type_, + "description": description, + "packages": p.get_packages() + }) + + if json_output: + click.echo(json.dumps(data)) + else: + for item in data: + click.secho(item['type'], fg="cyan", nl=False) + click.echo(" (available packages: %s)" % ", ".join( + p.get_packages().keys())) + click.secho("-" * len(item['type']), fg="cyan") + click.echo(item['description']) + click.echo() + + +@cli.command("show", short_help="Show details about installed platform") +@click.argument("platform") +@click.pass_context +def platforms_show(ctx, platform): + + installed_platforms = PlatformFactory.get_platforms( + installed=True).keys() + + if platform not in installed_platforms: + if (not app.get_setting("enable_prompts") or + click.confirm("The platform '%s' has not been installed yet. " + "Would you like to install it now?" % platform)): + ctx.invoke(platforms_install, platforms=[platform]) + else: + raise PlatformNotInstalledYet(platform) + + p = PlatformFactory.newPlatform(platform) + click.echo("{name:<20} - {description} [ {url} ]".format( + name=click.style(p.get_type(), fg="cyan"), + description=p.get_description(), url=p.get_vendor_url())) + + installed_packages = PackageManager.get_installed() + for name in p.get_installed_packages(): + data = installed_packages[name] + pkgalias = p.get_pkg_alias(name) + click.echo("----------") + click.echo("Package: %s" % click.style(name, fg="yellow")) + if pkgalias: + click.echo("Alias: %s" % pkgalias) + click.echo("Version: %d" % int(data['version'])) + click.echo("Installed: %s" % datetime.fromtimestamp( + data['time']).strftime("%Y-%m-%d %H:%M:%S")) + + +@cli.command("uninstall", short_help="Uninstall platforms") +@click.argument("platforms", nargs=-1) +def platforms_uninstall(platforms): + + for platform in platforms: + p = PlatformFactory.newPlatform(platform) + if p.uninstall(): + click.secho("The platform '%s' has been successfully " + "uninstalled!" % platform, fg="green") + + +@cli.command("update", short_help="Update installed Platforms and Packages") +def platforms_update(): + + installed_platforms = PlatformFactory.get_platforms( + installed=True).keys() + installed_platforms.sort() + + for platform in installed_platforms: + click.echo("\nPlatform %s" % click.style(platform, fg="cyan")) + click.echo("--------") + p = PlatformFactory.newPlatform(platform) + p.update() diff --git a/platformio/commands/run.py b/platformio/commands/run.py index d4c5bd8a..8d3d792f 100644 --- a/platformio/commands/run.py +++ b/platformio/commands/run.py @@ -9,7 +9,8 @@ from time import time import click from platformio import app, exception, telemetry, util -from platformio.commands.install import cli as cmd_install +from platformio.commands.platforms import \ + platforms_install as cmd_platforms_install from platformio.platforms.base import PlatformFactory @@ -120,7 +121,7 @@ def _run_environment(ctx, name, options, targets, upload_port): not app.get_setting("enable_prompts") or click.confirm("The platform '%s' has not been installed yet. " "Would you like to install it now?" % platform))): - ctx.invoke(cmd_install, platforms=[platform]) + ctx.invoke(cmd_platforms_install, platforms=[platform]) p = PlatformFactory.newPlatform(platform) return p.run(variables, envtargets) diff --git a/platformio/commands/search.py b/platformio/commands/search.py deleted file mode 100644 index d3b7d69a..00000000 --- a/platformio/commands/search.py +++ /dev/null @@ -1,46 +0,0 @@ -# Copyright (C) Ivan Kravets -# See LICENSE for details. - -import json - -import click - -from platformio.platforms.base import PlatformFactory - - -@click.command("search", short_help="Search for development platforms") -@click.argument("query", required=False) -@click.option("--json-output", is_flag=True) -def cli(query, json_output): - - data = [] - platforms = PlatformFactory.get_platforms().keys() - platforms.sort() - for platform in platforms: - p = PlatformFactory.newPlatform(platform) - type_ = p.get_type() - description = p.get_description() - - if query == "all": - query = "" - - search_data = "%s %s %s" % (type_, description, p.get_packages()) - if query and query.lower() not in search_data.lower(): - continue - - data.append({ - "type": type_, - "description": description, - "packages": p.get_packages() - }) - - if json_output: - click.echo(json.dumps(data)) - else: - for item in data: - click.secho(item['type'], fg="cyan", nl=False) - click.echo(" (available packages: %s)" % ", ".join( - p.get_packages().keys())) - click.secho("-" * len(item['type']), fg="cyan") - click.echo(item['description']) - click.echo() diff --git a/platformio/commands/show.py b/platformio/commands/show.py deleted file mode 100644 index f0913ff9..00000000 --- a/platformio/commands/show.py +++ /dev/null @@ -1,46 +0,0 @@ -# Copyright (C) Ivan Kravets -# See LICENSE for details. - -from datetime import datetime - -import click - -from platformio import app -from platformio.commands.install import cli as cmd_install -from platformio.exception import PlatformNotInstalledYet -from platformio.pkgmanager import PackageManager -from platformio.platforms.base import PlatformFactory - - -@click.command("show", short_help="Show details about installed platform") -@click.argument("platform") -@click.pass_context -def cli(ctx, platform): - - installed_platforms = PlatformFactory.get_platforms( - installed=True).keys() - - if platform not in installed_platforms: - if (not app.get_setting("enable_prompts") or - click.confirm("The platform '%s' has not been installed yet. " - "Would you like to install it now?" % platform)): - ctx.invoke(cmd_install, platforms=[platform]) - else: - raise PlatformNotInstalledYet(platform) - - p = PlatformFactory.newPlatform(platform) - click.echo("{name:<20} - {description} [ {url} ]".format( - name=click.style(p.get_type(), fg="cyan"), - description=p.get_description(), url=p.get_vendor_url())) - - installed_packages = PackageManager.get_installed() - for name in p.get_installed_packages(): - data = installed_packages[name] - pkgalias = p.get_pkg_alias(name) - click.echo("----------") - click.echo("Package: %s" % click.style(name, fg="yellow")) - if pkgalias: - click.echo("Alias: %s" % pkgalias) - click.echo("Version: %d" % int(data['version'])) - click.echo("Installed: %s" % datetime.fromtimestamp( - data['time']).strftime("%Y-%m-%d %H:%M:%S")) diff --git a/platformio/commands/uninstall.py b/platformio/commands/uninstall.py deleted file mode 100644 index a14569e2..00000000 --- a/platformio/commands/uninstall.py +++ /dev/null @@ -1,17 +0,0 @@ -# Copyright (C) Ivan Kravets -# See LICENSE for details. - -import click - -from platformio.platforms.base import PlatformFactory - - -@click.command("uninstall", short_help="Uninstall platforms") -@click.argument("platforms", nargs=-1) -def cli(platforms): - - for platform in platforms: - p = PlatformFactory.newPlatform(platform) - if p.uninstall(): - click.secho("The platform '%s' has been successfully " - "uninstalled!" % platform, fg="green") diff --git a/platformio/commands/update.py b/platformio/commands/update.py index 9091e31e..8afdc5ed 100644 --- a/platformio/commands/update.py +++ b/platformio/commands/update.py @@ -3,18 +3,14 @@ import click -from platformio.platforms.base import PlatformFactory +from platformio.commands.lib import lib_update as cmd_lib_update +from platformio.commands.platforms import \ + platforms_update as cmd_platforms_update -@click.command("update", short_help="Update installed platforms") -def cli(): - - installed_platforms = PlatformFactory.get_platforms( - installed=True).keys() - installed_platforms.sort() - - for platform in installed_platforms: - click.echo("\nPlatform %s" % click.style(platform, fg="cyan")) - click.echo("--------") - p = PlatformFactory.newPlatform(platform) - p.update() +@click.command("update", + short_help="Update installed Platforms, Packages and Libraries") +@click.pass_context +def cli(ctx): + ctx.invoke(cmd_platforms_update) + ctx.invoke(cmd_lib_update) diff --git a/platformio/maintenance.py b/platformio/maintenance.py index 4a00efe9..36a91f4e 100644 --- a/platformio/maintenance.py +++ b/platformio/maintenance.py @@ -11,9 +11,11 @@ from time import time import click from platformio import __version__, app, exception, telemetry -from platformio.commands.install import cli as cmd_install from platformio.commands.lib import lib_update as cmd_libraries_update -from platformio.commands.update import cli as cli_update +from platformio.commands.platforms import \ + platforms_install as cmd_platforms_install +from platformio.commands.platforms import \ + platforms_update as cmd_platforms_update from platformio.commands.upgrade import get_latest_version from platformio.libmanager import LibraryManager from platformio.platforms.base import PlatformFactory @@ -90,7 +92,7 @@ class Upgrader(object): remove(join(get_home_dir(), fname)) if prev_platforms: - ctx.invoke(cmd_install, platforms=prev_platforms) + ctx.invoke(cmd_platforms_install, platforms=prev_platforms) return True @@ -98,8 +100,7 @@ class Upgrader(object): installed_platforms = PlatformFactory.get_platforms( installed=True).keys() if installed_platforms: - ctx.invoke(cmd_install, platforms=installed_platforms) - ctx.invoke(cli_update) + ctx.invoke(cmd_platforms_install, platforms=installed_platforms) return True @@ -134,6 +135,8 @@ def after_upgrade(ctx): u = Upgrader(last_version, __version__) if u.run(ctx): app.set_state_item("last_version", __version__) + ctx.invoke(cmd_platforms_update) + click.secho("PlatformIO has been successfully upgraded to %s!\n" % __version__, fg="green") @@ -195,14 +198,14 @@ def check_internal_updates(ctx, what): if not app.get_setting("auto_update_" + what): click.secho("Please update them via ", fg="yellow", nl=False) - click.secho("`platformio %supdate`" % - ("lib " if what == "libraries" else ""), + click.secho("`platformio %s update`" % + ("lib" if what == "libraries" else "platforms"), fg="cyan", nl=False) click.secho(" command.\n", fg="yellow") else: click.secho("Please wait while updating %s ..." % what, fg="yellow") if what == "platforms": - ctx.invoke(cli_update) + ctx.invoke(cmd_platforms_update) elif what == "libraries": ctx.invoke(cmd_libraries_update) click.echo() diff --git a/tests/commands/test_boards.py b/tests/commands/test_boards.py index 4a96d2e5..62a7f102 100644 --- a/tests/commands/test_boards.py +++ b/tests/commands/test_boards.py @@ -5,13 +5,15 @@ import json from os.path import isfile, join from platformio import util -from platformio.commands.boards import cli as boards_cli -from platformio.commands.install import cli as install_cli -from platformio.commands.search import cli as search_cli +from platformio.commands.boards import cli as cmd_boards +from platformio.commands.platforms import \ + platforms_install as cmd_platforms_install +from platformio.commands.platforms import \ + platforms_search as cmd_platforms_search def test_board_json_output(platformio_setup, clirunner, validate_cliresult): - result = clirunner.invoke(boards_cli, ["cortex", "--json-output"]) + result = clirunner.invoke(cmd_boards, ["cortex", "--json-output"]) validate_cliresult(result) boards = json.loads(result.output) assert isinstance(boards, dict) @@ -19,7 +21,7 @@ def test_board_json_output(platformio_setup, clirunner, validate_cliresult): def test_board_raw_output(platformio_setup, clirunner, validate_cliresult): - result = clirunner.invoke(boards_cli, ["energia"]) + result = clirunner.invoke(cmd_boards, ["energia"]) validate_cliresult(result) assert "titiva" in result.output @@ -29,7 +31,7 @@ def test_board_options(platformio_setup, clirunner, validate_cliresult): ["build", "platform", "upload", "name"]) # fetch available platforms - result = clirunner.invoke(search_cli, ["--json-output"]) + result = clirunner.invoke(cmd_platforms_search, ["--json-output"]) validate_cliresult(result) search_result = json.loads(result.output) assert isinstance(search_result, list) @@ -43,7 +45,7 @@ def test_board_options(platformio_setup, clirunner, validate_cliresult): def test_board_ldscripts(platformio_setup, clirunner, validate_cliresult): result = clirunner.invoke( - install_cli, [ + cmd_platforms_install, [ "ststm32", "--skip-default-package", "--with-package=ldscripts" From 1cf026d9568b228cc6494ec4c4b6751290154674 Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Fri, 17 Apr 2015 15:32:33 +0100 Subject: [PATCH 05/49] Fix platform tests according refactor changes --- tests/commands/test_list.py | 22 ----------------- tests/commands/test_platforms.py | 42 ++++++++++++++++++++++++++++++++ tests/commands/test_search.py | 22 ----------------- 3 files changed, 42 insertions(+), 44 deletions(-) delete mode 100644 tests/commands/test_list.py create mode 100644 tests/commands/test_platforms.py delete mode 100644 tests/commands/test_search.py diff --git a/tests/commands/test_list.py b/tests/commands/test_list.py deleted file mode 100644 index e40b5926..00000000 --- a/tests/commands/test_list.py +++ /dev/null @@ -1,22 +0,0 @@ -# Copyright (C) Ivan Kravets -# See LICENSE for details. - -import json - -from platformio.commands.list import cli - - -def test_list_json_output(clirunner, validate_cliresult): - result = clirunner.invoke(cli, ["--json-output"]) - validate_cliresult(result) - list_result = json.loads(result.output) - assert isinstance(list_result, list) - assert len(list_result) - platforms = [item['name'] for item in list_result] - assert "titiva" in platforms - - -def test_list_raw_output(clirunner, validate_cliresult): - result = clirunner.invoke(cli) - validate_cliresult(result) - assert "teensy" in result.output diff --git a/tests/commands/test_platforms.py b/tests/commands/test_platforms.py new file mode 100644 index 00000000..310967a2 --- /dev/null +++ b/tests/commands/test_platforms.py @@ -0,0 +1,42 @@ +# Copyright (C) Ivan Kravets +# See LICENSE for details. + +import json + +from platformio.commands.platforms import \ + platforms_list as cmd_platforms_list +from platformio.commands.platforms import \ + platforms_search as cmd_platforms_search + + +def test_list_json_output(clirunner, validate_cliresult): + result = clirunner.invoke(cmd_platforms_list, ["--json-output"]) + validate_cliresult(result) + list_result = json.loads(result.output) + assert isinstance(list_result, list) + assert len(list_result) + platforms = [item['name'] for item in list_result] + assert "titiva" in platforms + + +def test_list_raw_output(clirunner, validate_cliresult): + result = clirunner.invoke(cmd_platforms_list) + validate_cliresult(result) + assert "teensy" in result.output + + +def test_search_json_output(clirunner, validate_cliresult): + result = clirunner.invoke(cmd_platforms_search, + ["arduino", "--json-output"]) + validate_cliresult(result) + search_result = json.loads(result.output) + assert isinstance(search_result, list) + assert len(search_result) + platforms = [item['type'] for item in search_result] + assert "atmelsam" in platforms + + +def test_search_raw_output(clirunner, validate_cliresult): + result = clirunner.invoke(cmd_platforms_search, ["arduino"]) + validate_cliresult(result) + assert "teensy" in result.output diff --git a/tests/commands/test_search.py b/tests/commands/test_search.py deleted file mode 100644 index 4179f1b2..00000000 --- a/tests/commands/test_search.py +++ /dev/null @@ -1,22 +0,0 @@ -# Copyright (C) Ivan Kravets -# See LICENSE for details. - -import json - -from platformio.commands.search import cli - - -def test_search_json_output(clirunner, validate_cliresult): - result = clirunner.invoke(cli, ["arduino", "--json-output"]) - validate_cliresult(result) - search_result = json.loads(result.output) - assert isinstance(search_result, list) - assert len(search_result) - platforms = [item['type'] for item in search_result] - assert "atmelsam" in platforms - - -def test_search_raw_output(clirunner, validate_cliresult): - result = clirunner.invoke(cli, ["arduino"]) - validate_cliresult(result) - assert "teensy" in result.output From ee962c1919c1af0f268e979639eca522f387850a Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Mon, 20 Apr 2015 16:19:59 +0100 Subject: [PATCH 06/49] Created PlatformIO gitter.im room --- HISTORY.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/HISTORY.rst b/HISTORY.rst index f2fc641a..193143d6 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -7,6 +7,8 @@ Release History * Implemented PlatformIO CLI 2.0: "platform" related commands have been moved to ``platformio platforms`` subcommand (`issue #158 `_) +* Created `PlatformIO gitter.im `_ room + (`issue #174 `_) * Added global ``-f, --force`` option which will force to accept any confirmation prompts (`issue #152 `_) * Allowed to choose which library to update From 71261023defad05df76c59c9a00a97eff82ac97c Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Mon, 20 Apr 2015 17:20:27 +0100 Subject: [PATCH 07/49] Enhance commands output --- platformio/commands/boards.py | 9 ++++++--- platformio/commands/lib.py | 4 +++- platformio/commands/platforms.py | 3 ++- platformio/commands/serialports.py | 2 +- platformio/commands/settings.py | 3 ++- platformio/maintenance.py | 9 ++++++++- 6 files changed, 22 insertions(+), 8 deletions(-) diff --git a/platformio/commands/boards.py b/platformio/commands/boards.py index 1bb89f21..0681623a 100644 --- a/platformio/commands/boards.py +++ b/platformio/commands/boards.py @@ -18,6 +18,7 @@ def cli(query, json_output): # pylint: disable=R0912 BOARDLIST_TPL = ("{type:<30} {mcu:<14} {frequency:<8} " " {flash:<7} {ram:<6} {name}") + terminal_width, _ = click.get_terminal_size() grpboards = {} for type_, data in get_boards().items(): @@ -31,12 +32,14 @@ def cli(query, json_output): # pylint: disable=R0912 if query.lower() not in search_data.lower(): continue - click.echo("\nPlatform: %s" % platform) - click.echo("-" * 75) + click.echo("") + click.echo("Platform: ", nl=False) + click.secho(platform, bold=True) + click.echo("-" * terminal_width) click.echo(BOARDLIST_TPL.format( type=click.style("Type", fg="cyan"), mcu="MCU", frequency="Frequency", flash="Flash", ram="RAM", name="Name")) - click.echo("-" * 75) + click.echo("-" * terminal_width) for type_, data in sorted(boards.items(), key=lambda b: b[1]['name']): if query: diff --git a/platformio/commands/lib.py b/platformio/commands/lib.py index da3d2b19..f90ce614 100644 --- a/platformio/commands/lib.py +++ b/platformio/commands/lib.py @@ -21,7 +21,9 @@ def echo_liblist_header(): authornames="Authors", description="Description" )) - click.echo("-" * 85) + + terminal_width, _ = click.get_terminal_size() + click.echo("-" * terminal_width) def echo_liblist_item(item): diff --git a/platformio/commands/platforms.py b/platformio/commands/platforms.py index b3781074..36fa9b0b 100644 --- a/platformio/commands/platforms.py +++ b/platformio/commands/platforms.py @@ -86,11 +86,12 @@ def platforms_search(query, json_output): if json_output: click.echo(json.dumps(data)) else: + terminal_width, _ = click.get_terminal_size() for item in data: click.secho(item['type'], fg="cyan", nl=False) click.echo(" (available packages: %s)" % ", ".join( p.get_packages().keys())) - click.secho("-" * len(item['type']), fg="cyan") + click.echo("-" * terminal_width) click.echo(item['description']) click.echo() diff --git a/platformio/commands/serialports.py b/platformio/commands/serialports.py index c52f27da..5c241d03 100644 --- a/platformio/commands/serialports.py +++ b/platformio/commands/serialports.py @@ -25,7 +25,7 @@ def serialports_list(json_output): for item in get_serialports(): click.secho(item['port'], fg="cyan") - click.echo("----------") + click.echo("-" * len(item['port'])) click.echo("Hardware ID: %s" % item['hwid']) click.echo("Description: %s" % item['description']) click.echo("") diff --git a/platformio/commands/settings.py b/platformio/commands/settings.py index f239559f..e600e197 100644 --- a/platformio/commands/settings.py +++ b/platformio/commands/settings.py @@ -16,6 +16,7 @@ def cli(): def settings_get(name): list_tpl = "{name:<40} {value:<35} {description}" + terminal_width, _ = click.get_terminal_size() click.echo(list_tpl.format( name=click.style("Name", fg="cyan"), @@ -23,7 +24,7 @@ def settings_get(name): click.style(" [Default]", fg="yellow")), description="Description" )) - click.echo("-" * 90) + click.echo("-" * terminal_width) for _name, _data in sorted(app.DEFAULT_SETTINGS.items()): if name and name != _name: diff --git a/platformio/maintenance.py b/platformio/maintenance.py index 36a91f4e..c7976452 100644 --- a/platformio/maintenance.py +++ b/platformio/maintenance.py @@ -193,6 +193,10 @@ def check_internal_updates(ctx, what): if not outdated_items: return + terminal_width, _ = click.get_terminal_size() + + click.echo("") + click.echo("*" * terminal_width) click.secho("There are the new updates for %s (%s)" % (what, ", ".join(outdated_items)), fg="yellow") @@ -201,7 +205,7 @@ def check_internal_updates(ctx, what): click.secho("`platformio %s update`" % ("lib" if what == "libraries" else "platforms"), fg="cyan", nl=False) - click.secho(" command.\n", fg="yellow") + click.secho(" command.", fg="yellow") else: click.secho("Please wait while updating %s ..." % what, fg="yellow") if what == "platforms": @@ -212,3 +216,6 @@ def check_internal_updates(ctx, what): telemetry.on_event(category="Auto", action="Update", label=what.title()) + + click.echo("*" * terminal_width) + click.echo("") From 5af3b9b7c98c88a28e515b93142af65aa0ee493b Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Mon, 20 Apr 2015 19:55:18 +0100 Subject: [PATCH 08/49] Validate passed boards before project initialization --- platformio/commands/init.py | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/platformio/commands/init.py b/platformio/commands/init.py index 1c32ecca..12e70990 100644 --- a/platformio/commands/init.py +++ b/platformio/commands/init.py @@ -11,13 +11,25 @@ from platformio import app, exception from platformio.util import get_boards, get_source_dir +def validate_boards(ctx, param, value): + unknown_boards = set(value) - set(get_boards().keys()) + try: + assert not unknown_boards + return value + except AssertionError: + raise click.BadParameter( + "%s. Please search for the board types using " + "`platformio boards` command" % ", ".join(unknown_boards)) + + @click.command("init", short_help="Initialize new PlatformIO based project") @click.option("--project-dir", "-d", default=getcwd, type=click.Path(exists=True, file_okay=False, dir_okay=True, writable=True, resolve_path=True)) -@click.option("--board", "-b", multiple=True, metavar="TYPE") +@click.option("--board", "-b", multiple=True, metavar="TYPE", + callback=validate_boards) @click.option("--disable-auto-uploading", is_flag=True) -def cli(project_dir, board, disable_auto_uploading): +def cli(project_dir, board, disable_auto_uploading, ide): project_file = join(project_dir, "platformio.ini") src_dir = join(project_dir, "src") @@ -33,11 +45,12 @@ def cli(project_dir, board, disable_auto_uploading): # ask about auto-uploading if board and app.get_setting("enable_prompts"): disable_auto_uploading = not click.confirm( - "\nWould you like to enable firmware auto-uploading when project " + "Would you like to enable firmware auto-uploading when project " "is successfully built using `platformio run` command? \n" "Don't forget that you can upload firmware manually using " "`platformio run --target upload` command." ) + click.echo("") if project_dir == getcwd(): click.secho("\nThe current working directory", fg="yellow", nl=False) @@ -45,9 +58,10 @@ def cli(project_dir, board, disable_auto_uploading): click.secho( "will be used for the new project.\n" "You can specify another project directory via\n" - "`platformio init -d %PATH_TO_THE_PROJECT_DIR%` command.\n", + "`platformio init -d %PATH_TO_THE_PROJECT_DIR%` command.", fg="yellow" ) + click.echo("") click.echo("The next files/directories will be created in %s" % click.style(project_dir, fg="cyan")) @@ -70,7 +84,7 @@ def cli(project_dir, board, disable_auto_uploading): if board: fill_project_envs(project_file, board, disable_auto_uploading) click.secho( - "Project has been successfully initialized!\nUseful commands:\n" + "\nProject has been successfully initialized!\nUseful commands:\n" "`platformio run` - process/build project from the current " "directory\n" "`platformio run --target upload` or `platformio run -t upload` " From 4d8cbc1349addcdc63f3e81159e94a2aeccbe897 Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Wed, 22 Apr 2015 14:21:26 +0100 Subject: [PATCH 09/49] Fix bug with creating copies of source files // Resolve #177 --- HISTORY.rst | 2 ++ platformio/__init__.py | 2 +- platformio/builder/tools/platformio.py | 4 ++-- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/HISTORY.rst b/HISTORY.rst index 193143d6..89ee0785 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -15,6 +15,8 @@ Release History (`issue #168 `_) * Disabled automatic updates by default for platforms, packages and libraries (`issue #171 `_) +* Fixed bug with creating copies of source files + (`issue #177 `_) 1.4.0 (2015-04-11) diff --git a/platformio/__init__.py b/platformio/__init__.py index c6851e7e..ffc095fc 100644 --- a/platformio/__init__.py +++ b/platformio/__init__.py @@ -1,7 +1,7 @@ # Copyright (C) Ivan Kravets # See LICENSE for details. -VERSION = (2, 0, "0.dev1") +VERSION = (2, 0, "0.dev2") __version__ = ".".join([str(s) for s in VERSION]) __title__ = "platformio" diff --git a/platformio/builder/tools/platformio.py b/platformio/builder/tools/platformio.py index 8402e6e3..a45b526d 100644 --- a/platformio/builder/tools/platformio.py +++ b/platformio/builder/tools/platformio.py @@ -31,7 +31,7 @@ def BuildFirmware(env): firmenv = env.Clone() vdirs = firmenv.VariantDirRecursive( - join("$BUILD_DIR", "src"), "$PROJECTSRC_DIR") + join("$BUILD_DIR", "src"), "$PROJECTSRC_DIR", duplicate=False) # build dependent libs deplibs = firmenv.BuildDependentLibraries("$PROJECTSRC_DIR") @@ -365,7 +365,7 @@ def ConvertInoToCpp(env): if not data: return - tmpcpp_file = join(env.subst("$PROJECTSRC_DIR"), "piomain.cpp") + tmpcpp_file = join(env.subst("$PROJECTSRC_DIR"), "tmp_ino_to.cpp") with open(tmpcpp_file, "w") as f: f.write(data) From 60863a43042b7be6e4fb2ef40c366c02ad951c51 Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Wed, 22 Apr 2015 14:58:42 +0100 Subject: [PATCH 10/49] Fix PyLint warnings --- platformio/commands/init.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/platformio/commands/init.py b/platformio/commands/init.py index 12e70990..750e4a62 100644 --- a/platformio/commands/init.py +++ b/platformio/commands/init.py @@ -11,7 +11,7 @@ from platformio import app, exception from platformio.util import get_boards, get_source_dir -def validate_boards(ctx, param, value): +def validate_boards(ctx, param, value): # pylint: disable=W0613 unknown_boards = set(value) - set(get_boards().keys()) try: assert not unknown_boards @@ -29,7 +29,7 @@ def validate_boards(ctx, param, value): @click.option("--board", "-b", multiple=True, metavar="TYPE", callback=validate_boards) @click.option("--disable-auto-uploading", is_flag=True) -def cli(project_dir, board, disable_auto_uploading, ide): +def cli(project_dir, board, disable_auto_uploading): project_file = join(project_dir, "platformio.ini") src_dir = join(project_dir, "src") From 47b8a4dd69697dab283b114729bc7d26cbe2dee2 Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Wed, 22 Apr 2015 15:24:45 +0100 Subject: [PATCH 11/49] Fix test with incorrect board --- tests/commands/test_init.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/commands/test_init.py b/tests/commands/test_init.py index 0d816ff2..d951f760 100644 --- a/tests/commands/test_init.py +++ b/tests/commands/test_init.py @@ -71,4 +71,6 @@ def test_init_disable_auto_uploading(platformio_setup, clirunner, def test_init_incorrect_board(clirunner): result = clirunner.invoke(cli, ["-b", "missed_board"]) - assert isinstance(result.exception, exception.UnknownBoard) + assert result.exit_code == 2 + assert 'Error: Invalid value for "--board" / "-b"' in result.output + assert isinstance(result.exception, SystemExit) From 0d648074e4f65e52a6ef60244b55235234d498e7 Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Thu, 23 Apr 2015 12:40:19 +0100 Subject: [PATCH 12/49] Allow to add more boards to existing platformio.ini // Resolve #167 --- HISTORY.rst | 3 ++ platformio/commands/init.py | 87 +++++++++++++++++++------------------ platformio/exception.py | 6 --- 3 files changed, 48 insertions(+), 48 deletions(-) diff --git a/HISTORY.rst b/HISTORY.rst index 89ee0785..33713b31 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -11,6 +11,9 @@ Release History (`issue #174 `_) * Added global ``-f, --force`` option which will force to accept any confirmation prompts (`issue #152 `_) +* Allowed to add more boards to existing + `platformio.ini `__ + (`issue #167 `_) * Allowed to choose which library to update (`issue #168 `_) * Disabled automatic updates by default for platforms, packages and libraries diff --git a/platformio/commands/init.py b/platformio/commands/init.py index 750e4a62..cd301978 100644 --- a/platformio/commands/init.py +++ b/platformio/commands/init.py @@ -31,17 +31,6 @@ def validate_boards(ctx, param, value): # pylint: disable=W0613 @click.option("--disable-auto-uploading", is_flag=True) def cli(project_dir, board, disable_auto_uploading): - project_file = join(project_dir, "platformio.ini") - src_dir = join(project_dir, "src") - lib_dir = join(project_dir, "lib") - if all([isfile(project_file), isdir(src_dir), isdir(lib_dir)]): - raise exception.ProjectInitialized() - - builtin_boards = set(get_boards().keys()) - if board and not set(board).issubset(builtin_boards): - raise exception.UnknownBoard( - ", ".join(set(board).difference(builtin_boards))) - # ask about auto-uploading if board and app.get_setting("enable_prompts"): disable_auto_uploading = not click.confirm( @@ -56,7 +45,7 @@ def cli(project_dir, board, disable_auto_uploading): click.secho("\nThe current working directory", fg="yellow", nl=False) click.secho(" %s " % project_dir, fg="cyan", nl=False) click.secho( - "will be used for the new project.\n" + "will be used for project.\n" "You can specify another project directory via\n" "`platformio init -d %PATH_TO_THE_PROJECT_DIR%` command.", fg="yellow" @@ -72,49 +61,63 @@ def cli(project_dir, board, disable_auto_uploading): click.echo("%s - Put here project specific or 3-rd party libraries" % click.style("lib", fg="cyan")) - if (not app.get_setting("enable_prompts") or - click.confirm("Do you want to continue?")): - - for d in (src_dir, lib_dir): - if not isdir(d): - makedirs(d) - if not isfile(project_file): - copyfile(join(get_source_dir(), "projectconftpl.ini"), - project_file) - if board: - fill_project_envs(project_file, board, disable_auto_uploading) - click.secho( - "\nProject has been successfully initialized!\nUseful commands:\n" - "`platformio run` - process/build project from the current " - "directory\n" - "`platformio run --target upload` or `platformio run -t upload` " - "- upload firmware to embedded board\n" - "`platformio run --target clean` - clean project (remove compiled " - "files)", - fg="green" - ) - else: + if (app.get_setting("enable_prompts") and + not click.confirm("Do you want to continue?")): raise exception.AbortedByUser() + project_file = join(project_dir, "platformio.ini") + src_dir = join(project_dir, "src") + lib_dir = join(project_dir, "lib") + + for d in (src_dir, lib_dir): + if not isdir(d): + makedirs(d) + + if not isfile(project_file): + copyfile(join(get_source_dir(), "projectconftpl.ini"), + project_file) + + if board: + fill_project_envs(project_file, board, disable_auto_uploading) + + click.secho( + "\nProject has been successfully initialized!\nUseful commands:\n" + "`platformio run` - process/build project from the current " + "directory\n" + "`platformio run --target upload` or `platformio run -t upload` " + "- upload firmware to embedded board\n" + "`platformio run --target clean` - clean project (remove compiled " + "files)", + fg="green" + ) + def fill_project_envs(project_file, board_types, disable_auto_uploading): builtin_boards = get_boards() content = [] - for type_ in board_types: - if type_ not in builtin_boards: - continue - else: - content.append("") + used_envs = [] + with open(project_file) as f: + used_envs = [l.strip() for l in f.read().splitlines() if + l.strip().startswith("[env:")] + + for type_ in board_types: data = builtin_boards[type_] + env_name = "[env:autogen_%s]" % type_ + + if env_name in used_envs: + continue + + content.append("") + content.append(env_name) + content.append("platform = %s" % data['platform']) + # find default framework for board frameworks = data.get("frameworks") - content.append("[env:autogen_%s]" % type_) - content.append("platform = %s" % data['platform']) if frameworks: content.append("framework = %s" % frameworks[0]) - content.append("board = %s" % type_) + content.append("board = %s" % type_) content.append("%stargets = upload" % ("# " if disable_auto_uploading else "")) diff --git a/platformio/exception.py b/platformio/exception.py index 451e7761..daaa176e 100644 --- a/platformio/exception.py +++ b/platformio/exception.py @@ -96,12 +96,6 @@ class UnsupportedArchiveType(PlatformioException): MESSAGE = "Can not unpack file '%s'" -class ProjectInitialized(PlatformioException): - - MESSAGE = ("Project is already initialized. " - "Process it with `platformio run` command") - - class ProjectEnvsNotAvailable(PlatformioException): MESSAGE = "Please setup environments in `platformio.ini` file." From 476de84dc5729b263e82543de742e2a1219f6d71 Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Thu, 23 Apr 2015 12:54:59 +0100 Subject: [PATCH 13/49] Allow to specify environment prefix when initialise project // Resolve #182 --- HISTORY.rst | 2 ++ docs/userguide/cmd_init.rst | 8 ++++++++ platformio/commands/init.py | 15 +++++++++++---- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/HISTORY.rst b/HISTORY.rst index 33713b31..b765373a 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -16,6 +16,8 @@ Release History (`issue #167 `_) * Allowed to choose which library to update (`issue #168 `_) +* Allowed to specify `platformio init --env-prefix `__ when initialise/update project + (`issue #182 `_) * Disabled automatic updates by default for platforms, packages and libraries (`issue #171 `_) * Fixed bug with creating copies of source files diff --git a/docs/userguide/cmd_init.rst b/docs/userguide/cmd_init.rst index 4890adf1..637cdafd 100644 --- a/docs/userguide/cmd_init.rst +++ b/docs/userguide/cmd_init.rst @@ -54,6 +54,14 @@ If you initialise project with the specified ``--board``, then *PlatformIO* will create environment with enabled firmware auto-uploading. This option allows you to disable firmware auto-uploading by default. +.. option:: + --env-prefix + +An environment prefix which will be used with pair in board type. The default +value is ``autogen_``. For example, the default environment name for +``teensy_31`` board will be ``[env:autogen_teensy_31]``. + + Examples -------- diff --git a/platformio/commands/init.py b/platformio/commands/init.py index cd301978..a77d753a 100644 --- a/platformio/commands/init.py +++ b/platformio/commands/init.py @@ -29,7 +29,8 @@ def validate_boards(ctx, param, value): # pylint: disable=W0613 @click.option("--board", "-b", multiple=True, metavar="TYPE", callback=validate_boards) @click.option("--disable-auto-uploading", is_flag=True) -def cli(project_dir, board, disable_auto_uploading): +@click.option("--env-prefix", default="autogen_") +def cli(project_dir, board, disable_auto_uploading, env_prefix): # ask about auto-uploading if board and app.get_setting("enable_prompts"): @@ -78,7 +79,8 @@ def cli(project_dir, board, disable_auto_uploading): project_file) if board: - fill_project_envs(project_file, board, disable_auto_uploading) + fill_project_envs( + project_file, board, disable_auto_uploading, env_prefix) click.secho( "\nProject has been successfully initialized!\nUseful commands:\n" @@ -92,7 +94,8 @@ def cli(project_dir, board, disable_auto_uploading): ) -def fill_project_envs(project_file, board_types, disable_auto_uploading): +def fill_project_envs(project_file, board_types, disable_auto_uploading, + env_prefix): builtin_boards = get_boards() content = [] used_envs = [] @@ -103,7 +106,7 @@ def fill_project_envs(project_file, board_types, disable_auto_uploading): for type_ in board_types: data = builtin_boards[type_] - env_name = "[env:autogen_%s]" % type_ + env_name = "[env:%s%s]" % (env_prefix, type_) if env_name in used_envs: continue @@ -121,5 +124,9 @@ def fill_project_envs(project_file, board_types, disable_auto_uploading): content.append("%stargets = upload" % ("# " if disable_auto_uploading else "")) + if not content: + return + with open(project_file, "a") as f: + content.append("") f.write("\n".join(content)) From 31a2880c3c123069610abf61a9417d9203c18d82 Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Thu, 23 Apr 2015 13:09:41 +0100 Subject: [PATCH 14/49] Improve carols with Bountysource --- platformio/maintenance.py | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/platformio/maintenance.py b/platformio/maintenance.py index c7976452..a44f454f 100644 --- a/platformio/maintenance.py +++ b/platformio/maintenance.py @@ -109,8 +109,12 @@ def after_upgrade(ctx): if last_version == __version__: return + terminal_width, _ = click.get_terminal_size() + # promotion - click.echo("\nIf you like %s, please:" % ( + click.echo("") + click.echo("*" * terminal_width) + click.echo("If you like %s, please:" % ( click.style("PlatformIO", fg="cyan") )) click.echo( @@ -123,7 +127,13 @@ def after_upgrade(ctx): click.style("give", fg="cyan"), click.style("https://github.com/platformio/platformio", fg="cyan") )) - click.secho("Thanks a lot!\n", fg="green") + click.echo("- %s for the new features/issues on Bountysource > %s" % ( + click.style("vote", fg="cyan"), + click.style("https://www.bountysource.com/teams/platformio/issues", + fg="cyan") + )) + click.echo("*" * terminal_width) + click.echo("") if last_version == "0.0.0": app.set_state_item("last_version", __version__) @@ -162,13 +172,19 @@ def check_platformio_upgrade(): Upgrader.version_to_int(__version__)): return + terminal_width, _ = click.get_terminal_size() + + click.echo("") + click.echo("*" * terminal_width) click.secho("There is a new version %s of PlatformIO available.\n" "Please upgrade it via " % latest_version, fg="yellow", nl=False) click.secho("platformio upgrade", fg="cyan", nl=False) click.secho(" command.\nChanges: ", fg="yellow", nl=False) - click.secho("http://docs.platformio.org/en/latest/history.html\n", + click.secho("http://docs.platformio.org/en/latest/history.html", fg="cyan") + click.echo("*" * terminal_width) + click.echo("") def check_internal_updates(ctx, what): From 97044bf5a54d7573b0a2b5fb46219de81cc806ed Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Thu, 23 Apr 2015 14:11:30 +0100 Subject: [PATCH 15/49] Improve cache logic for lookup operations --- platformio/pkgmanager.py | 14 ++--- platformio/platforms/base.py | 49 +++++++-------- platformio/util.py | 114 +++++++++++++++++++++++------------ 3 files changed, 106 insertions(+), 71 deletions(-) diff --git a/platformio/pkgmanager.py b/platformio/pkgmanager.py index bd0e816f..b60332af 100644 --- a/platformio/pkgmanager.py +++ b/platformio/pkgmanager.py @@ -8,28 +8,24 @@ from time import time import click -from platformio import exception, telemetry +from platformio import exception, telemetry, util from platformio.app import get_state_item, set_state_item from platformio.downloader import FileDownloader from platformio.unpacker import FileUnpacker -from platformio.util import get_api_result, get_home_dir, get_systype class PackageManager(object): def __init__(self): - self._package_dir = join(get_home_dir(), "packages") + self._package_dir = join(util.get_home_dir(), "packages") if not isdir(self._package_dir): makedirs(self._package_dir) assert isdir(self._package_dir) @classmethod + @util.memoized def get_manifest(cls): - try: - return cls._cached_manifest - except AttributeError: - cls._cached_manifest = get_api_result("/packages/manifest") - return cls._cached_manifest + return util.get_api_result("/packages/manifest") @staticmethod def download(url, dest_dir, sha1=None): @@ -63,7 +59,7 @@ class PackageManager(object): raise exception.UnknownPackage(name) # check system platform - systype = get_systype() + systype = util.get_systype() builds = ([b for b in manifest[name] if b['system'] == "all" or systype in b['system']]) if not builds: diff --git a/platformio/platforms/base.py b/platformio/platforms/base.py index 9be68191..d91118ec 100644 --- a/platformio/platforms/base.py +++ b/platformio/platforms/base.py @@ -132,32 +132,33 @@ class PlatformFactory(object): return module @classmethod - def get_platforms(cls, installed=False): + @util.memoized + def _lookup_platforms(cls): platforms = {} - - try: - platforms = cls.get_platforms_cache - except AttributeError: - for d in (util.get_home_dir(), util.get_source_dir()): - pdir = join(d, "platforms") - if not isdir(pdir): + for d in (util.get_home_dir(), util.get_source_dir()): + pdir = join(d, "platforms") + if not isdir(pdir): + continue + for p in listdir(pdir): + if (p in ("__init__.py", "base.py") or not + p.endswith(".py")): continue - for p in listdir(pdir): - if (p in ("__init__.py", "base.py") or not - p.endswith(".py")): - continue - type_ = p[:-3] - path = join(pdir, p) - try: - isplatform = hasattr( - cls.load_module(type_, path), - cls.get_clsname(type_) - ) - if isplatform: - platforms[type_] = path - except exception.UnknownPlatform: - pass - cls.get_platforms_cache = platforms + type_ = p[:-3] + path = join(pdir, p) + try: + isplatform = hasattr( + cls.load_module(type_, path), + cls.get_clsname(type_) + ) + if isplatform: + platforms[type_] = path + except exception.UnknownPlatform: + pass + return platforms + + @classmethod + def get_platforms(cls, installed=False): + platforms = cls._lookup_platforms() if not installed: return platforms diff --git a/platformio/util.py b/platformio/util.py index 82582573..a4faf4ca 100644 --- a/platformio/util.py +++ b/platformio/util.py @@ -1,6 +1,8 @@ # Copyright (C) Ivan Kravets # See LICENSE for details. +import collections +import functools import json import os import re @@ -53,6 +55,39 @@ class AsyncPipe(Thread): self.join() +class memoized(object): + ''' + Decorator. Caches a function's return value each time it is called. + If called later with the same arguments, the cached value is returned + (not reevaluated). + https://wiki.python.org/moin/PythonDecoratorLibrary#Memoize + ''' + + def __init__(self, func): + self.func = func + self.cache = {} + + def __call__(self, *args): + if not isinstance(args, collections.Hashable): + # uncacheable. a list, for instance. + # better to not cache than blow up. + return self.func(*args) + if args in self.cache: + return self.cache[args] + else: + value = self.func(*args) + self.cache[args] = value + return value + + def __repr__(self): + '''Return the function's docstring.''' + return self.func.__doc__ + + def __get__(self, obj, objtype): + '''Support instance methods.''' + return functools.partial(self.__call__, obj) + + def get_systype(): data = uname() return ("%s_%s" % (data[0], data[4])).lower() @@ -239,22 +274,24 @@ def get_api_result(path, params=None, data=None): return result -def get_boards(type_=None): +@memoized +def _lookup_boards(): boards = {} - try: - boards = get_boards._cache # pylint: disable=W0212 - except AttributeError: - bdirs = [join(get_source_dir(), "boards")] - if isdir(join(get_home_dir(), "boards")): - bdirs.append(join(get_home_dir(), "boards")) + bdirs = [join(get_source_dir(), "boards")] + if isdir(join(get_home_dir(), "boards")): + bdirs.append(join(get_home_dir(), "boards")) - for bdir in bdirs: - for json_file in os.listdir(bdir): - if not json_file.endswith(".json"): - continue - with open(join(bdir, json_file)) as f: - boards.update(json.load(f)) - get_boards._cache = boards # pylint: disable=W0212 + for bdir in bdirs: + for json_file in os.listdir(bdir): + if not json_file.endswith(".json"): + continue + with open(join(bdir, json_file)) as f: + boards.update(json.load(f)) + return boards + + +def get_boards(type_=None): + boards = _lookup_boards() if type_ is None: return boards @@ -264,33 +301,34 @@ def get_boards(type_=None): return boards[type_] -def get_frameworks(type_=None): +@memoized +def _lookup_frameworks(): frameworks = {} + frameworks_path = join( + get_source_dir(), "builder", "scripts", "frameworks") - try: - frameworks = get_frameworks._cache # pylint: disable=W0212 - except AttributeError: - frameworks_path = join( - get_source_dir(), "builder", "scripts", "frameworks") + frameworks_list = [f[:-3] for f in os.listdir(frameworks_path) + if not f.startswith("__") and f.endswith(".py")] + for _type in frameworks_list: + script_path = join(frameworks_path, "%s.py" % _type) + with open(script_path) as f: + fcontent = f.read() + assert '"""' in fcontent + _doc_start = fcontent.index('"""') + 3 + fdoc = fcontent[ + _doc_start:fcontent.index('"""', _doc_start)].strip() + doclines = [l.strip() for l in fdoc.splitlines() if l.strip()] + frameworks[_type] = { + "name": doclines[0], + "description": " ".join(doclines[1:-1]), + "url": doclines[-1], + "script": script_path + } + return frameworks - frameworks_list = [f[:-3] for f in os.listdir(frameworks_path) - if not f.startswith("__") and f.endswith(".py")] - for _type in frameworks_list: - script_path = join(frameworks_path, "%s.py" % _type) - with open(script_path) as f: - fcontent = f.read() - assert '"""' in fcontent - _doc_start = fcontent.index('"""') + 3 - fdoc = fcontent[ - _doc_start:fcontent.index('"""', _doc_start)].strip() - doclines = [l.strip() for l in fdoc.splitlines() if l.strip()] - frameworks[_type] = { - "name": doclines[0], - "description": " ".join(doclines[1:-1]), - "url": doclines[-1], - "script": script_path - } - get_frameworks._cache = frameworks # pylint: disable=W0212 + +def get_frameworks(type_=None): + frameworks = _lookup_frameworks() if type_ is None: return frameworks From 6fd07e1e5692c3bcab10cd6844e8336d6cc52c15 Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Fri, 24 Apr 2015 14:43:13 +0100 Subject: [PATCH 16/49] Initial support of PlatformIO Project Generator // Issue #151 --- .isort.cfg | 2 +- platformio/__init__.py | 2 +- platformio/commands/init.py | 9 ++- platformio/ide/__init__.py | 2 + platformio/ide/projectgenerator.py | 63 +++++++++++++++ platformio/ide/tpls/eclipse/.cproject.tpl | 81 +++++++++++++++++++ platformio/ide/tpls/eclipse/.project.tpl | 27 +++++++ .../ide/tpls/qtcreator/platformio.pro.tpl | 19 +++++ .../platformio.sublime-project.tpl | 45 +++++++++++ .../platformio.vcxproj.filters.tpl | 29 +++++++ .../tpls/visualstudio/platformio.vcxproj.tpl | 62 ++++++++++++++ requirements.txt | 1 + setup.py | 10 ++- 13 files changed, 348 insertions(+), 4 deletions(-) create mode 100644 platformio/ide/__init__.py create mode 100644 platformio/ide/projectgenerator.py create mode 100644 platformio/ide/tpls/eclipse/.cproject.tpl create mode 100644 platformio/ide/tpls/eclipse/.project.tpl create mode 100644 platformio/ide/tpls/qtcreator/platformio.pro.tpl create mode 100644 platformio/ide/tpls/sublimetext/platformio.sublime-project.tpl create mode 100644 platformio/ide/tpls/visualstudio/platformio.vcxproj.filters.tpl create mode 100644 platformio/ide/tpls/visualstudio/platformio.vcxproj.tpl diff --git a/.isort.cfg b/.isort.cfg index 72280366..3dbd6d91 100644 --- a/.isort.cfg +++ b/.isort.cfg @@ -1,3 +1,3 @@ [settings] line_length=79 -known_third_party=click,requests,serial,SCons,pytest +known_third_party=click,requests,serial,SCons,pytest,bottle diff --git a/platformio/__init__.py b/platformio/__init__.py index ffc095fc..9e004963 100644 --- a/platformio/__init__.py +++ b/platformio/__init__.py @@ -1,7 +1,7 @@ # Copyright (C) Ivan Kravets # See LICENSE for details. -VERSION = (2, 0, "0.dev2") +VERSION = (2, 0, "0.dev3") __version__ = ".".join([str(s) for s in VERSION]) __title__ = "platformio" diff --git a/platformio/commands/init.py b/platformio/commands/init.py index a77d753a..229a1c23 100644 --- a/platformio/commands/init.py +++ b/platformio/commands/init.py @@ -8,6 +8,7 @@ from shutil import copyfile import click from platformio import app, exception +from platformio.ide.projectgenerator import ProjectGenerator from platformio.util import get_boards, get_source_dir @@ -28,9 +29,11 @@ def validate_boards(ctx, param, value): # pylint: disable=W0613 writable=True, resolve_path=True)) @click.option("--board", "-b", multiple=True, metavar="TYPE", callback=validate_boards) +@click.option("--ide", + type=click.Choice(ProjectGenerator.get_supported_ides())) @click.option("--disable-auto-uploading", is_flag=True) @click.option("--env-prefix", default="autogen_") -def cli(project_dir, board, disable_auto_uploading, env_prefix): +def cli(project_dir, board, ide, disable_auto_uploading, env_prefix): # ask about auto-uploading if board and app.get_setting("enable_prompts"): @@ -82,6 +85,10 @@ def cli(project_dir, board, disable_auto_uploading, env_prefix): fill_project_envs( project_file, board, disable_auto_uploading, env_prefix) + if ide: + pg = ProjectGenerator(project_dir, ide) + pg.generate() + click.secho( "\nProject has been successfully initialized!\nUseful commands:\n" "`platformio run` - process/build project from the current " diff --git a/platformio/ide/__init__.py b/platformio/ide/__init__.py new file mode 100644 index 00000000..ca6f0304 --- /dev/null +++ b/platformio/ide/__init__.py @@ -0,0 +1,2 @@ +# Copyright (C) Ivan Kravets +# See LICENSE for details. diff --git a/platformio/ide/projectgenerator.py b/platformio/ide/projectgenerator.py new file mode 100644 index 00000000..3ce36a6b --- /dev/null +++ b/platformio/ide/projectgenerator.py @@ -0,0 +1,63 @@ +# Copyright (C) Ivan Kravets +# See LICENSE for details. + +from glob import glob +from os import listdir +from os.path import basename, isdir, join + +import bottle + +from platformio import util + + +class ProjectGenerator(object): + + def __init__(self, project_dir, ide): + self.project_dir = project_dir + self.ide = ide + self._tplvars = self._gather_tplvars() + + @staticmethod + def get_supported_ides(): + tpls_dir = join(util.get_source_dir(), "ide", "tpls") + return [d for d in listdir(tpls_dir) + if isdir(join(tpls_dir, d))] + + @staticmethod + def get_project_env(): + data = {} + config = util.get_project_config() + for section in config.sections(): + if not section.startswith("env:"): + continue + for k, v in config.items(section): + data[k] = v + return data + + def get_project_name(self): + return basename(self.project_dir) + + def get_tpls(self): + tpls_dir = join(util.get_source_dir(), "ide", "tpls", self.ide) + return glob(join(tpls_dir, ".*.tpl")) + glob(join(tpls_dir, "*.tpl")) + + def generate(self): + for tpl_path in self.get_tpls(): + file_name = basename(tpl_path)[:-4] + with open(join(self.project_dir, file_name), "w") as f: + f.write(self._render_tpl(tpl_path)) + + def _render_tpl(self, tpl_path): + content = "" + with open(tpl_path) as f: + content = f.read() + return bottle.template(content, **self._tplvars) + + def _gather_tplvars(self): + data = self.get_project_env() + + data.update({ + "project_name": self.get_project_name() + }) + + return data diff --git a/platformio/ide/tpls/eclipse/.cproject.tpl b/platformio/ide/tpls/eclipse/.cproject.tpl new file mode 100644 index 00000000..7ed43a49 --- /dev/null +++ b/platformio/ide/tpls/eclipse/.cproject.tpl @@ -0,0 +1,81 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/platformio/ide/tpls/eclipse/.project.tpl b/platformio/ide/tpls/eclipse/.project.tpl new file mode 100644 index 00000000..ac49f548 --- /dev/null +++ b/platformio/ide/tpls/eclipse/.project.tpl @@ -0,0 +1,27 @@ + + + {{project_name}} + + + + + + org.eclipse.cdt.managedbuilder.core.genmakebuilder + clean,full,incremental, + + + + + org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder + full,incremental, + + + + + + org.eclipse.cdt.core.cnature + org.eclipse.cdt.core.ccnature + org.eclipse.cdt.managedbuilder.core.managedBuildNature + org.eclipse.cdt.managedbuilder.core.ScannerConfigNature + + diff --git a/platformio/ide/tpls/qtcreator/platformio.pro.tpl b/platformio/ide/tpls/qtcreator/platformio.pro.tpl new file mode 100644 index 00000000..22188cd8 --- /dev/null +++ b/platformio/ide/tpls/qtcreator/platformio.pro.tpl @@ -0,0 +1,19 @@ +win32 { + HOMEDIR += $$(USERPROFILE) +} +else { + HOMEDIR += $$(PWD) +} + +INCLUDEPATH += "$$HOMEDIR/.platformio/packages/framework-arduinoavr/cores/arduino" +INCLUDEPATH += "$$HOMEDIR/.platformio/packages/toolchain-atmelavr/avr/include" + +win32:INCLUDEPATH ~= s,/,\\,g + +# DEFINES += __AVR_ATmega328__ + +OTHER_FILES += \ + platformio.ini + +SOURCES += \ + src/main.c diff --git a/platformio/ide/tpls/sublimetext/platformio.sublime-project.tpl b/platformio/ide/tpls/sublimetext/platformio.sublime-project.tpl new file mode 100644 index 00000000..8054bd59 --- /dev/null +++ b/platformio/ide/tpls/sublimetext/platformio.sublime-project.tpl @@ -0,0 +1,45 @@ +{ + "build_systems": + [ + { + "cmd": + [ + "platformio", + "run" + ], + "name": "{{project_name}}", + "variants": + [ + { + "cmd": + [ + "platformio", + "--force", + "run", + "--target", + "clean" + ], + "name": "Clean" + }, + { + "cmd": + [ + "platformio", + "--force", + "run", + "--target", + "upload" + ], + "name": "Upload" + } + ], + "working_dir": "${project_path:${folder}}" + } + ], + "folders": + [ + { + "path": "." + } + ] +} diff --git a/platformio/ide/tpls/visualstudio/platformio.vcxproj.filters.tpl b/platformio/ide/tpls/visualstudio/platformio.vcxproj.filters.tpl new file mode 100644 index 00000000..87bc92f6 --- /dev/null +++ b/platformio/ide/tpls/visualstudio/platformio.vcxproj.filters.tpl @@ -0,0 +1,29 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + {cad450ef-1a84-42d4-a5b5-a1736b8833d3} + + + + + + + + + Source Files\src + + + \ No newline at end of file diff --git a/platformio/ide/tpls/visualstudio/platformio.vcxproj.tpl b/platformio/ide/tpls/visualstudio/platformio.vcxproj.tpl new file mode 100644 index 00000000..4da8da32 --- /dev/null +++ b/platformio/ide/tpls/visualstudio/platformio.vcxproj.tpl @@ -0,0 +1,62 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + + {0FA9C3A8-452B-41EF-A418-9102B170F49F} + MakeFileProj + + + + Makefile + true + v120 + + + Makefile + false + v120 + + + + + + + + + + + + + platformio --force run + platformio --force run --target clean + WIN32;_DEBUG;$(NMakePreprocessorDefinitions) + $(HOMEDRIVE)$(HOMEPATH)\.platformio\packages\toolchain-atmelavr\avr\include;$(HOMEDRIVE)$(HOMEPATH)\.platformio\packages\framework-arduinoavr\cores\arduino;$(NMakeIncludeSearchPath) + + + platformio run + platformio run -t clean + WIN32;NDEBUG;$(NMakePreprocessorDefinitions) + $(HOMEDRIVE)$(HOMEPATH)\.platformio\packages\toolchain-atmelavr\avr\include;$(HOMEDRIVE)$(HOMEPATH)\.platformio\packages\framework-arduinoavr\cores\arduino;$(NMakeIncludeSearchPath) + + + + + + + + + + + + + + \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 6a5ccae6..a540932f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ +bottle=0.12.8 click==3.3 colorama==0.3.3 pyserial==2.7 diff --git a/setup.py b/setup.py index 9a01f68c..41b5a586 100644 --- a/setup.py +++ b/setup.py @@ -18,13 +18,21 @@ setup( url=__url__, license=__license__, install_requires=[ + "bottle", "click>=3.0", "pyserial", "requests>=2.4.0", # "SCons" ] + (["colorama"] if system() == "Windows" else []), packages=find_packages(), - package_data={"platformio": ["projectconftpl.ini", "boards/*.json"]}, + package_data={ + "platformio": [ + "projectconftpl.ini", + "boards/*.json", + "ide/tpls/*/.*.tpl", + "ide/tpls/*/*.tpl" + ] + }, entry_points={ "console_scripts": [ "platformio = platformio.__main__:main" From c79114c345c01a13fb65dfaf13007c2c15746c9d Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Fri, 24 Apr 2015 14:53:07 +0100 Subject: [PATCH 17/49] Fix build system to "PlatformIO" for ST --- platformio/ide/tpls/sublimetext/platformio.sublime-project.tpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platformio/ide/tpls/sublimetext/platformio.sublime-project.tpl b/platformio/ide/tpls/sublimetext/platformio.sublime-project.tpl index 8054bd59..4c4855a2 100644 --- a/platformio/ide/tpls/sublimetext/platformio.sublime-project.tpl +++ b/platformio/ide/tpls/sublimetext/platformio.sublime-project.tpl @@ -7,7 +7,7 @@ "platformio", "run" ], - "name": "{{project_name}}", + "name": "PlatformIO", "variants": [ { From d415cbbe45b8547b03f150b28706b208fd7dc71d Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Fri, 24 Apr 2015 15:33:29 +0100 Subject: [PATCH 18/49] Require minimum 1 argument for the "install" command --- platformio/commands/platforms.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platformio/commands/platforms.py b/platformio/commands/platforms.py index 8d8486c6..54a4721d 100644 --- a/platformio/commands/platforms.py +++ b/platformio/commands/platforms.py @@ -18,7 +18,7 @@ def cli(): @cli.command("install", short_help="Install new platforms") -@click.argument("platforms", nargs=-1) +@click.argument("platforms", nargs=-1, required=True) @click.option("--with-package", multiple=True, metavar="") @click.option("--without-package", multiple=True, metavar="") @click.option("--skip-default-package", is_flag=True) From 0bf7e68ea55a9f2aadf033e091cfe3034527c4ac Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Fri, 24 Apr 2015 15:37:08 +0100 Subject: [PATCH 19/49] Require minimum 1 argument for the "uninstall" command --- platformio/commands/platforms.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platformio/commands/platforms.py b/platformio/commands/platforms.py index 54a4721d..bdfae393 100644 --- a/platformio/commands/platforms.py +++ b/platformio/commands/platforms.py @@ -131,7 +131,7 @@ def platforms_show(ctx, platform): @cli.command("uninstall", short_help="Uninstall platforms") -@click.argument("platforms", nargs=-1) +@click.argument("platforms", nargs=-1, required=True) def platforms_uninstall(platforms): for platform in platforms: From 36ad6efa258ef15c6f523f5695e113ad301e21a1 Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Fri, 24 Apr 2015 15:48:32 +0100 Subject: [PATCH 20/49] Handle obsoleted commands // Issue #158 --- platformio/__main__.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/platformio/__main__.py b/platformio/__main__.py index a3de3544..892b36c0 100644 --- a/platformio/__main__.py +++ b/platformio/__main__.py @@ -31,9 +31,23 @@ class PlatformioCLI(click.MultiCommand): # pylint: disable=R0904 mod = __import__("platformio.commands." + name, None, None, ["cli"]) except ImportError: - raise exception.UnknownCLICommand(name) + try: + return self._handle_obsolate_command(name) + except AttributeError: + raise exception.UnknownCLICommand(name) return mod.cli + def _handle_obsolate_command(self, name): + if name in ("install", "list", "search", "show", "uninstall"): + click.secho( + "Warning! `platformio %s` command is obsoleted! Please use " + "`platformio platforms %s`" % (name, name), + fg="red" + ) + from platformio.commands import platforms + return getattr(platforms, "platforms_" + name) + raise AttributeError() + @click.command(cls=PlatformioCLI) @click.version_option(__version__, prog_name="PlatformIO") From 97d229232d1ca902c4bab55973999607e628f6ec Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Fri, 24 Apr 2015 15:51:08 +0100 Subject: [PATCH 21/49] Correct warning about obsoleted commands --- platformio/__main__.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/platformio/__main__.py b/platformio/__main__.py index 892b36c0..d0e910c8 100644 --- a/platformio/__main__.py +++ b/platformio/__main__.py @@ -40,8 +40,9 @@ class PlatformioCLI(click.MultiCommand): # pylint: disable=R0904 def _handle_obsolate_command(self, name): if name in ("install", "list", "search", "show", "uninstall"): click.secho( - "Warning! `platformio %s` command is obsoleted! Please use " - "`platformio platforms %s`" % (name, name), + "Warning! `platformio %s` command is obsoleted and will be " + "removed in the next release! Please use " + "`platformio platforms %s` instead." % (name, name), fg="red" ) from platformio.commands import platforms From 8b8d5c360ca8f8a2b41c8827c3b9d95f71fad472 Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Fri, 24 Apr 2015 16:34:14 +0100 Subject: [PATCH 22/49] Add prototypes for includes/srcfiles --- platformio/ide/projectgenerator.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/platformio/ide/projectgenerator.py b/platformio/ide/projectgenerator.py index 3ce36a6b..7873d801 100644 --- a/platformio/ide/projectgenerator.py +++ b/platformio/ide/projectgenerator.py @@ -37,6 +37,12 @@ class ProjectGenerator(object): def get_project_name(self): return basename(self.project_dir) + def get_includes(self): + return [] + + def get_srcfiles(self): + return [] + def get_tpls(self): tpls_dir = join(util.get_source_dir(), "ide", "tpls", self.ide) return glob(join(tpls_dir, ".*.tpl")) + glob(join(tpls_dir, "*.tpl")) @@ -45,6 +51,7 @@ class ProjectGenerator(object): for tpl_path in self.get_tpls(): file_name = basename(tpl_path)[:-4] with open(join(self.project_dir, file_name), "w") as f: + print tpl_path f.write(self._render_tpl(tpl_path)) def _render_tpl(self, tpl_path): @@ -57,7 +64,9 @@ class ProjectGenerator(object): data = self.get_project_env() data.update({ - "project_name": self.get_project_name() + "project_name": self.get_project_name(), + "includes": self.get_includes(), + "srcfiles": self.get_srcfiles() }) return data From c14b436aec4ad19ee9f71c4918fcac712168b84d Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Fri, 24 Apr 2015 17:17:24 +0100 Subject: [PATCH 23/49] Fix encoding for Project Generator --- platformio/ide/projectgenerator.py | 3 +-- .../ide/tpls/visualstudio/platformio.vcxproj.filters.tpl | 2 +- platformio/ide/tpls/visualstudio/platformio.vcxproj.tpl | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/platformio/ide/projectgenerator.py b/platformio/ide/projectgenerator.py index 7873d801..f086eabe 100644 --- a/platformio/ide/projectgenerator.py +++ b/platformio/ide/projectgenerator.py @@ -51,8 +51,7 @@ class ProjectGenerator(object): for tpl_path in self.get_tpls(): file_name = basename(tpl_path)[:-4] with open(join(self.project_dir, file_name), "w") as f: - print tpl_path - f.write(self._render_tpl(tpl_path)) + f.write(self._render_tpl(tpl_path).encode("utf8")) def _render_tpl(self, tpl_path): content = "" diff --git a/platformio/ide/tpls/visualstudio/platformio.vcxproj.filters.tpl b/platformio/ide/tpls/visualstudio/platformio.vcxproj.filters.tpl index 87bc92f6..1b4a764e 100644 --- a/platformio/ide/tpls/visualstudio/platformio.vcxproj.filters.tpl +++ b/platformio/ide/tpls/visualstudio/platformio.vcxproj.filters.tpl @@ -26,4 +26,4 @@ Source Files\src - \ No newline at end of file + diff --git a/platformio/ide/tpls/visualstudio/platformio.vcxproj.tpl b/platformio/ide/tpls/visualstudio/platformio.vcxproj.tpl index 4da8da32..54d5be85 100644 --- a/platformio/ide/tpls/visualstudio/platformio.vcxproj.tpl +++ b/platformio/ide/tpls/visualstudio/platformio.vcxproj.tpl @@ -59,4 +59,4 @@ - \ No newline at end of file + From 1033e827c07b55379f2e800058f55f1b94127438 Mon Sep 17 00:00:00 2001 From: Valeriy Koval Date: Mon, 27 Apr 2015 18:27:26 +0300 Subject: [PATCH 24/49] Add example with creating especial platform in documentation --- docs/librarymanager/creating.rst | 115 +++++++++++++++++++++++++++++++ 1 file changed, 115 insertions(+) diff --git a/docs/librarymanager/creating.rst b/docs/librarymanager/creating.rst index 1db24f56..c54b564e 100644 --- a/docs/librarymanager/creating.rst +++ b/docs/librarymanager/creating.rst @@ -134,3 +134,118 @@ The registration requirements: Now, you can :ref:`register ` your library and allow others to :ref:`install ` it. + +Examples +-------- + +Create :ref:`platform_ststm32` based platform which uses GDB for uploading + +First of all, we need to create new folder ``platforms`` :ref:`projectconf_pio_home_dir` and copy there two files: + +1. Platform manifest file ``ststm32gdb.py`` with the next content: + +.. code-block:: python + + import os + + from platformio.platforms.ststm32 import Ststm32Platform + + + class Ststm32gdbPlatform(Ststm32Platform): + + """ + ST STM32 using GDB as uploader + + http://www.st.com/web/en/catalog/mmc/FM141/SC1169?sc=stm32 + """ + + def get_build_script(self): + + return os.path.join( + os.path.dirname(os.path.realpath(__file__)), + "ststm32gdb-builder.py" + ) + +2. Build script file ``ststm32gdb-builder.py`` with the next content: + +.. code-block:: python + + """ + Builder for ST STM32 Series ARM microcontrollers with GDB upload. + """ + + from os.path import join + + from SCons.Script import (COMMAND_LINE_TARGETS, AlwaysBuild, Default, + DefaultEnvironment, SConscript) + + + env = DefaultEnvironment() + + SConscript(env.subst(join("$PIOBUILDER_DIR", "scripts", "basearm.py"))) + + env.Replace( + UPLOADER=join( + "$PIOPACKAGES_DIR", "toolchain-gccarmnoneeabi", + "bin", "arm-none-eabi-gdb" + ), + UPLOADERFLAGS=[ + join("$BUILD_DIR", "firmware.elf"), + "-batch", + "-x", join("$PROJECT_DIR", "upload.gdb") + ], + + UPLOADCMD="$UPLOADER $UPLOADERFLAGS" + ) + + env.Append( + CPPDEFINES=[ + "${BOARD_OPTIONS['build']['variant'].upper()}" + ], + + LINKFLAGS=[ + "-nostartfiles", + "-nostdlib" + ] + ) + + # + # Target: Build executable and linkable firmware + # + + target_elf = env.BuildFirmware() + + # + # Target: Build the .bin file + # + + if "uploadlazy" in COMMAND_LINE_TARGETS: + target_firm = join("$BUILD_DIR", "firmware.bin") + else: + target_firm = env.ElfToBin(join("$BUILD_DIR", "firmware"), target_elf) + + # + # Target: Print binary size + # + + target_size = env.Alias("size", target_elf, "$SIZEPRINTCMD") + AlwaysBuild(target_size) + + # + # Target: Upload by default .bin file + # + + upload = env.Alias( + ["upload", "uploadlazy"], target_firm, "$UPLOADCMD") + AlwaysBuild(upload) + + # + # Target: Define targets + # + + Default([target_firm, target_size]) + +You should see ststm32gdb platform in ``platformio search`` command output. +Now, you can install new platform via :ref:`platformio install ststm32gdb ` command. + +For more detailed information how to use this platform please follow to `issue 175 `_ From 49bd13adc4ab51636744e613179328313acfcf61 Mon Sep 17 00:00:00 2001 From: Valeriy Koval Date: Mon, 27 Apr 2015 20:25:47 +0300 Subject: [PATCH 25/49] Move documentation example with creating especial platform to right place. --- docs/librarymanager/creating.rst | 114 -------------------------- docs/platforms/creating_platform.rst | 115 +++++++++++++++++++++++++++ 2 files changed, 115 insertions(+), 114 deletions(-) diff --git a/docs/librarymanager/creating.rst b/docs/librarymanager/creating.rst index c54b564e..88011f12 100644 --- a/docs/librarymanager/creating.rst +++ b/docs/librarymanager/creating.rst @@ -135,117 +135,3 @@ The registration requirements: Now, you can :ref:`register ` your library and allow others to :ref:`install ` it. -Examples --------- - -Create :ref:`platform_ststm32` based platform which uses GDB for uploading - -First of all, we need to create new folder ``platforms`` :ref:`projectconf_pio_home_dir` and copy there two files: - -1. Platform manifest file ``ststm32gdb.py`` with the next content: - -.. code-block:: python - - import os - - from platformio.platforms.ststm32 import Ststm32Platform - - - class Ststm32gdbPlatform(Ststm32Platform): - - """ - ST STM32 using GDB as uploader - - http://www.st.com/web/en/catalog/mmc/FM141/SC1169?sc=stm32 - """ - - def get_build_script(self): - - return os.path.join( - os.path.dirname(os.path.realpath(__file__)), - "ststm32gdb-builder.py" - ) - -2. Build script file ``ststm32gdb-builder.py`` with the next content: - -.. code-block:: python - - """ - Builder for ST STM32 Series ARM microcontrollers with GDB upload. - """ - - from os.path import join - - from SCons.Script import (COMMAND_LINE_TARGETS, AlwaysBuild, Default, - DefaultEnvironment, SConscript) - - - env = DefaultEnvironment() - - SConscript(env.subst(join("$PIOBUILDER_DIR", "scripts", "basearm.py"))) - - env.Replace( - UPLOADER=join( - "$PIOPACKAGES_DIR", "toolchain-gccarmnoneeabi", - "bin", "arm-none-eabi-gdb" - ), - UPLOADERFLAGS=[ - join("$BUILD_DIR", "firmware.elf"), - "-batch", - "-x", join("$PROJECT_DIR", "upload.gdb") - ], - - UPLOADCMD="$UPLOADER $UPLOADERFLAGS" - ) - - env.Append( - CPPDEFINES=[ - "${BOARD_OPTIONS['build']['variant'].upper()}" - ], - - LINKFLAGS=[ - "-nostartfiles", - "-nostdlib" - ] - ) - - # - # Target: Build executable and linkable firmware - # - - target_elf = env.BuildFirmware() - - # - # Target: Build the .bin file - # - - if "uploadlazy" in COMMAND_LINE_TARGETS: - target_firm = join("$BUILD_DIR", "firmware.bin") - else: - target_firm = env.ElfToBin(join("$BUILD_DIR", "firmware"), target_elf) - - # - # Target: Print binary size - # - - target_size = env.Alias("size", target_elf, "$SIZEPRINTCMD") - AlwaysBuild(target_size) - - # - # Target: Upload by default .bin file - # - - upload = env.Alias( - ["upload", "uploadlazy"], target_firm, "$UPLOADCMD") - AlwaysBuild(upload) - - # - # Target: Define targets - # - - Default([target_firm, target_size]) - -You should see ststm32gdb platform in ``platformio search`` command output. -Now, you can install new platform via :ref:`platformio install ststm32gdb ` command. - -For more detailed information how to use this platform please follow to `issue 175 `_ diff --git a/docs/platforms/creating_platform.rst b/docs/platforms/creating_platform.rst index 811a4038..1bb556cb 100644 --- a/docs/platforms/creating_platform.rst +++ b/docs/platforms/creating_platform.rst @@ -300,3 +300,118 @@ Installation Now, you can use ``test`` for the :ref:`projectconf_env_platform` option in :ref:`projectconf`. + +Examples +-------- + +Create :ref:`platform_ststm32` based platform which uses GDB for uploading + +First of all, we need to create new folder ``platforms`` :ref:`projectconf_pio_home_dir` and copy there two files: + +1. Platform manifest file ``ststm32gdb.py`` with the next content: + +.. code-block:: python + + import os + + from platformio.platforms.ststm32 import Ststm32Platform + + + class Ststm32gdbPlatform(Ststm32Platform): + + """ + ST STM32 using GDB as uploader + + http://www.st.com/web/en/catalog/mmc/FM141/SC1169?sc=stm32 + """ + + def get_build_script(self): + + return os.path.join( + os.path.dirname(os.path.realpath(__file__)), + "ststm32gdb-builder.py" + ) + +2. Build script file ``ststm32gdb-builder.py`` with the next content: + +.. code-block:: python + + """ + Builder for ST STM32 Series ARM microcontrollers with GDB upload. + """ + + from os.path import join + + from SCons.Script import (COMMAND_LINE_TARGETS, AlwaysBuild, Default, + DefaultEnvironment, SConscript) + + + env = DefaultEnvironment() + + SConscript(env.subst(join("$PIOBUILDER_DIR", "scripts", "basearm.py"))) + + env.Replace( + UPLOADER=join( + "$PIOPACKAGES_DIR", "toolchain-gccarmnoneeabi", + "bin", "arm-none-eabi-gdb" + ), + UPLOADERFLAGS=[ + join("$BUILD_DIR", "firmware.elf"), + "-batch", + "-x", join("$PROJECT_DIR", "upload.gdb") + ], + + UPLOADCMD="$UPLOADER $UPLOADERFLAGS" + ) + + env.Append( + CPPDEFINES=[ + "${BOARD_OPTIONS['build']['variant'].upper()}" + ], + + LINKFLAGS=[ + "-nostartfiles", + "-nostdlib" + ] + ) + + # + # Target: Build executable and linkable firmware + # + + target_elf = env.BuildFirmware() + + # + # Target: Build the .bin file + # + + if "uploadlazy" in COMMAND_LINE_TARGETS: + target_firm = join("$BUILD_DIR", "firmware.bin") + else: + target_firm = env.ElfToBin(join("$BUILD_DIR", "firmware"), target_elf) + + # + # Target: Print binary size + # + + target_size = env.Alias("size", target_elf, "$SIZEPRINTCMD") + AlwaysBuild(target_size) + + # + # Target: Upload by default .bin file + # + + upload = env.Alias( + ["upload", "uploadlazy"], target_firm, "$UPLOADCMD") + AlwaysBuild(upload) + + # + # Target: Define targets + # + + Default([target_firm, target_size]) + +You should see ``ststm32gdb`` platform in :ref:`platformio search ` command output. +Now, you can install new platform via :ref:`platformio install ststm32gdb ` command. + +For more detailed information how to use this platform please follow to `issue 175 `_ From bdcf89bf32f953cffb0c958919a357b4319345a0 Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Mon, 27 Apr 2015 18:48:16 +0100 Subject: [PATCH 26/49] Correct spelling in Creating platform example --- docs/platforms/creating_platform.rst | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/docs/platforms/creating_platform.rst b/docs/platforms/creating_platform.rst index 1bb556cb..1c5c0505 100644 --- a/docs/platforms/creating_platform.rst +++ b/docs/platforms/creating_platform.rst @@ -301,12 +301,14 @@ Installation Now, you can use ``test`` for the :ref:`projectconf_env_platform` option in :ref:`projectconf`. -Examples --------- +Example +------- -Create :ref:`platform_ststm32` based platform which uses GDB for uploading +Let's use the real example which was requested by our user in `issue 175 `_. Need to add support for uploading firmware using GDB to +:ref:`platform_ststm32`. -First of all, we need to create new folder ``platforms`` :ref:`projectconf_pio_home_dir` and copy there two files: +First of all, need to create new folder ``platforms`` in :ref:`projectconf_pio_home_dir` +and copy there two files: 1. Platform manifest file ``ststm32gdb.py`` with the next content: @@ -411,7 +413,5 @@ First of all, we need to create new folder ``platforms`` :ref:`projectconf_pio_h Default([target_firm, target_size]) -You should see ``ststm32gdb`` platform in :ref:`platformio search ` command output. -Now, you can install new platform via :ref:`platformio install ststm32gdb ` command. - -For more detailed information how to use this platform please follow to `issue 175 `_ +Now, we should see ``ststm32gdb`` platform using :ref:`cmd_search` command output +and can install it via :ref:`platformio platforms install ststm32gdb ` command. From 7b80e176644ec20392bae4a18a9495b546e81543 Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Tue, 28 Apr 2015 13:13:17 +0100 Subject: [PATCH 27/49] Improve handling of platforms commands for telemetry --- platformio/telemetry.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platformio/telemetry.py b/platformio/telemetry.py index 55b26f21..87762dbd 100644 --- a/platformio/telemetry.py +++ b/platformio/telemetry.py @@ -96,7 +96,7 @@ class MeasurementProtocol(TelemetryBase): if not args: return - if args[0] in ("lib", "serialports", "settings"): + if args[0] in ("lib", "platforms", "serialports", "settings"): cmd_path = args[:2] else: cmd_path = args[:1] From cd842d5a86398959cd31f38c3f651ac89bf9b445 Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Wed, 29 Apr 2015 18:17:14 +0100 Subject: [PATCH 28/49] Put UserAgent for all http requests --- platformio/commands/upgrade.py | 13 +++++++------ platformio/downloader.py | 12 +++++++----- platformio/telemetry.py | 8 ++++---- platformio/util.py | 13 ++++++++----- 4 files changed, 26 insertions(+), 20 deletions(-) diff --git a/platformio/commands/upgrade.py b/platformio/commands/upgrade.py index 7e57579e..263401de 100644 --- a/platformio/commands/upgrade.py +++ b/platformio/commands/upgrade.py @@ -4,9 +4,8 @@ import click import requests -from platformio import __version__ +from platformio import __version__, util from platformio.exception import GetLatestVersionError -from platformio.util import exec_command @click.command("upgrade", @@ -22,9 +21,9 @@ def cli(): click.secho("Please wait while upgrading PlatformIO ...", fg="yellow") - pip_result = exec_command(["pip", "install", "--upgrade", - "platformio"]) - pio_result = exec_command(["platformio", "--version"]) + pip_result = util.exec_command(["pip", "install", "--upgrade", + "platformio"]) + pio_result = util.exec_command(["platformio", "--version"]) if last in pio_result['out'].strip(): click.secho("PlatformIO has been successfully upgraded to %s" % @@ -37,7 +36,9 @@ def cli(): def get_latest_version(): try: pkgdata = requests.get( - "https://pypi.python.org/pypi/platformio/json").json() + "https://pypi.python.org/pypi/platformio/json", + headers=util.get_request_defheaders() + ).json() return pkgdata['info']['version'] except: raise GetLatestVersionError() diff --git a/platformio/downloader.py b/platformio/downloader.py index df9f5b64..a3aa37f9 100644 --- a/platformio/downloader.py +++ b/platformio/downloader.py @@ -9,9 +9,9 @@ from time import mktime from click import progressbar from requests import get +from platformio import util from platformio.exception import (FDSHASumMismatch, FDSizeMismatch, FDUnrecognizedStatusCode) -from platformio.util import change_filemtime, exec_command class FileDownloader(object): @@ -27,7 +27,8 @@ class FileDownloader(object): self.set_destination(join(dest_dir, self._fname)) self._progressbar = None - self._request = get(url, stream=True) + self._request = get(url, stream=True, + headers=util.get_request_defheaders()) if self._request.status_code != 200: raise FDUnrecognizedStatusCode(self._request.status_code, url) @@ -66,11 +67,12 @@ class FileDownloader(object): dlsha1 = None try: - result = exec_command(["sha1sum", self._destination]) + result = util.exec_command(["sha1sum", self._destination]) dlsha1 = result['out'] except OSError: try: - result = exec_command(["shasum", "-a", "1", self._destination]) + result = util.exec_command( + ["shasum", "-a", "1", self._destination]) dlsha1 = result['out'] except OSError: pass @@ -83,7 +85,7 @@ class FileDownloader(object): def _preserve_filemtime(self, lmdate): timedata = parsedate_tz(lmdate) lmtime = mktime(timedata[:9]) - change_filemtime(self._destination, lmtime) + util.change_filemtime(self._destination, lmtime) def __del__(self): self._request.close() diff --git a/platformio/telemetry.py b/platformio/telemetry.py index 87762dbd..3662b7f4 100644 --- a/platformio/telemetry.py +++ b/platformio/telemetry.py @@ -12,8 +12,7 @@ from time import time import click import requests -from platformio import __version__, app -from platformio.util import exec_command, get_systype +from platformio import __version__, app, util class TelemetryBase(object): @@ -77,7 +76,7 @@ class MeasurementProtocol(TelemetryBase): dpdata.append("Click/%s" % click.__version__) # dpdata.append("Requests/%s" % requests.__version__) try: - result = exec_command(["scons", "--version"]) + result = util.exec_command(["scons", "--version"]) match = re.search(r"engine: v([\d\.]+)", result['out']) if match: dpdata.append("SCons/%s" % match.group(1)) @@ -86,7 +85,7 @@ class MeasurementProtocol(TelemetryBase): self['an'] = " ".join(dpdata) def _prefill_custom_data(self): - self['cd1'] = get_systype() + self['cd1'] = util.get_systype() self['cd2'] = "Python/%s %s" % (platform.python_version(), platform.platform()) self['cd4'] = 1 if app.get_setting("enable_prompts") else 0 @@ -155,6 +154,7 @@ class MPDataPusher(threading.Thread): r = self.http_session().post( "https://ssl.google-analytics.com/collect", data=data, + headers=util.get_request_defheaders(), timeout=3 ) r.raise_for_status() diff --git a/platformio/util.py b/platformio/util.py index a4faf4ca..806225fc 100644 --- a/platformio/util.py +++ b/platformio/util.py @@ -242,19 +242,22 @@ def get_logicaldisks(): return disks +def get_request_defheaders(): + return {"User-Agent": "PlatformIO/%s %s" % ( + __version__, requests.utils.default_user_agent())} + + def get_api_result(path, params=None, data=None): result = None r = None try: - headers = {"User-Agent": "PlatformIO/%s %s" % ( - __version__, requests.utils.default_user_agent())} - if data: r = requests.post(__apiurl__ + path, params=params, data=data, - headers=headers) + headers=get_request_defheaders()) else: - r = requests.get(__apiurl__ + path, params=params, headers=headers) + r = requests.get(__apiurl__ + path, params=params, + headers=get_request_defheaders()) result = r.json() r.raise_for_status() except requests.exceptions.HTTPError as e: From 47903a7ac9765e1fdd8ed84142d8f8cba9a44bb6 Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Thu, 30 Apr 2015 14:14:57 +0100 Subject: [PATCH 29/49] Update User Guide documentation for PlatformIO 2.0 // Issue #158 --- docs/platforms/creating_platform.rst | 8 +- docs/userguide/cmd_update.rst | 3 +- docs/userguide/index.rst | 6 +- .../userguide/{ => platforms}/cmd_install.rst | 12 +-- docs/userguide/{ => platforms}/cmd_list.rst | 10 +- docs/userguide/{ => platforms}/cmd_search.rst | 14 +-- docs/userguide/{ => platforms}/cmd_show.rst | 10 +- .../{ => platforms}/cmd_uninstall.rst | 10 +- docs/userguide/platforms/cmd_update.rst | 99 +++++++++++++++++++ docs/userguide/platforms/index.rst | 22 +++++ 10 files changed, 156 insertions(+), 38 deletions(-) rename docs/userguide/{ => platforms}/cmd_install.rst (84%) rename docs/userguide/{ => platforms}/cmd_list.rst (89%) rename docs/userguide/{ => platforms}/cmd_search.rst (94%) rename docs/userguide/{ => platforms}/cmd_show.rst (81%) rename docs/userguide/{ => platforms}/cmd_uninstall.rst (69%) create mode 100644 docs/userguide/platforms/cmd_update.rst create mode 100644 docs/userguide/platforms/index.rst diff --git a/docs/platforms/creating_platform.rst b/docs/platforms/creating_platform.rst index 1c5c0505..656c6497 100644 --- a/docs/platforms/creating_platform.rst +++ b/docs/platforms/creating_platform.rst @@ -294,9 +294,9 @@ Installation 1. Create ``platforms`` directory in :ref:`projectconf_pio_home_dir` if it doesn't exists. 2. Copy ``test.py`` and ``test-builder.py`` files to ``platforms`` directory. -3. Search available platforms via :ref:`cmd_search` command. You should see +3. Search available platforms via :ref:`cmd_platforms_search` command. You should see ``test`` platform. -4. Install ``test`` platform via :ref:`cmd_install` command. +4. Install ``test`` platform via :ref:`cmd_platforms_install` command. Now, you can use ``test`` for the :ref:`projectconf_env_platform` option in :ref:`projectconf`. @@ -413,5 +413,5 @@ and copy there two files: Default([target_firm, target_size]) -Now, we should see ``ststm32gdb`` platform using :ref:`cmd_search` command output -and can install it via :ref:`platformio platforms install ststm32gdb ` command. +Now, we should see ``ststm32gdb`` platform using :ref:`cmd_platforms_search` command output +and can install it via :ref:`platformio platforms install ststm32gdb ` command. diff --git a/docs/userguide/cmd_update.rst b/docs/userguide/cmd_update.rst index b01cf9b4..60609fe2 100644 --- a/docs/userguide/cmd_update.rst +++ b/docs/userguide/cmd_update.rst @@ -16,7 +16,8 @@ Usage Description ----------- -Check or update installed :ref:`Platforms ` +Check or update installed :ref:`Platforms ` and +:ref:`Libraries ` Examples diff --git a/docs/userguide/index.rst b/docs/userguide/index.rst index a2db09ce..7d91e152 100644 --- a/docs/userguide/index.rst +++ b/docs/userguide/index.rst @@ -16,14 +16,10 @@ To print all available commands and options use: cmd_boards cmd_init - cmd_install platformio lib - cmd_list + platformio platforms cmd_run - cmd_search cmd_serialports cmd_settings - cmd_show - cmd_uninstall cmd_update cmd_upgrade diff --git a/docs/userguide/cmd_install.rst b/docs/userguide/platforms/cmd_install.rst similarity index 84% rename from docs/userguide/cmd_install.rst rename to docs/userguide/platforms/cmd_install.rst index 33557ca6..6f7dc8a8 100644 --- a/docs/userguide/cmd_install.rst +++ b/docs/userguide/platforms/cmd_install.rst @@ -1,7 +1,7 @@ -.. _cmd_install: +.. _cmd_platforms_install: -platformio install -================== +platformio platforms install +============================ .. contents:: @@ -10,7 +10,7 @@ Usage .. code-block:: bash - platformio install [OPTIONS] [PLATFORMS] + platformio platforms install [OPTIONS] [PLATFORMS] Description @@ -50,7 +50,7 @@ Examples .. code-block:: bash - $ platformio install timsp430 + $ platformio platforms install timsp430 Installing toolchain-timsp430 package: Downloading [####################################] 100% Unpacking [####################################] 100% @@ -68,7 +68,7 @@ Examples .. code-block:: bash - $ platformio install timsp430 --skip-default-package --with-package=uploader + $ platformio platforms install timsp430 --skip-default-package --with-package=uploader Installing tool-mspdebug package: Downloading [####################################] 100% Unpacking [####################################] 100% diff --git a/docs/userguide/cmd_list.rst b/docs/userguide/platforms/cmd_list.rst similarity index 89% rename from docs/userguide/cmd_list.rst rename to docs/userguide/platforms/cmd_list.rst index 1bc6b745..594defe6 100644 --- a/docs/userguide/cmd_list.rst +++ b/docs/userguide/platforms/cmd_list.rst @@ -1,7 +1,7 @@ -.. _cmd_list: +.. _cmd_platforms_list: -platformio list -=============== +platformio platforms list +========================= .. contents:: @@ -10,7 +10,7 @@ Usage .. code-block:: bash - platformio list [OPTIONS] + platformio platforms list [OPTIONS] Description @@ -31,7 +31,7 @@ Examples .. code-block:: bash - $ platformio list + $ platformio platforms list atmelavr with packages: toolchain-atmelavr, tool-avrdude, framework-arduinoavr, tool-micronucleus atmelsam with packages: framework-arduinosam, ldscripts, toolchain-gccarmnoneeabi, tool-bossac freescalekinetis with packages: framework-mbed, toolchain-gccarmnoneeabi diff --git a/docs/userguide/cmd_search.rst b/docs/userguide/platforms/cmd_search.rst similarity index 94% rename from docs/userguide/cmd_search.rst rename to docs/userguide/platforms/cmd_search.rst index 304c7fc6..b77bed41 100644 --- a/docs/userguide/cmd_search.rst +++ b/docs/userguide/platforms/cmd_search.rst @@ -1,7 +1,7 @@ -.. _cmd_search: +.. _cmd_platforms_search: -platformio search -================= +platformio platforms search +=========================== .. contents:: @@ -10,7 +10,7 @@ Usage .. code-block:: bash - platformio search QUERY [OPTIONS] + platformio platforms search QUERY [OPTIONS] Description @@ -34,7 +34,7 @@ Examples .. code-block:: bash - $ platformio search + $ platformio platforms search atmelavr (available packages: ldscripts, toolchain-gccarmnoneeabi, tool-lm4flash, framework-opencm3, framework-energiativa) -------- Atmel AVR 8- and 32-bit MCUs deliver a unique combination of performance... @@ -75,7 +75,7 @@ Examples .. code-block:: bash - $ platformio search ti + $ platformio platforms search ti timsp430 (available packages: ldscripts, toolchain-gccarmnoneeabi, tool-lm4flash, framework-opencm3, framework-energiativa) -------- MSP430 microcontrollers (MCUs) from Texas Instruments (TI) are ... @@ -88,7 +88,7 @@ Examples .. code-block:: bash - $ platformio search mbed + $ platformio platforms search mbed freescalekinetis (available packages: ldscripts, toolchain-gccarmnoneeabi, tool-lm4flash, framework-opencm3, framework-energiativa) ---------------- Freescale Kinetis Microcontrollers is family of multiple hardware- and ... diff --git a/docs/userguide/cmd_show.rst b/docs/userguide/platforms/cmd_show.rst similarity index 81% rename from docs/userguide/cmd_show.rst rename to docs/userguide/platforms/cmd_show.rst index c109117f..1948b4f2 100644 --- a/docs/userguide/cmd_show.rst +++ b/docs/userguide/platforms/cmd_show.rst @@ -1,7 +1,7 @@ -.. _cmd_show: +.. _cmd_platforms_show: -platformio show -=============== +platformio platforms show +========================= .. contents:: @@ -10,7 +10,7 @@ Usage .. code-block:: bash - platformio show PLATFORM + platformio platforms show PLATFORM Description @@ -24,7 +24,7 @@ Examples .. code-block:: bash - $ platformio show atmelavr + $ platformio platforms show atmelavr atmelavr - An embedded platform for Atmel AVR microcontrollers (with Arduino Framework) ---------- Package: toolchain-atmelavr diff --git a/docs/userguide/cmd_uninstall.rst b/docs/userguide/platforms/cmd_uninstall.rst similarity index 69% rename from docs/userguide/cmd_uninstall.rst rename to docs/userguide/platforms/cmd_uninstall.rst index ef6348f1..a7e307f9 100644 --- a/docs/userguide/cmd_uninstall.rst +++ b/docs/userguide/platforms/cmd_uninstall.rst @@ -1,7 +1,7 @@ -.. _cmd_uninstall: +.. _cmd_platforms_uninstall: -platformio uninstall -==================== +platformio platforms uninstall +============================== .. contents:: @@ -10,7 +10,7 @@ Usage .. code-block:: bash - platformio uninstall PLATFORM + platformio platforms uninstall PLATFORM Description @@ -24,7 +24,7 @@ Examples .. code-block:: bash - $ platformio uninstall timsp430 + $ platformio platforms uninstall timsp430 Uninstalling toolchain-timsp430 package: [OK] Uninstalling tool-mspdebug package: [OK] Uninstalling framework-energiamsp430 package: [OK] diff --git a/docs/userguide/platforms/cmd_update.rst b/docs/userguide/platforms/cmd_update.rst new file mode 100644 index 00000000..398d9527 --- /dev/null +++ b/docs/userguide/platforms/cmd_update.rst @@ -0,0 +1,99 @@ +.. _cmd_platforms_update: + +platformio platforms update +=========================== + +.. contents:: + +Usage +----- + +.. code-block:: bash + + platformio platforms update + + +Description +----------- + +Check or update installed :ref:`Platforms ` + + +Examples +-------- + +.. code-block:: bash + + $ platformio platforms update + + Platform atmelavr + -------- + Updating toolchain-atmelavr package: + Versions: Current=1, Latest=1 [Up-to-date] + Updating tool-avrdude package: + Versions: Current=2, Latest=2 [Up-to-date] + Updating framework-arduinoavr package: + Versions: Current=12, Latest=12 [Up-to-date] + Updating tool-micronucleus package: + Versions: Current=1, Latest=1 [Up-to-date] + + Platform atmelsam + -------- + Updating framework-arduinosam package: + Versions: Current=3, Latest=3 [Up-to-date] + Updating ldscripts package: + Versions: Current=1, Latest=1 [Up-to-date] + Updating toolchain-gccarmnoneeabi package: + Versions: Current=1, Latest=1 [Up-to-date] + Updating tool-bossac package: + Versions: Current=1, Latest=1 [Up-to-date] + + Platform stm32 + -------- + Updating toolchain-gccarmnoneeabi package: + Versions: Current=1, Latest=1 [Up-to-date] + Updating tool-stlink package: + Versions: Current=1, Latest=1 [Up-to-date] + Updating framework-spl package: + Versions: Current=1, Latest=1 [Up-to-date] + Updating framework-cmsis package: + Versions: Current=2, Latest=2 [Up-to-date] + Updating framework-opencm3 package: + Versions: Current=1, Latest=1 [Up-to-date] + Updating ldscripts package: + Versions: Current=1, Latest=1 [Up-to-date] + + Platform teensy + -------- + Updating toolchain-atmelavr package: + Versions: Current=1, Latest=1 [Up-to-date] + Updating ldscripts package: + Versions: Current=1, Latest=1 [Up-to-date] + Updating framework-arduinoteensy package: + Versions: Current=1, Latest=1 [Up-to-date] + Updating toolchain-gccarmnoneeabi package: + Versions: Current=1, Latest=1 [Up-to-date] + Updating tool-teensy package: + Versions: Current=1, Latest=1 [Up-to-date] + + Platform timsp430 + -------- + Updating toolchain-timsp430 package: + Versions: Current=1, Latest=1 [Up-to-date] + Updating tool-mspdebug package: + Versions: Current=1, Latest=1 [Up-to-date] + Updating framework-energiamsp430 package: + Versions: Current=2, Latest=2 [Up-to-date] + + Platform titiva + -------- + Updating ldscripts package: + Versions: Current=1, Latest=1 [Up-to-date] + Updating toolchain-gccarmnoneeabi package: + Versions: Current=1, Latest=1 [Up-to-date] + Updating tool-lm4flash package: + Versions: Current=1, Latest=1 [Up-to-date] + Updating framework-opencm3 package: + Versions: Current=1, Latest=1 [Up-to-date] + Updating framework-energiativa package: + Versions: Current=4, Latest=4 [Up-to-date] diff --git a/docs/userguide/platforms/index.rst b/docs/userguide/platforms/index.rst new file mode 100644 index 00000000..7a582752 --- /dev/null +++ b/docs/userguide/platforms/index.rst @@ -0,0 +1,22 @@ +.. _userguide_platforms: + +Platforms Manager +================= + +To print all available commands and options use: + +.. code-block:: bash + + $ platformio platforms --help + $ platformio platforms COMMAND --help + + +.. toctree:: + :maxdepth: 2 + + cmd_install + cmd_list + cmd_search + cmd_show + cmd_uninstall + cmd_update From 6967e936a6d3b72a35a09054f6832bbbd384316a Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Fri, 1 May 2015 12:06:34 +0100 Subject: [PATCH 30/49] Fix CPPFLAGS example for build flags --- docs/projectconf.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/projectconf.rst b/docs/projectconf.rst index df508ed5..b33f0ea7 100644 --- a/docs/projectconf.rst +++ b/docs/projectconf.rst @@ -226,7 +226,7 @@ processes: * - Format - Scope - Description - * - ``Wp,option`` + * - ``-Wp,option`` - CPPFLAGS - Bypass the compiler driver and pass *option* directly through to the preprocessor From ab9a7e05c8a528900f4669956ed580f1c98cc9a9 Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Fri, 1 May 2015 12:54:45 +0100 Subject: [PATCH 31/49] Use "lib_dir" by default for LibraryManager --- platformio/commands/lib.py | 12 ++++++------ platformio/libmanager.py | 6 +++--- platformio/maintenance.py | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/platformio/commands/lib.py b/platformio/commands/lib.py index f90ce614..7bf31383 100644 --- a/platformio/commands/lib.py +++ b/platformio/commands/lib.py @@ -7,7 +7,7 @@ import click from platformio import app, exception from platformio.libmanager import LibraryManager -from platformio.util import get_api_result, get_lib_dir +from platformio.util import get_api_result LIBLIST_TPL = ("[{id:^14}] {name:<25} {compatibility:<30} " "\"{authornames}\": {description}") @@ -100,7 +100,7 @@ def lib_search(query, **filters): @click.option("-v", "--version") @click.pass_context def lib_install(ctx, libid, version): - lm = LibraryManager(get_lib_dir()) + lm = LibraryManager() for id_ in libid: click.echo( "Installing library [ %s ]:" % click.style(str(id_), fg="green")) @@ -149,7 +149,7 @@ def lib_install_dependency(ctx, data): @cli.command("uninstall", short_help="Uninstall libraries") @click.argument("libid", type=click.INT, nargs=-1) def lib_uninstall(libid): - lm = LibraryManager(get_lib_dir()) + lm = LibraryManager() for id_ in libid: info = lm.get_info(id_) if lm.uninstall(id_): @@ -160,7 +160,7 @@ def lib_uninstall(libid): @cli.command("list", short_help="List installed libraries") @click.option("--json-output", is_flag=True) def lib_list(json_output): - lm = LibraryManager(get_lib_dir()) + lm = LibraryManager() items = lm.get_installed().values() if json_output: @@ -179,7 +179,7 @@ def lib_list(json_output): @cli.command("show", short_help="Show details about installed library") @click.argument("libid", type=click.INT) def lib_show(libid): - lm = LibraryManager(get_lib_dir()) + lm = LibraryManager() info = lm.get_info(libid) click.secho(info['name'], fg="cyan") click.echo("-" * len(info['name'])) @@ -215,7 +215,7 @@ def lib_show(libid): metavar="[LIBRARY_ID]") @click.pass_context def lib_update(ctx, libid): - lm = LibraryManager(get_lib_dir()) + lm = LibraryManager() for id_, latest_version in (lm.get_latest_versions() or {}).items(): if libid and int(id_) not in libid: continue diff --git a/platformio/libmanager.py b/platformio/libmanager.py index ae577d15..72d9665c 100644 --- a/platformio/libmanager.py +++ b/platformio/libmanager.py @@ -12,15 +12,15 @@ from platformio import telemetry from platformio.downloader import FileDownloader from platformio.exception import LibAlreadyInstalledError, LibNotInstalledError from platformio.unpacker import FileUnpacker -from platformio.util import get_api_result +from platformio.util import get_api_result, get_lib_dir class LibraryManager(object): CONFIG_NAME = ".library.json" - def __init__(self, lib_dir): - self.lib_dir = lib_dir + def __init__(self, lib_dir=None): + self.lib_dir = lib_dir or get_lib_dir() @staticmethod def download(url, dest_dir): diff --git a/platformio/maintenance.py b/platformio/maintenance.py index a44f454f..b67824b9 100644 --- a/platformio/maintenance.py +++ b/platformio/maintenance.py @@ -203,7 +203,7 @@ def check_internal_updates(ctx, what): if p.is_outdated(): outdated_items.append(platform) elif what == "libraries": - lm = LibraryManager(get_lib_dir()) + lm = LibraryManager() outdated_items = lm.get_outdated() if not outdated_items: From 0a474d34d8537c566fa3d7223b0deafc3d0ad29a Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Fri, 1 May 2015 13:00:33 +0100 Subject: [PATCH 32/49] Cache get_installed_libs result --- platformio/libmanager.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/platformio/libmanager.py b/platformio/libmanager.py index 72d9665c..40f015ff 100644 --- a/platformio/libmanager.py +++ b/platformio/libmanager.py @@ -8,11 +8,10 @@ from os.path import isdir, isfile, join from shutil import rmtree from tempfile import gettempdir -from platformio import telemetry +from platformio import telemetry, util from platformio.downloader import FileDownloader from platformio.exception import LibAlreadyInstalledError, LibNotInstalledError from platformio.unpacker import FileUnpacker -from platformio.util import get_api_result, get_lib_dir class LibraryManager(object): @@ -20,7 +19,7 @@ class LibraryManager(object): CONFIG_NAME = ".library.json" def __init__(self, lib_dir=None): - self.lib_dir = lib_dir or get_lib_dir() + self.lib_dir = lib_dir or util.get_lib_dir() @staticmethod def download(url, dest_dir): @@ -33,6 +32,7 @@ class LibraryManager(object): fu = FileUnpacker(pkgpath, dest_dir) return fu.start() + @util.memoized def get_installed(self): items = {} if not isdir(self.lib_dir): @@ -49,7 +49,7 @@ class LibraryManager(object): lib_ids = [str(item['id']) for item in self.get_installed().values()] if not lib_ids: return None - return get_api_result("/lib/version/" + str(",".join(lib_ids))) + return util.get_api_result("/lib/version/" + str(",".join(lib_ids))) def get_outdated(self): outdated = [] @@ -75,8 +75,10 @@ class LibraryManager(object): if self.is_installed(id_): raise LibAlreadyInstalledError() - dlinfo = get_api_result("/lib/download/" + str(id_), - dict(version=version) if version else None) + dlinfo = util.get_api_result( + "/lib/download/" + str(id_), + dict(version=version) if version else None + ) dlpath = None tmplib_dir = join(self.lib_dir, str(id_)) try: From 7391dfa93691e3dfd8b5dd7cbd38edf9d6be5823 Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Fri, 1 May 2015 13:48:06 +0100 Subject: [PATCH 33/49] Fix caching for installed platforms and libraries --- platformio/libmanager.py | 1 - platformio/platforms/base.py | 1 - 2 files changed, 2 deletions(-) diff --git a/platformio/libmanager.py b/platformio/libmanager.py index 40f015ff..0dfd220d 100644 --- a/platformio/libmanager.py +++ b/platformio/libmanager.py @@ -32,7 +32,6 @@ class LibraryManager(object): fu = FileUnpacker(pkgpath, dest_dir) return fu.start() - @util.memoized def get_installed(self): items = {} if not isdir(self.lib_dir): diff --git a/platformio/platforms/base.py b/platformio/platforms/base.py index d91118ec..e1bcc20f 100644 --- a/platformio/platforms/base.py +++ b/platformio/platforms/base.py @@ -132,7 +132,6 @@ class PlatformFactory(object): return module @classmethod - @util.memoized def _lookup_platforms(cls): platforms = {} for d in (util.get_home_dir(), util.get_source_dir()): From 424e87a811f774e8c622dfec49b947849fe95501 Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Fri, 1 May 2015 13:49:18 +0100 Subject: [PATCH 34/49] Add library dependencies using "install_libs" option in platformio.ini // Resolve #134 --- HISTORY.rst | 3 +++ docs/projectconf.rst | 16 ++++++++++++++++ platformio/commands/run.py | 32 ++++++++++++++++++++++++++++++-- 3 files changed, 49 insertions(+), 2 deletions(-) diff --git a/HISTORY.rst b/HISTORY.rst index b765373a..2cf461a3 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -11,6 +11,9 @@ Release History (`issue #174 `_) * Added global ``-f, --force`` option which will force to accept any confirmation prompts (`issue #152 `_) +* Added library dependencies using ``install_libs`` option in + `platformio.ini `__ + (`issue #134 `_) * Allowed to add more boards to existing `platformio.ini `__ (`issue #167 `_) diff --git a/docs/projectconf.rst b/docs/projectconf.rst index b33f0ea7..5242e3aa 100644 --- a/docs/projectconf.rst +++ b/docs/projectconf.rst @@ -309,6 +309,22 @@ but will be applied only for the project source code from This option can be overridden by global environment variable :ref:`envvar_PLATFORMIO_SRCBUILD_FLAGS`. +``install_libs`` +^^^^^^^^^^^^^^^^ + +Specify dependent libraries which should be installed before environment +process. The only library IDs are allowed. Multiple libraries can be passed +using comma ``,`` sign. + +You can obtain library IDs using :ref:`cmd_lib_search` command. + +Example: + +.. code-block:: ini + + [env:depends_on_some_libs] + install_libs = 1,13,19 + ``ignore_libs`` ^^^^^^^^^^^^^^^ diff --git a/platformio/commands/run.py b/platformio/commands/run.py index 8d3d792f..0a49d513 100644 --- a/platformio/commands/run.py +++ b/platformio/commands/run.py @@ -9,8 +9,10 @@ from time import time import click from platformio import app, exception, telemetry, util +from platformio.commands.lib import lib_install as cmd_lib_install from platformio.commands.platforms import \ platforms_install as cmd_platforms_install +from platformio.libmanager import LibraryManager from platformio.platforms.base import PlatformFactory @@ -115,6 +117,16 @@ def _run_environment(ctx, name, options, targets, upload_port): telemetry.on_run_environment(options, envtargets) + # install platform and libs dependencies + _autoinstall_env_platform(ctx, platform) + if "install_libs" in options: + _autoinstall_env_libs(ctx, options['install_libs']) + + p = PlatformFactory.newPlatform(platform) + return p.run(variables, envtargets) + + +def _autoinstall_env_platform(ctx, platform): installed_platforms = PlatformFactory.get_platforms( installed=True).keys() if (platform not in installed_platforms and ( @@ -123,5 +135,21 @@ def _run_environment(ctx, name, options, targets, upload_port): "Would you like to install it now?" % platform))): ctx.invoke(cmd_platforms_install, platforms=[platform]) - p = PlatformFactory.newPlatform(platform) - return p.run(variables, envtargets) + +def _autoinstall_env_libs(ctx, libids_list): + require_libs = [int(l.strip()) for l in libids_list.split(",")] + installed_libs = [ + l['id'] for l in LibraryManager().get_installed().values() + ] + + not_intalled_libs = set(require_libs) - set(installed_libs) + if not require_libs or not not_intalled_libs: + return + + if (not app.get_setting("enable_prompts") or + click.confirm( + "The libraries with IDs '%s' have not been installed yet. " + "Would you like to install them now?" % + ", ".join([str(i) for i in not_intalled_libs]) + )): + ctx.invoke(cmd_lib_install, libid=not_intalled_libs) From 125c7b2aba75fa06ec4797d78a9ea6a5b5abaa13 Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Fri, 1 May 2015 17:51:20 +0100 Subject: [PATCH 35/49] Revert caching for development platforms --- platformio/platforms/base.py | 1 + 1 file changed, 1 insertion(+) diff --git a/platformio/platforms/base.py b/platformio/platforms/base.py index e1bcc20f..d91118ec 100644 --- a/platformio/platforms/base.py +++ b/platformio/platforms/base.py @@ -132,6 +132,7 @@ class PlatformFactory(object): return module @classmethod + @util.memoized def _lookup_platforms(cls): platforms = {} for d in (util.get_home_dir(), util.get_source_dir()): From f001c087ec87e1a6cfc3a711e05ad0d8abd236a0 Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Tue, 5 May 2015 15:47:21 +0100 Subject: [PATCH 36/49] Allow to specify libraries which are compatible with build environment using use_libs option in platformio.ini --- HISTORY.rst | 19 +++++++++++++------ docs/projectconf.rst | 13 +++++++++++++ platformio/__init__.py | 2 +- platformio/builder/main.py | 1 + platformio/builder/tools/platformio.py | 12 +++++++++--- 5 files changed, 37 insertions(+), 10 deletions(-) diff --git a/HISTORY.rst b/HISTORY.rst index 2cf461a3..b5063b09 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -11,11 +11,17 @@ Release History (`issue #174 `_) * Added global ``-f, --force`` option which will force to accept any confirmation prompts (`issue #152 `_) -* Added library dependencies using ``install_libs`` option in - `platformio.ini `__ +* Allowed to add library dependencies for build environment using + `install_libs `_ + option in ``platformio.ini`` (`issue #134 `_) -* Allowed to add more boards to existing - `platformio.ini `__ +* Allowed to specify libraries which are compatible with build environment using + `use_libs `_ + option in ``platformio.ini`` + (`issue #148 `_) +* Allowed to add more boards to PlatformIO project with + `platformio init --board `__ + command (`issue #167 `_) * Allowed to choose which library to update (`issue #168 `_) @@ -45,8 +51,9 @@ Release History 1.6.3 version (`issue #156 `_) * Upgraded `Energia Framework `__ to 0101E0015 version (`issue #146 `_) -* Upgraded `Arduino Framework with Teensy Core `_ to - 1.22 version (`issue #162 `_, +* Upgraded `Arduino Framework with Teensy Core `_ + to 1.22 version + (`issue #162 `_, `issue #170 `_) * Fixed exceptions with PlatformIO auto-updates when Internet connection isn't active diff --git a/docs/projectconf.rst b/docs/projectconf.rst index 5242e3aa..698a8762 100644 --- a/docs/projectconf.rst +++ b/docs/projectconf.rst @@ -325,6 +325,19 @@ Example: [env:depends_on_some_libs] install_libs = 1,13,19 +``use_libs`` +^^^^^^^^^^^^ + +Specify libraries which should be used by ``Library Dependency Finder`` with +the highest priority. + +Example: + +.. code-block:: ini + + [env:libs_with_highest_priority] + use_libs = OneWire_ID1 + ``ignore_libs`` ^^^^^^^^^^^^^^^ diff --git a/platformio/__init__.py b/platformio/__init__.py index 9e004963..1d3f6c57 100644 --- a/platformio/__init__.py +++ b/platformio/__init__.py @@ -1,7 +1,7 @@ # Copyright (C) Ivan Kravets # See LICENSE for details. -VERSION = (2, 0, "0.dev3") +VERSION = (2, 0, "0.dev4") __version__ = ".".join([str(s) for s in VERSION]) __title__ = "platformio" diff --git a/platformio/builder/main.py b/platformio/builder/main.py index a68aceb9..45ec63d6 100644 --- a/platformio/builder/main.py +++ b/platformio/builder/main.py @@ -37,6 +37,7 @@ commonvars.AddVariables( ("BUILD_FLAGS",), ("SRCBUILD_FLAGS",), ("IGNORE_LIBS",), + ("USE_LIBS",), # board options ("BOARD",), diff --git a/platformio/builder/tools/platformio.py b/platformio/builder/tools/platformio.py index a45b526d..b70cc2c0 100644 --- a/platformio/builder/tools/platformio.py +++ b/platformio/builder/tools/platformio.py @@ -131,9 +131,11 @@ def BuildLibrary(env, variant_dir, library_dir, ignore_files=None): def BuildDependentLibraries(env, src_dir): # pylint: disable=R0914 - INCLUDES_RE = re.compile(r"^\s*#include\s+(\<|\")([^\>\"\']+)(?:\>|\")", - re.M) + INCLUDES_RE = re.compile( + r"^\s*#include\s+(\<|\")([^\>\"\']+)(?:\>|\")", re.M) LIBSOURCE_DIRS = [env.subst(d) for d in env.get("LIBSOURCE_DIRS", [])] + USE_LIBS = [l.strip() for l in env.get("USE_LIBS", "").split(",") + if l.strip()] # start internal prototypes @@ -174,7 +176,10 @@ def BuildDependentLibraries(env, src_dir): # pylint: disable=R0914 if not isdir(lsd_dir): continue - for ld in listdir(lsd_dir): + for ld in USE_LIBS + listdir(lsd_dir): + if not isdir(join(lsd_dir, ld)): + continue + inc_path = normpath(join(lsd_dir, ld, self.name)) try: lib_dir = inc_path[:inc_path.index( @@ -205,6 +210,7 @@ def BuildDependentLibraries(env, src_dir): # pylint: disable=R0914 "libs": set(), "ordered": set() } + state = _process_src_dir(state, env.subst(src_dir)) result = [] From 5469b98057b1c471e807920f469f63d1bcb038f3 Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Tue, 5 May 2015 16:15:44 +0100 Subject: [PATCH 37/49] Improve documentation for User Guide --- docs/userguide/index.rst | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/docs/userguide/index.rst b/docs/userguide/index.rst index 7d91e152..21d25d41 100644 --- a/docs/userguide/index.rst +++ b/docs/userguide/index.rst @@ -3,7 +3,33 @@ User Guide ========== -To print all available commands and options use: +.. contents:: + +Usage +----- + +.. code-block:: bash + + platformio [OPTIONS] COMMAND + +Options +------- + +.. option:: + --force, - f + +Force to accept any confirmation prompts. This option allows to avoid an issue +with :ref:`faq_troubleshooting_pioblocksprompt` + +.. option:: + --version + +Show the version of PlatformIO + +.. option:: + --help + +Show help for the available options and commands .. code-block:: bash @@ -11,6 +37,9 @@ To print all available commands and options use: $ platformio COMMAND --help +Commands +-------- + .. toctree:: :maxdepth: 2 From 945b1324af18662ad49c00fd01be50d5c6d42ba3 Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Wed, 6 May 2015 11:17:38 +0100 Subject: [PATCH 38/49] Fix gathering of _tplvars --- platformio/ide/projectgenerator.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/platformio/ide/projectgenerator.py b/platformio/ide/projectgenerator.py index f086eabe..45fdd3d8 100644 --- a/platformio/ide/projectgenerator.py +++ b/platformio/ide/projectgenerator.py @@ -15,7 +15,9 @@ class ProjectGenerator(object): def __init__(self, project_dir, ide): self.project_dir = project_dir self.ide = ide - self._tplvars = self._gather_tplvars() + self._tplvars = {} + + self._gather_tplvars() @staticmethod def get_supported_ides(): @@ -60,12 +62,10 @@ class ProjectGenerator(object): return bottle.template(content, **self._tplvars) def _gather_tplvars(self): - data = self.get_project_env() + self._tplvars.update(self.get_project_env()) - data.update({ + self._tplvars.update({ "project_name": self.get_project_name(), "includes": self.get_includes(), "srcfiles": self.get_srcfiles() }) - - return data From 04f246ea9d7a76e05b6402afa14e52f23e28dc41 Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Wed, 6 May 2015 11:28:56 +0100 Subject: [PATCH 39/49] Remove "autogen_" prefix from default env --- docs/userguide/cmd_init.rst | 7 ++++--- platformio/commands/init.py | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/docs/userguide/cmd_init.rst b/docs/userguide/cmd_init.rst index 637cdafd..fa0d8e43 100644 --- a/docs/userguide/cmd_init.rst +++ b/docs/userguide/cmd_init.rst @@ -57,9 +57,10 @@ allows you to disable firmware auto-uploading by default. .. option:: --env-prefix -An environment prefix which will be used with pair in board type. The default -value is ``autogen_``. For example, the default environment name for -``teensy_31`` board will be ``[env:autogen_teensy_31]``. +An environment prefix which will be used with pair in board type. + +For example, the default environment name for ``teensy_31`` board will +be ``[env:teensy_31]``. Examples diff --git a/platformio/commands/init.py b/platformio/commands/init.py index 229a1c23..4799d5fc 100644 --- a/platformio/commands/init.py +++ b/platformio/commands/init.py @@ -32,7 +32,7 @@ def validate_boards(ctx, param, value): # pylint: disable=W0613 @click.option("--ide", type=click.Choice(ProjectGenerator.get_supported_ides())) @click.option("--disable-auto-uploading", is_flag=True) -@click.option("--env-prefix", default="autogen_") +@click.option("--env-prefix", default="") def cli(project_dir, board, ide, disable_auto_uploading, env_prefix): # ask about auto-uploading From eeeed1ba08bd1781eb302ff663a216401ba83fd2 Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Wed, 6 May 2015 17:29:58 +0100 Subject: [PATCH 40/49] =?UTF-8?q?Allow=20to=20run=20project=20with=20platf?= =?UTF-8?q?ormio=20run=20=E2=80=93project-dir=20option=20without=20changin?= =?UTF-8?q?g=20the=20current=20working=20directory=20//=20Resolve=20#192?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- HISTORY.rst | 3 ++ docs/userguide/cmd_run.rst | 6 +++ platformio/commands/run.py | 81 +++++++++++++++++++++----------------- 3 files changed, 54 insertions(+), 36 deletions(-) diff --git a/HISTORY.rst b/HISTORY.rst index b5063b09..2de01062 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -11,6 +11,9 @@ Release History (`issue #174 `_) * Added global ``-f, --force`` option which will force to accept any confirmation prompts (`issue #152 `_) +* Allowed to run project with `platformio run --project-dir `_ option without changing the current working + directory + (`issue #192 `_) * Allowed to add library dependencies for build environment using `install_libs `_ option in ``platformio.ini`` diff --git a/docs/userguide/cmd_run.rst b/docs/userguide/cmd_run.rst index 2dc833f4..9c170794 100644 --- a/docs/userguide/cmd_run.rst +++ b/docs/userguide/cmd_run.rst @@ -39,6 +39,12 @@ Process specified targets Upload port of embedded board. To print all available ports use :ref:`cmd_serialports` command +.. option:: + --build-dir + +Specify the path to project directory. By default, ``--build-dir`` is equal to +current working directory (``CWD``). + Examples -------- diff --git a/platformio/commands/run.py b/platformio/commands/run.py index 0a49d513..e29d1366 100644 --- a/platformio/commands/run.py +++ b/platformio/commands/run.py @@ -2,6 +2,7 @@ # See LICENSE for details. from datetime import datetime +from os import chdir, getcwd from os.path import getmtime, isdir, join from shutil import rmtree from time import time @@ -20,52 +21,60 @@ from platformio.platforms.base import PlatformFactory @click.option("--environment", "-e", multiple=True, metavar="") @click.option("--target", "-t", multiple=True, metavar="") @click.option("--upload-port", metavar="") +@click.option("--project-dir", default=getcwd, + type=click.Path(exists=True, file_okay=False, dir_okay=True, + writable=True, resolve_path=True)) @click.pass_context -def cli(ctx, environment, target, upload_port): +def cli(ctx, environment, target, upload_port, project_dir): + initial_cwd = getcwd() + chdir(project_dir) + try: + config = util.get_project_config() - config = util.get_project_config() + if not config.sections(): + raise exception.ProjectEnvsNotAvailable() - if not config.sections(): - raise exception.ProjectEnvsNotAvailable() + unknown = set(environment) - set([s[4:] for s in config.sections()]) + if unknown: + raise exception.UnknownEnvNames(", ".join(unknown)) - unknown = set(environment) - set([s[4:] for s in config.sections()]) - if unknown: - raise exception.UnknownEnvNames(", ".join(unknown)) + # remove ".pioenvs" if project config is modified + _pioenvs_dir = util.get_pioenvs_dir() + if (isdir(_pioenvs_dir) and + getmtime(join(util.get_project_dir(), "platformio.ini")) > + getmtime(_pioenvs_dir)): + rmtree(_pioenvs_dir) - # remove ".pioenvs" if project config is modified - _pioenvs_dir = util.get_pioenvs_dir() - if (isdir(_pioenvs_dir) and - getmtime(join(util.get_project_dir(), "platformio.ini")) > - getmtime(_pioenvs_dir)): - rmtree(_pioenvs_dir) + found_error = False + _first_done = False + for section in config.sections(): + # skip main configuration section + if section == "platformio": + continue + elif section[:4] != "env:": + raise exception.InvalidEnvName(section) - found_error = False - _first_done = False - for section in config.sections(): - # skip main configuration section - if section == "platformio": - continue - elif section[:4] != "env:": - raise exception.InvalidEnvName(section) + envname = section[4:] + if environment and envname not in environment: + # echo("Skipped %s environment" % style(envname, fg="yellow")) + continue - envname = section[4:] - if environment and envname not in environment: - # echo("Skipped %s environment" % style(envname, fg="yellow")) - continue + options = {} + for k, v in config.items(section): + options[k] = v - options = {} - for k, v in config.items(section): - options[k] = v + if _first_done: + click.echo() - if _first_done: - click.echo() + if not process_environment( + ctx, envname, options, target, upload_port): + found_error = True + _first_done = True - if not process_environment(ctx, envname, options, target, upload_port): - found_error = True - _first_done = True - - if found_error: - raise exception.ReturnErrorCode() + if found_error: + raise exception.ReturnErrorCode() + finally: + chdir(initial_cwd) def process_environment(ctx, name, options, targets, upload_port): From 92e81ee61909fe903b8a9b5052829317070b2b03 Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Wed, 6 May 2015 18:07:17 +0100 Subject: [PATCH 41/49] Cleanup code --- platformio/__main__.py | 3 ++- platformio/commands/run.py | 51 ++++++++++++++++++++------------------ platformio/maintenance.py | 2 +- 3 files changed, 30 insertions(+), 26 deletions(-) diff --git a/platformio/__main__.py b/platformio/__main__.py index d0e910c8..a4e44146 100644 --- a/platformio/__main__.py +++ b/platformio/__main__.py @@ -37,7 +37,8 @@ class PlatformioCLI(click.MultiCommand): # pylint: disable=R0904 raise exception.UnknownCLICommand(name) return mod.cli - def _handle_obsolate_command(self, name): + @staticmethod + def _handle_obsolate_command(name): if name in ("install", "list", "search", "show", "uninstall"): click.secho( "Warning! `platformio %s` command is obsoleted and will be " diff --git a/platformio/commands/run.py b/platformio/commands/run.py index e29d1366..5cbd650f 100644 --- a/platformio/commands/run.py +++ b/platformio/commands/run.py @@ -45,39 +45,42 @@ def cli(ctx, environment, target, upload_port, project_dir): getmtime(_pioenvs_dir)): rmtree(_pioenvs_dir) - found_error = False - _first_done = False + results = [] for section in config.sections(): - # skip main configuration section - if section == "platformio": - continue - elif section[:4] != "env:": - raise exception.InvalidEnvName(section) - - envname = section[4:] - if environment and envname not in environment: - # echo("Skipped %s environment" % style(envname, fg="yellow")) - continue - - options = {} - for k, v in config.items(section): - options[k] = v - - if _first_done: + if results and results[-1] is not None: click.echo() - if not process_environment( - ctx, envname, options, target, upload_port): - found_error = True - _first_done = True + results.append(_process_conf_section( + ctx, config, section, environment, target, upload_port)) - if found_error: + if not all([r for r in results if r is not None]): raise exception.ReturnErrorCode() finally: chdir(initial_cwd) -def process_environment(ctx, name, options, targets, upload_port): +def _process_conf_section(ctx, config, section, # pylint: disable=R0913 + environment, target, upload_port): + # skip main configuration section + if section == "platformio": + return None + + if section[:4] != "env:": + raise exception.InvalidEnvName(section) + + envname = section[4:] + if environment and envname not in environment: + # echo("Skipped %s environment" % style(envname, fg="yellow")) + return None + + options = {} + for k, v in config.items(section): + options[k] = v + + return _process_environment(ctx, envname, options, target, upload_port) + + +def _process_environment(ctx, name, options, targets, upload_port): terminal_width, _ = click.get_terminal_size() start_time = time() diff --git a/platformio/maintenance.py b/platformio/maintenance.py index b67824b9..89d7fbd3 100644 --- a/platformio/maintenance.py +++ b/platformio/maintenance.py @@ -19,7 +19,7 @@ from platformio.commands.platforms import \ from platformio.commands.upgrade import get_latest_version from platformio.libmanager import LibraryManager from platformio.platforms.base import PlatformFactory -from platformio.util import get_home_dir, get_lib_dir +from platformio.util import get_home_dir def on_platformio_start(ctx, force): From 19b7c730aecb7bebcf3a0a5dd0980d96e9102f0a Mon Sep 17 00:00:00 2001 From: Valeriy Koval Date: Thu, 7 May 2015 17:21:44 +0300 Subject: [PATCH 42/49] Update project generator and templates. --- platformio/ide/projectgenerator.py | 14 +- platformio/ide/tpls/eclipse/.cproject.tpl | 37 +-- .../ide/tpls/qtcreator/platformio.pro.tpl | 13 +- .../tpls/qtcreator/platformio.pro.user.tpl | 231 ++++++++++++++++++ .../tpls/visualstudio/platformio.vcxproj.tpl | 12 +- 5 files changed, 280 insertions(+), 27 deletions(-) create mode 100644 platformio/ide/tpls/qtcreator/platformio.pro.user.tpl diff --git a/platformio/ide/projectgenerator.py b/platformio/ide/projectgenerator.py index 45fdd3d8..ebdaa2fb 100644 --- a/platformio/ide/projectgenerator.py +++ b/platformio/ide/projectgenerator.py @@ -2,7 +2,7 @@ # See LICENSE for details. from glob import glob -from os import listdir +from os import listdir, walk from os.path import basename, isdir, join import bottle @@ -32,6 +32,7 @@ class ProjectGenerator(object): for section in config.sections(): if not section.startswith("env:"): continue + data['env_name'] = section[4:] for k, v in config.items(section): data[k] = v return data @@ -43,6 +44,13 @@ class ProjectGenerator(object): return [] def get_srcfiles(self): + result = [] + for root, _, files in walk(util.get_projectsrc_dir()): + for f in files: + result.append(join(root, f)) + return result + + def get_defines(self): return [] def get_tpls(self): @@ -67,5 +75,7 @@ class ProjectGenerator(object): self._tplvars.update({ "project_name": self.get_project_name(), "includes": self.get_includes(), - "srcfiles": self.get_srcfiles() + "srcfiles": self.get_srcfiles(), + "defines": self.get_defines(), + "project_dir": self.project_dir }) diff --git a/platformio/ide/tpls/eclipse/.cproject.tpl b/platformio/ide/tpls/eclipse/.cproject.tpl index 7ed43a49..ccd645ed 100644 --- a/platformio/ide/tpls/eclipse/.cproject.tpl +++ b/platformio/ide/tpls/eclipse/.cproject.tpl @@ -15,7 +15,7 @@ - + @@ -23,35 +23,40 @@ @@ -63,7 +68,7 @@ - + @@ -74,7 +79,7 @@ - + diff --git a/platformio/ide/tpls/qtcreator/platformio.pro.tpl b/platformio/ide/tpls/qtcreator/platformio.pro.tpl index 22188cd8..d809a9b3 100644 --- a/platformio/ide/tpls/qtcreator/platformio.pro.tpl +++ b/platformio/ide/tpls/qtcreator/platformio.pro.tpl @@ -5,15 +5,20 @@ else { HOMEDIR += $$(PWD) } -INCLUDEPATH += "$$HOMEDIR/.platformio/packages/framework-arduinoavr/cores/arduino" -INCLUDEPATH += "$$HOMEDIR/.platformio/packages/toolchain-atmelavr/avr/include" +% for include in includes: +INCLUDEPATH += "{{include}}" +% end win32:INCLUDEPATH ~= s,/,\\,g -# DEFINES += __AVR_ATmega328__ +% for define in defines: +DEFINES += "{{define}}" +% end OTHER_FILES += \ platformio.ini SOURCES += \ - src/main.c + % for file in srcfiles: + {{file}} + % end diff --git a/platformio/ide/tpls/qtcreator/platformio.pro.user.tpl b/platformio/ide/tpls/qtcreator/platformio.pro.user.tpl new file mode 100644 index 00000000..72ecb9ad --- /dev/null +++ b/platformio/ide/tpls/qtcreator/platformio.pro.user.tpl @@ -0,0 +1,231 @@ + + + + + + EnvironmentId + {00248b6a-4380-4f03-8dea-a03053177907} + + + ProjectExplorer.Project.ActiveTarget + 0 + + + ProjectExplorer.Project.EditorSettings + + true + false + true + + Cpp + + CppGlobal + + + + QmlJS + + QmlJSGlobal + + + 2 + UTF-8 + false + 4 + false + 80 + true + true + 1 + true + false + 0 + true + 0 + 8 + true + 1 + true + true + true + false + + + + ProjectExplorer.Project.PluginSettings + + + + ProjectExplorer.Project.Target.0 + + {{project_name}} + {{project_name}} + qt.53.win32_mingw482_kit + 1 + 0 + 0 + + {{project_dir}} + + + true + --force run + platformio + %{buildDir} + Custom Process Step + + ProjectExplorer.ProcessStep + + 1 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + --force run -t clean + platformio + %{buildDir} + Custom Process Step + + ProjectExplorer.ProcessStep + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Debug + + Qt4ProjectManager.Qt4BuildConfiguration + 2 + true + + + {{project_dir}} + + + true + --force run + platformio + %{buildDir} + Custom Process Step + + ProjectExplorer.ProcessStep + + 1 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + --force run -t clean + platformio + %{buildDir} + Custom Process Step + + ProjectExplorer.ProcessStep + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Release + + Qt4ProjectManager.Qt4BuildConfiguration + 0 + true + + 2 + + + 0 + Deploy + + ProjectExplorer.BuildSteps.Deploy + + 1 + Deploy locally + + ProjectExplorer.DefaultDeployConfiguration + + 1 + + + + false + false + false + false + true + 0.01 + 10 + true + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + platformio + + Qt4ProjectManager.Qt4RunConfiguration:{{project_dir}}/platformio.pro + + platformio.pro + false + false + + 3768 + false + true + false + false + true + + 1 + + + + ProjectExplorer.Project.TargetCount + 1 + + + ProjectExplorer.Project.Updater.FileVersion + 16 + + + Version + 16 + + diff --git a/platformio/ide/tpls/visualstudio/platformio.vcxproj.tpl b/platformio/ide/tpls/visualstudio/platformio.vcxproj.tpl index 54d5be85..1a069d7e 100644 --- a/platformio/ide/tpls/visualstudio/platformio.vcxproj.tpl +++ b/platformio/ide/tpls/visualstudio/platformio.vcxproj.tpl @@ -38,14 +38,14 @@ platformio --force run platformio --force run --target clean - WIN32;_DEBUG;$(NMakePreprocessorDefinitions) - $(HOMEDRIVE)$(HOMEPATH)\.platformio\packages\toolchain-atmelavr\avr\include;$(HOMEDRIVE)$(HOMEPATH)\.platformio\packages\framework-arduinoavr\cores\arduino;$(NMakeIncludeSearchPath) + {{";".join(defines)}} + {{";".join(includes)}} platformio run platformio run -t clean - WIN32;NDEBUG;$(NMakePreprocessorDefinitions) - $(HOMEDRIVE)$(HOMEPATH)\.platformio\packages\toolchain-atmelavr\avr\include;$(HOMEDRIVE)$(HOMEPATH)\.platformio\packages\framework-arduinoavr\cores\arduino;$(NMakeIncludeSearchPath) + {";".join(defines)}} + {{";".join(includes)}} @@ -54,7 +54,9 @@ - + % for file in srcfiles: + + % end From 7822a929f39b4b9ba823d6e350b7fd4589e954ca Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Thu, 7 May 2015 15:53:06 +0100 Subject: [PATCH 43/49] Fix tests after removing "autogen" prefix for init project --- examples/wiring-blink/platformio.ini | 8 ++++---- tests/commands/test_init.py | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/examples/wiring-blink/platformio.ini b/examples/wiring-blink/platformio.ini index a1445967..33d4a63f 100644 --- a/examples/wiring-blink/platformio.ini +++ b/examples/wiring-blink/platformio.ini @@ -5,22 +5,22 @@ ; http://docs.platformio.org/en/latest/projectconf.html ; -[env:autogen_uno] +[env:uno] platform = atmelavr framework = arduino board = uno -[env:autogen_teensy31] +[env:teensy31] platform = teensy framework = arduino board = teensy31 -[env:autogen_lpmsp430g2553] +[env:lpmsp430g2553] platform = timsp430 framework = energia board = lpmsp430g2553 -[env:autogen_lptm4c1230c3pm] +[env:lptm4c1230c3pm] platform = titiva framework = energia board = lptm4c1230c3pm diff --git a/tests/commands/test_init.py b/tests/commands/test_init.py index d951f760..d354982e 100644 --- a/tests/commands/test_init.py +++ b/tests/commands/test_init.py @@ -46,9 +46,9 @@ def test_init_special_board(platformio_setup, clirunner, validate_cliresult): ("targets", "upload") ] - assert config.has_section("env:autogen_uno") + assert config.has_section("env:uno") assert len(set(expected_result).symmetric_difference( - set(config.items("env:autogen_uno")))) == 0 + set(config.items("env:uno")))) == 0 def test_init_disable_auto_uploading(platformio_setup, clirunner, @@ -64,9 +64,9 @@ def test_init_disable_auto_uploading(platformio_setup, clirunner, ("framework", "arduino"), ("board", "uno") ] - assert config.has_section("env:autogen_uno") + assert config.has_section("env:uno") assert len(set(expected_result).symmetric_difference( - set(config.items("env:autogen_uno")))) == 0 + set(config.items("env:uno")))) == 0 def test_init_incorrect_board(clirunner): From 510c4decb7c4bcae9b2dd95b05880e04841636f9 Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Thu, 7 May 2015 16:20:53 +0100 Subject: [PATCH 44/49] PlatformIO as Continuous Integration tool for embedded projects // Resolve #108 --- HISTORY.rst | 4 +- docs/userguide/cmd_ci.rst | 125 ++++++++++++++++++++++++++++++++++ docs/userguide/index.rst | 1 + platformio/__init__.py | 2 +- platformio/commands/ci.py | 139 ++++++++++++++++++++++++++++++++++++++ platformio/exception.py | 9 +++ 6 files changed, 278 insertions(+), 2 deletions(-) create mode 100644 docs/userguide/cmd_ci.rst create mode 100644 platformio/commands/ci.py diff --git a/HISTORY.rst b/HISTORY.rst index 2de01062..29867dd9 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -4,9 +4,11 @@ Release History 2.0.0 (2015-??-??) ------------------ -* Implemented PlatformIO CLI 2.0: "platform" related commands have been +* PlatformIO CLI 2.0: "platform" related commands have been moved to ``platformio platforms`` subcommand (`issue #158 `_) +* PlatformIO as Continuous Integration (CI) tool for embedded projects + (`issue #108 `_) * Created `PlatformIO gitter.im `_ room (`issue #174 `_) * Added global ``-f, --force`` option which will force to accept any diff --git a/docs/userguide/cmd_ci.rst b/docs/userguide/cmd_ci.rst new file mode 100644 index 00000000..cb7e6642 --- /dev/null +++ b/docs/userguide/cmd_ci.rst @@ -0,0 +1,125 @@ +.. _cmd_ci: + +platformio ci +============= + +.. contents:: + +Usage +----- + +.. code-block:: bash + + platformio ci [OPTIONS] [SRC] + + +Description +----------- + +`Continuous integration (CI, wiki) `_ +is the practice, in software engineering, of merging all developer working +copies with a shared mainline several times a day. + +:ref:`cmd_ci` command is conceived of as "hot key" for building project with +arbitrary source code structure. In a nutshell, using ``SRC`` and +:option:`platformio ci --lib` contents PlatformIO initialises via +:ref:`cmd_init` new project in :option:`platformio ci --build-dir` +with the build environments (using :option:`platformio ci --board` or +:option:`platformio ci --project-conf`) and processes them via :ref:`cmd_run` +command. + +:ref:`cmd_ci` command is intended to be used in combination with the build +servers and the popular +`Continuous Integration Software `_. + +By integrating regularly, you can detect errors quickly, and locate them more +easily. + +.. note:: + :ref:`cmd_ci` command accepts **multiple** ``SRC`` arguments, + :option:`platformio ci --lib` and :option:`platformio ci --exclude` options + which can be a path to directory, file or + `Glob Pattern `_. + +Options +------- + +.. program:: platformio ci + +.. option:: + -l, --lib + +Source code which will be copied to ``%build_dir%/lib`` directly. + +If :option:`platformio ci --lib` is a path to file (not to directory), then +PlatformIO will create temporary directory within ``%build_dir%/lib`` and copy +the rest files into it. + + +.. option:: + --exclude + +Exclude directories and/-or files from :option:`platformio ci --build-dir`. The +path must be relative to PlatformIO project within +:option:`platformio ci --build-dir`. + +For example, exclude from project ``src`` directory: + +* ``examples`` folder +* ``*.h`` files from ``foo`` folder + +.. code-block:: bash + + platformio ci --exclude=src/examples --exclude=src/foo/*.h [SRC] + +.. option:: + --board, -b + +Build project with automatically pre-generated environments based on board +settings. + +For more details please look into :option:`platformio init --board`. + +.. option:: + --build-dir + +Path to directory where PlatformIO will initialise new project. By default it's +temporary directory within your operation system. + +.. note:: + + This directory will be removed at the end of build process. If you want to + keep it, please use :option:`platformio ci --keep-build-dir`. + +.. option:: + --keep-build-dir + +Don't remove :option:`platformio ci --build-dir` after build process. + +.. option:: + --project-conf + +Buid project using pre-configured :ref:`projectconf`. + +Examples +-------- + +1. Integration `Travis.CI `_ for GitHub + `USB_Host_Shield_2.0 `_ + project. The ``.travis.yml`` configuration file: + +.. code-block:: yaml + + language: python + python: + - "2.7" + + env: + - PLATFORMIO_CI_SRC=examples/Bluetooth/PS3SPP/PS3SPP.ino + - PLATFORMIO_CI_SRC=examples/pl2303/pl2303_gps/pl2303_gps.ino + + install: + - python -c "$(curl -fsSL https://raw.githubusercontent.com/platformio/platformio/master/scripts/get-platformio.py)" + + script: + - platformio ci --lib="." --board=uno --board=teensy31 --board=due diff --git a/docs/userguide/index.rst b/docs/userguide/index.rst index 21d25d41..e849ed58 100644 --- a/docs/userguide/index.rst +++ b/docs/userguide/index.rst @@ -44,6 +44,7 @@ Commands :maxdepth: 2 cmd_boards + cmd_ci cmd_init platformio lib platformio platforms diff --git a/platformio/__init__.py b/platformio/__init__.py index 1d3f6c57..83054086 100644 --- a/platformio/__init__.py +++ b/platformio/__init__.py @@ -1,7 +1,7 @@ # Copyright (C) Ivan Kravets # See LICENSE for details. -VERSION = (2, 0, "0.dev4") +VERSION = (2, 0, "0.dev5") __version__ = ".".join([str(s) for s in VERSION]) __title__ = "platformio" diff --git a/platformio/commands/ci.py b/platformio/commands/ci.py new file mode 100644 index 00000000..43e56ac7 --- /dev/null +++ b/platformio/commands/ci.py @@ -0,0 +1,139 @@ +# Copyright (C) Ivan Kravets +# See LICENSE for details. + +from glob import glob +from os import environ, makedirs, remove +from os.path import basename, isdir, isfile, join +from shutil import copyfile, copytree, rmtree +from tempfile import mkdtemp + +import click + +from platformio import app +from platformio.commands.init import cli as cmd_init +from platformio.commands.run import cli as cmd_run +from platformio.exception import CIBuildEnvsEmpty +from platformio.util import get_boards + + +def validate_path(ctx, param, value): # pylint: disable=W0613 + invalid_path = None + for p in value: + if not glob(p): + invalid_path = p + break + try: + assert invalid_path is None + return value + except AssertionError: + raise click.BadParameter("Found invalid path: %s" % invalid_path) + + +def validate_boards(ctx, param, value): # pylint: disable=W0613 + unknown_boards = set(value) - set(get_boards().keys()) + try: + assert not unknown_boards + return value + except AssertionError: + raise click.BadParameter( + "%s. Please search for the board types using " + "`platformio boards` command" % ", ".join(unknown_boards)) + + +@click.command("ci", short_help="Continuous Integration") +@click.argument("src", nargs=-1, callback=validate_path) +@click.option("--lib", "-l", multiple=True, callback=validate_path) +@click.option("--exclude", multiple=True) +@click.option("--board", "-b", multiple=True, callback=validate_boards) +@click.option("--build-dir", default=mkdtemp, + type=click.Path(exists=True, file_okay=False, dir_okay=True, + writable=True, resolve_path=True)) +@click.option("--keep-build-dir", is_flag=True) +@click.option("--project-conf", + type=click.Path(exists=True, file_okay=True, dir_okay=False, + readable=True, resolve_path=True)) +@click.pass_context +def cli(ctx, src, lib, exclude, board, # pylint: disable=R0913 + build_dir, keep_build_dir, project_conf): + + if not src: + src = environ.get("PLATFORMIO_CI_SRC", "").split(":") + if not src: + raise click.BadParameter("Missing argument 'src'") + + try: + app.set_session_var("force_option", True) + _clean_dir(build_dir) + + for dir_name, patterns in dict(lib=lib, src=src).iteritems(): + if not patterns: + continue + contents = [] + for p in patterns: + contents += glob(p) + _copy_contents(join(build_dir, dir_name), contents) + + if project_conf and isfile(project_conf): + copyfile(project_conf, join(build_dir, "platformio.ini")) + elif not board: + raise CIBuildEnvsEmpty() + + if exclude: + _exclude_contents(build_dir, exclude) + + # initialise project + ctx.invoke(cmd_init, project_dir=build_dir, board=board, + disable_auto_uploading=True) + + # process project + ctx.invoke(cmd_run, project_dir=build_dir) + finally: + if not keep_build_dir: + rmtree(build_dir) + + +def _clean_dir(dirpath): + rmtree(dirpath) + makedirs(dirpath) + + +def _copy_contents(dst_dir, contents): + items = { + "dirs": set(), + "files": set() + } + + for path in contents: + if isdir(path): + items['dirs'].add(path) + elif isfile(path): + items['files'].add(path) + + dst_dir_name = basename(dst_dir) + + if dst_dir_name == "src" and len(items['dirs']) == 1: + copytree(list(items['dirs']).pop(), dst_dir) + else: + makedirs(dst_dir) + for d in items['dirs']: + copytree(d, join(dst_dir, basename(d))) + + if not items['files']: + return + + if dst_dir_name == "lib": + dst_dir = join(dst_dir, mkdtemp(dir=dst_dir)) + + for f in items['files']: + copyfile(f, join(dst_dir, basename(f))) + + +def _exclude_contents(dst_dir, patterns): + contents = [] + for p in patterns: + contents += glob(join(dst_dir, p)) + for path in contents: + if isdir(path): + rmtree(path) + elif isfile(path): + remove(path) diff --git a/platformio/exception.py b/platformio/exception.py index daaa176e..22b5978a 100644 --- a/platformio/exception.py +++ b/platformio/exception.py @@ -165,6 +165,15 @@ class UpgraderFailed(PlatformioException): MESSAGE = "An error occurred while upgrading PlatformIO" +class CIBuildEnvsEmpty(PlatformioException): + + MESSAGE = ( + "Can't find PlatformIO build environments.\nPlease specify `--board` " + "or path to `platformio.ini` with predefined environments using " + "`--project-conf` option" + ) + + class SConsNotInstalled(PlatformioException): MESSAGE = ( From a1bad33d9dec989e355fa6337bbcee8f163191d6 Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Thu, 7 May 2015 16:44:56 +0100 Subject: [PATCH 45/49] Add "program" to command options --- docs/userguide/cmd_ci.rst | 2 +- docs/userguide/cmd_init.rst | 5 ++++- docs/userguide/cmd_run.rst | 2 ++ docs/userguide/cmd_serialports.rst | 4 ++++ docs/userguide/index.rst | 2 ++ docs/userguide/lib/cmd_install.rst | 2 ++ docs/userguide/lib/cmd_list.rst | 2 ++ docs/userguide/lib/cmd_search.rst | 2 ++ docs/userguide/platforms/cmd_install.rst | 2 ++ docs/userguide/platforms/cmd_list.rst | 2 ++ docs/userguide/platforms/cmd_search.rst | 2 ++ 11 files changed, 25 insertions(+), 2 deletions(-) diff --git a/docs/userguide/cmd_ci.rst b/docs/userguide/cmd_ci.rst index cb7e6642..a9b7b153 100644 --- a/docs/userguide/cmd_ci.rst +++ b/docs/userguide/cmd_ci.rst @@ -47,7 +47,7 @@ Options .. program:: platformio ci .. option:: - -l, --lib + --lib, -l Source code which will be copied to ``%build_dir%/lib`` directly. diff --git a/docs/userguide/cmd_init.rst b/docs/userguide/cmd_init.rst index fa0d8e43..d7c5170a 100644 --- a/docs/userguide/cmd_init.rst +++ b/docs/userguide/cmd_init.rst @@ -29,6 +29,8 @@ This command will create: Options ------- +.. program:: platformio init + .. option:: --project-dir, -d @@ -50,7 +52,8 @@ The full list with pre-configured boards is available here :ref:`platforms`. .. option:: --disable-auto-uploading -If you initialise project with the specified ``--board``, then *PlatformIO* +If you initialise project with the specified +:option:`platformio init --board``, then *PlatformIO* will create environment with enabled firmware auto-uploading. This option allows you to disable firmware auto-uploading by default. diff --git a/docs/userguide/cmd_run.rst b/docs/userguide/cmd_run.rst index 9c170794..9daa9dda 100644 --- a/docs/userguide/cmd_run.rst +++ b/docs/userguide/cmd_run.rst @@ -22,6 +22,8 @@ Process environments which are defined in :ref:`projectconf` file Options ------- +.. program:: platformio run + .. option:: -e, --environment diff --git a/docs/userguide/cmd_serialports.rst b/docs/userguide/cmd_serialports.rst index 360877ec..53bae993 100644 --- a/docs/userguide/cmd_serialports.rst +++ b/docs/userguide/cmd_serialports.rst @@ -24,6 +24,8 @@ List available `Serial Ports `_ Options ~~~~~~~ +.. program:: platformio serialports list + .. option:: --json-output @@ -99,6 +101,8 @@ To control *monitor* please use these "hot keys": Options ~~~~~~~ +.. program:: platformio serialports monitor + .. option:: -p, --port diff --git a/docs/userguide/index.rst b/docs/userguide/index.rst index e849ed58..6c52a9e5 100644 --- a/docs/userguide/index.rst +++ b/docs/userguide/index.rst @@ -15,6 +15,8 @@ Usage Options ------- +.. program:: platformio + .. option:: --force, - f diff --git a/docs/userguide/lib/cmd_install.rst b/docs/userguide/lib/cmd_install.rst index 854401b7..bb4dd95f 100644 --- a/docs/userguide/lib/cmd_install.rst +++ b/docs/userguide/lib/cmd_install.rst @@ -22,6 +22,8 @@ Install new library by specified Options ------- +.. program:: platformio lib install + .. option:: -v, --version diff --git a/docs/userguide/lib/cmd_list.rst b/docs/userguide/lib/cmd_list.rst index 2551704b..07c68bc3 100644 --- a/docs/userguide/lib/cmd_list.rst +++ b/docs/userguide/lib/cmd_list.rst @@ -21,6 +21,8 @@ List installed libraries Options ~~~~~~~ +.. program:: platformio lib list + .. option:: --json-output diff --git a/docs/userguide/lib/cmd_search.rst b/docs/userguide/lib/cmd_search.rst index 84899256..41bd8199 100644 --- a/docs/userguide/lib/cmd_search.rst +++ b/docs/userguide/lib/cmd_search.rst @@ -61,6 +61,8 @@ For more detail information please go to Options ------- +.. program:: platformio lib search + .. option:: -a, --author diff --git a/docs/userguide/platforms/cmd_install.rst b/docs/userguide/platforms/cmd_install.rst index 6f7dc8a8..ced397f8 100644 --- a/docs/userguide/platforms/cmd_install.rst +++ b/docs/userguide/platforms/cmd_install.rst @@ -27,6 +27,8 @@ There are several predefined aliases for packages, such as: Options ------- +.. program:: platformio platforms install + .. option:: --with-package diff --git a/docs/userguide/platforms/cmd_list.rst b/docs/userguide/platforms/cmd_list.rst index 594defe6..90e5d9a5 100644 --- a/docs/userguide/platforms/cmd_list.rst +++ b/docs/userguide/platforms/cmd_list.rst @@ -21,6 +21,8 @@ List installed :ref:`Platforms ` Options ~~~~~~~ +.. program:: platformio platforms list + .. option:: --json-output diff --git a/docs/userguide/platforms/cmd_search.rst b/docs/userguide/platforms/cmd_search.rst index b77bed41..20d9e42e 100644 --- a/docs/userguide/platforms/cmd_search.rst +++ b/docs/userguide/platforms/cmd_search.rst @@ -21,6 +21,8 @@ Search for development :ref:`Platforms ` Options ~~~~~~~ +.. program:: platformio platforms search + .. option:: --json-output From 44eaf1db22867f3d300ab49d14d8161afc3417c5 Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Thu, 7 May 2015 17:02:53 +0100 Subject: [PATCH 46/49] Document PLATFORMIO_CI_SRC environment variable --- docs/userguide/cmd_ci.rst | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/docs/userguide/cmd_ci.rst b/docs/userguide/cmd_ci.rst index a9b7b153..a036d2e7 100644 --- a/docs/userguide/cmd_ci.rst +++ b/docs/userguide/cmd_ci.rst @@ -41,6 +41,11 @@ easily. which can be a path to directory, file or `Glob Pattern `_. +.. note:: + You can omit ``SRC`` argument and set path (multiple paths are allowed + denoting with ``:``) to + ``PLATFORMIO_CI_SRC`` `Environment variable `_ + Options ------- From 72ebe0ec1bf63d52cbceeff9e11c31740c79e8d0 Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Thu, 7 May 2015 18:40:53 +0100 Subject: [PATCH 47/49] Fix PyLint warnings --- platformio/ide/projectgenerator.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/platformio/ide/projectgenerator.py b/platformio/ide/projectgenerator.py index ebdaa2fb..3f09249c 100644 --- a/platformio/ide/projectgenerator.py +++ b/platformio/ide/projectgenerator.py @@ -40,17 +40,20 @@ class ProjectGenerator(object): def get_project_name(self): return basename(self.project_dir) - def get_includes(self): + @staticmethod + def get_includes(): return [] - def get_srcfiles(self): + @staticmethod + def get_srcfiles(): result = [] for root, _, files in walk(util.get_projectsrc_dir()): for f in files: result.append(join(root, f)) return result - def get_defines(self): + @staticmethod + def get_defines(): return [] def get_tpls(self): From 40322e0f9b69b301c89d93782b3555007d8d44be Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Fri, 8 May 2015 17:32:14 +0100 Subject: [PATCH 48/49] Allow to print dump of SCons environment using "envdump" target --- platformio/builder/tools/platformio.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/platformio/builder/tools/platformio.py b/platformio/builder/tools/platformio.py index b70cc2c0..90e9f41d 100644 --- a/platformio/builder/tools/platformio.py +++ b/platformio/builder/tools/platformio.py @@ -6,7 +6,8 @@ import re from os import getenv, listdir, remove, sep, walk from os.path import basename, dirname, isdir, isfile, join, normpath -from SCons.Script import Exit, SConscript, SConscriptChdir +from SCons.Script import (COMMAND_LINE_TARGETS, Exit, SConscript, + SConscriptChdir) from SCons.Util import case_sensitive_suffixes from platformio.util import pioversion_to_intstr @@ -60,6 +61,10 @@ def BuildFirmware(env): *pioversion_to_intstr())] ) + if "envdump" in COMMAND_LINE_TARGETS: + print env.Dump() + Exit() + return firmenv.Program( join("$BUILD_DIR", "firmware"), [firmenv.GlobCXXFiles(vdir) for vdir in vdirs], From ccfc9afba7e5881da5d7e41537c07247b2058cb7 Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Fri, 15 May 2015 13:56:19 +0200 Subject: [PATCH 49/49] Fix absolute paths for CI --- platformio/__init__.py | 2 +- platformio/commands/ci.py | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/platformio/__init__.py b/platformio/__init__.py index 83054086..ec20ef26 100644 --- a/platformio/__init__.py +++ b/platformio/__init__.py @@ -1,7 +1,7 @@ # Copyright (C) Ivan Kravets # See LICENSE for details. -VERSION = (2, 0, "0.dev5") +VERSION = (2, 0, "0.dev6") __version__ = ".".join([str(s) for s in VERSION]) __title__ = "platformio" diff --git a/platformio/commands/ci.py b/platformio/commands/ci.py index 43e56ac7..2218eb76 100644 --- a/platformio/commands/ci.py +++ b/platformio/commands/ci.py @@ -3,7 +3,7 @@ from glob import glob from os import environ, makedirs, remove -from os.path import basename, isdir, isfile, join +from os.path import abspath, basename, isdir, isfile, join from shutil import copyfile, copytree, rmtree from tempfile import mkdtemp @@ -104,6 +104,7 @@ def _copy_contents(dst_dir, contents): } for path in contents: + path = abspath(path) if isdir(path): items['dirs'].add(path) elif isfile(path): @@ -133,6 +134,7 @@ def _exclude_contents(dst_dir, patterns): for p in patterns: contents += glob(join(dst_dir, p)) for path in contents: + path = abspath(path) if isdir(path): rmtree(path) elif isfile(path):