diff --git a/platformio/builder/main.py b/platformio/builder/main.py index 2d070104..c656da0b 100644 --- a/platformio/builder/main.py +++ b/platformio/builder/main.py @@ -29,6 +29,10 @@ from SCons.Script import DefaultEnvironment # pylint: disable=import-error from SCons.Script import Variables # pylint: disable=import-error from platformio import util +from platformio.project.helpers import ( + get_project_dir, get_project_optional_dir, get_projectbuild_dir, + get_projectdata_dir, get_projectinclude_dir, get_projectlib_dir, + get_projectlibdeps_dir, get_projectsrc_dir, get_projecttest_dir) AllowSubstExceptions(NameError) @@ -101,19 +105,19 @@ DEFAULT_ENV_OPTIONS = dict( ENV=environ, UNIX_TIME=int(time()), PIOHOME_DIR=util.get_home_dir(), - PROJECT_DIR=util.get_project_dir(), - PROJECTINCLUDE_DIR=util.get_projectinclude_dir(), - PROJECTSRC_DIR=util.get_projectsrc_dir(), - PROJECTTEST_DIR=util.get_projecttest_dir(), - PROJECTDATA_DIR=util.get_projectdata_dir(), - PROJECTBUILD_DIR=util.get_projectbuild_dir(), + PROJECT_DIR=get_project_dir(), + PROJECTINCLUDE_DIR=get_projectinclude_dir(), + PROJECTSRC_DIR=get_projectsrc_dir(), + PROJECTTEST_DIR=get_projecttest_dir(), + PROJECTDATA_DIR=get_projectdata_dir(), + PROJECTBUILD_DIR=get_projectbuild_dir(), BUILD_DIR=join("$PROJECTBUILD_DIR", "$PIOENV"), BUILDSRC_DIR=join("$BUILD_DIR", "src"), BUILDTEST_DIR=join("$BUILD_DIR", "test"), LIBPATH=["$BUILD_DIR"], LIBSOURCE_DIRS=[ - util.get_projectlib_dir(), - util.get_projectlibdeps_dir(), + get_projectlib_dir(), + get_projectlibdeps_dir(), join("$PIOHOME_DIR", "lib") ], PROGNAME="program", @@ -156,10 +160,10 @@ for var in ("BUILD_FLAGS", "SRC_BUILD_FLAGS", "SRC_FILTER", "EXTRA_SCRIPTS", env.Append(**{var: util.parse_conf_multi_values(environ.get(k))}) # Configure extra library source directories for LDF -if util.get_project_optional_dir("lib_extra_dirs"): +if get_project_optional_dir("lib_extra_dirs"): env.Prepend( LIBSOURCE_DIRS=util.parse_conf_multi_values( - util.get_project_optional_dir("lib_extra_dirs"))) + get_project_optional_dir("lib_extra_dirs"))) env.Prepend(LIBSOURCE_DIRS=env.get("LIB_EXTRA_DIRS", [])) env['LIBSOURCE_DIRS'] = [ expanduser(d) if d.startswith("~") else d for d in env['LIBSOURCE_DIRS'] diff --git a/platformio/builder/tools/piolib.py b/platformio/builder/tools/piolib.py index 0651eddd..e1a0b50b 100644 --- a/platformio/builder/tools/piolib.py +++ b/platformio/builder/tools/piolib.py @@ -46,8 +46,8 @@ class LibBuilderFactory(object): clsname = "PlatformIOLibBuilder" else: used_frameworks = LibBuilderFactory.get_used_frameworks(env, path) - common_frameworks = ( - set(env.get("PIOFRAMEWORK", [])) & set(used_frameworks)) + common_frameworks = (set(env.get("PIOFRAMEWORK", [])) + & set(used_frameworks)) if common_frameworks: clsname = "%sLibBuilder" % list(common_frameworks)[0].title() elif used_frameworks: diff --git a/platformio/commands/device.py b/platformio/commands/device.py index 42bd4f6c..e75660ea 100644 --- a/platformio/commands/device.py +++ b/platformio/commands/device.py @@ -215,4 +215,4 @@ def get_project_options(project_dir, environment=None): environment = default_envs[0] else: environment = config.envs()[0] - return {k: v for k, v in config.items(env=environment)} + return config.items(env=environment, as_dict=True) diff --git a/platformio/commands/init.py b/platformio/commands/init.py index f08a52c2..70f8a8e4 100644 --- a/platformio/commands/init.py +++ b/platformio/commands/init.py @@ -25,6 +25,9 @@ from platformio.commands.platform import \ from platformio.ide.projectgenerator import ProjectGenerator from platformio.managers.platform import PlatformManager from platformio.project.config import ProjectConfig +from platformio.project.helpers import ( + get_projectinclude_dir, get_projectlib_dir, get_projectsrc_dir, + get_projecttest_dir, is_platformio_project) def validate_boards(ctx, param, value): # pylint: disable=W0613 @@ -87,7 +90,7 @@ def cli( click.echo("%s - Project Configuration File" % click.style( "platformio.ini", fg="cyan")) - is_new_project = not util.is_platformio_project(project_dir) + is_new_project = not is_platformio_project(project_dir) if is_new_project: init_base_project(project_dir) @@ -96,10 +99,8 @@ def cli( ide is not None) if ide: - env_name = get_best_envname(project_dir, board) - if not env_name: - raise exception.BoardNotDefined() - pg = ProjectGenerator(project_dir, ide, env_name) + pg = ProjectGenerator(project_dir, ide, + get_best_envname(project_dir, board)) pg.generate() if is_new_project: @@ -130,27 +131,34 @@ def cli( def get_best_envname(project_dir, boards=None): config = ProjectConfig(join(project_dir, "platformio.ini")) config.validate() + + envname = None default_envs = config.default_envs() if default_envs: - return default_envs[0] - section = None - for section in config.sections(): - if not section.startswith("env:"): - continue - elif config.has_option(section, "board") and (not boards or config.get( - section, "board") in boards): - break - return section[4:] if section else None + envname = default_envs[0] + if not boards: + return envname + + for env in config.envs(): + if not boards: + return env + if not envname: + envname = env + items = config.items(env=env, as_dict=True) + if "board" in items and items.get("board") in boards: + return env + + return envname def init_base_project(project_dir): ProjectConfig(join(project_dir, "platformio.ini")).save() with util.cd(project_dir): dir_to_readme = [ - (util.get_projectsrc_dir(), None), - (util.get_projectinclude_dir(), init_include_readme), - (util.get_projectlib_dir(), init_lib_readme), - (util.get_projecttest_dir(), init_test_readme), + (get_projectsrc_dir(), None), + (get_projectinclude_dir(), init_include_readme), + (get_projectlib_dir(), init_lib_readme), + (get_projecttest_dir(), init_test_readme), ] for (path, cb) in dir_to_readme: if isdir(path): diff --git a/platformio/commands/lib.py b/platformio/commands/lib.py index 2f09cd9c..7caf1271 100644 --- a/platformio/commands/lib.py +++ b/platformio/commands/lib.py @@ -22,7 +22,8 @@ import click from platformio import exception, util from platformio.managers.lib import LibraryManager, get_builtin_libs -from platformio.util import get_api_result +from platformio.project.helpers import ( + get_project_dir, get_projectlibdeps_dir, is_platformio_project) try: from urllib.parse import quote @@ -58,8 +59,8 @@ def cli(ctx, **options): if not storage_dir: if options['global']: storage_dir = join(util.get_home_dir(), "lib") - elif util.is_platformio_project(): - storage_dir = util.get_projectlibdeps_dir() + elif is_platformio_project(): + storage_dir = get_projectlibdeps_dir() elif util.is_ci(): storage_dir = join(util.get_home_dir(), "lib") click.secho( @@ -67,12 +68,12 @@ def cli(ctx, **options): "Please use `platformio lib --global %s` command to remove " "this warning." % ctx.invoked_subcommand, fg="yellow") - elif util.is_platformio_project(storage_dir): + elif is_platformio_project(storage_dir): with util.cd(storage_dir): - storage_dir = util.get_projectlibdeps_dir() + storage_dir = get_projectlibdeps_dir() - if not storage_dir and not util.is_platformio_project(): - raise exception.NotGlobalLibDir(util.get_project_dir(), + if not storage_dir and not is_platformio_project(): + raise exception.NotGlobalLibDir(get_project_dir(), join(util.get_home_dir(), "lib"), ctx.invoked_subcommand) @@ -211,7 +212,7 @@ def lib_search(query, json_output, page, noninteractive, **filters): for value in values: query.append('%s:"%s"' % (key, value)) - result = get_api_result( + result = util.get_api_result( "/v2/lib/search", dict(query=" ".join(query), page=page), cache_valid="1d") @@ -258,7 +259,7 @@ def lib_search(query, json_output, page, noninteractive, **filters): time.sleep(5) elif not click.confirm("Show next libraries?"): break - result = get_api_result( + result = util.get_api_result( "/v2/lib/search", { "query": " ".join(query), "page": int(result['page']) + 1 @@ -317,7 +318,7 @@ def lib_show(library, json_output): }, silent=json_output, interactive=not json_output) - lib = get_api_result("/lib/info/%d" % lib_id, cache_valid="1d") + lib = util.get_api_result("/lib/info/%d" % lib_id, cache_valid="1d") if json_output: return click.echo(json.dumps(lib)) @@ -393,7 +394,8 @@ def lib_register(config_url): and not config_url.startswith("https://")): raise exception.InvalidLibConfURL(config_url) - result = get_api_result("/lib/register", data=dict(config_url=config_url)) + result = util.get_api_result( + "/lib/register", data=dict(config_url=config_url)) if "message" in result and result['message']: click.secho( result['message'], @@ -404,7 +406,7 @@ def lib_register(config_url): @cli.command("stats", short_help="Library Registry Statistics") @click.option("--json-output", is_flag=True) def lib_stats(json_output): - result = get_api_result("/lib/stats", cache_valid="1h") + result = util.get_api_result("/lib/stats", cache_valid="1h") if json_output: return click.echo(json.dumps(result)) diff --git a/platformio/commands/run.py b/platformio/commands/run.py index baff6a54..17f088da 100644 --- a/platformio/commands/run.py +++ b/platformio/commands/run.py @@ -12,14 +12,13 @@ # See the License for the specific language governing permissions and # limitations under the License. -from hashlib import sha1 -from os import getcwd, makedirs, walk +from os import getcwd, makedirs from os.path import getmtime, isdir, isfile, join from time import time import click -from platformio import __version__, exception, telemetry, util +from platformio import exception, telemetry, util from platformio.commands.device import device_monitor as cmd_device_monitor from platformio.commands.lib import lib_install as cmd_lib_install from platformio.commands.platform import \ @@ -27,6 +26,9 @@ from platformio.commands.platform import \ from platformio.managers.lib import LibraryManager, is_builtin_lib from platformio.managers.platform import PlatformFactory from platformio.project.config import ProjectConfig +from platformio.project.helpers import ( + calculate_project_hash, find_project_dir_above, get_project_dir, + get_projectbuild_dir, get_projectlibdeps_dir) # pylint: disable=too-many-arguments,too-many-locals,too-many-branches @@ -53,18 +55,18 @@ def cli(ctx, environment, target, upload_port, project_dir, silent, verbose, disable_auto_clean): # find project directory on upper level if isfile(project_dir): - project_dir = util.find_project_dir_above(project_dir) + project_dir = find_project_dir_above(project_dir) with util.cd(project_dir): # clean obsolete build dir if not disable_auto_clean: try: - _clean_build_dir(util.get_projectbuild_dir()) + _clean_build_dir(get_projectbuild_dir()) except: # pylint: disable=bare-except click.secho( "Can not remove temporary directory `%s`. Please remove " "it manually to avoid build issues" % - util.get_projectbuild_dir(force=True), + get_projectbuild_dir(force=True), fg="yellow") config = ProjectConfig.get_instance( @@ -86,9 +88,7 @@ def cli(ctx, environment, target, upload_port, project_dir, silent, verbose, if not silent and results: click.echo() - options = {} - for k, v in config.items(env=envname): - options[k] = v + options = config.items(env=envname, as_dict=True) if "piotest" not in options and "piotest" in ctx.meta: options['piotest'] = ctx.meta['piotest'] @@ -239,7 +239,7 @@ class EnvironmentProcessor(object): def _autoinstall_libdeps(ctx, libraries, verbose=False): if not libraries: return - storage_dir = util.get_projectlibdeps_dir() + storage_dir = get_projectlibdeps_dir() ctx.obj = LibraryManager(storage_dir) if verbose: click.echo("Library Storage: " + storage_dir) @@ -258,9 +258,8 @@ def _clean_build_dir(build_dir): proj_hash = calculate_project_hash() # if project's config is modified - if (isdir(build_dir) - and getmtime(join(util.get_project_dir(), - "platformio.ini")) > getmtime(build_dir)): + if (isdir(build_dir) and getmtime( + join(get_project_dir(), "platformio.ini")) > getmtime(build_dir)): util.rmtree_(build_dir) # check project structure @@ -323,23 +322,3 @@ def check_project_envs(config, environments=None): # FIXME: Remove if unknown: raise exception.UnknownEnvNames(", ".join(unknown), ", ".join(known)) return True - - -def calculate_project_hash(): - check_suffixes = (".c", ".cc", ".cpp", ".h", ".hpp", ".s", ".S") - chunks = [__version__] - for d in (util.get_projectsrc_dir(), util.get_projectlib_dir()): - if not isdir(d): - continue - for root, _, files in walk(d): - for f in files: - path = join(root, f) - if path.endswith(check_suffixes): - chunks.append(path) - chunks_to_str = ",".join(sorted(chunks)) - if "windows" in util.get_systype(): - # Fix issue with useless project rebuilding for case insensitive FS. - # A case of disk drive can differ... - chunks_to_str = chunks_to_str.lower() - return sha1( - chunks_to_str if util.PY2 else chunks_to_str.encode()).hexdigest() diff --git a/platformio/exception.py b/platformio/exception.py index 26131a5d..4c4af06f 100644 --- a/platformio/exception.py +++ b/platformio/exception.py @@ -68,13 +68,6 @@ class PlatformNotInstalledYet(PlatformioException): "Use `platformio platform install {0}` command") -class BoardNotDefined(PlatformioException): - - MESSAGE = ( - "You need to specify board ID using `-b` or `--board` option. " - "Supported boards list is available via `platformio boards` command") - - class UnknownBoard(PlatformioException): MESSAGE = "Unknown board ID '{0}'" diff --git a/platformio/ide/projectgenerator.py b/platformio/ide/projectgenerator.py index 26774a70..9cbf3028 100644 --- a/platformio/ide/projectgenerator.py +++ b/platformio/ide/projectgenerator.py @@ -24,6 +24,8 @@ from click.testing import CliRunner from platformio import exception, util from platformio.commands.run import cli as cmd_run from platformio.project.config import ProjectConfig +from platformio.project.helpers import ( + get_projectlib_dir, get_projectlibdeps_dir, get_projectsrc_dir) class ProjectGenerator(object): @@ -50,9 +52,8 @@ class ProjectGenerator(object): for env in config.envs(): if self.env_name != env: continue - data = {"env_name": self.env_name} - for k, v in config.items(env=env): - data[k] = v + data = config.items(env=env, as_dict=True) + data['env_name'] = self.env_name return data def get_project_build_data(self): @@ -89,7 +90,7 @@ class ProjectGenerator(object): def get_src_files(self): result = [] with util.cd(self.project_dir): - for root, _, files in os.walk(util.get_projectsrc_dir()): + for root, _, files in os.walk(get_projectsrc_dir()): for f in files: result.append(relpath(join(root, f))) return result @@ -141,9 +142,9 @@ class ProjectGenerator(object): "src_files": self.get_src_files(), "user_home_dir": abspath(expanduser("~")), "project_dir": self.project_dir, - "project_src_dir": util.get_projectsrc_dir(), - "project_lib_dir": util.get_projectlib_dir(), - "project_libdeps_dir": util.get_projectlibdeps_dir(), + "project_src_dir": get_projectsrc_dir(), + "project_lib_dir": get_projectlib_dir(), + "project_libdeps_dir": get_projectlibdeps_dir(), "systype": util.get_systype(), "platformio_path": self._fix_os_path( sys.argv[0] if isfile(sys.argv[0]) diff --git a/platformio/managers/platform.py b/platformio/managers/platform.py index 851011a9..bfcda3f2 100644 --- a/platformio/managers/platform.py +++ b/platformio/managers/platform.py @@ -25,6 +25,7 @@ import semantic_version from platformio import __version__, app, exception, util from platformio.managers.core import get_core_package_dir from platformio.managers.package import BasePkgManager, PackageManager +from platformio.project.helpers import get_projectboards_dir try: from urllib.parse import quote @@ -566,7 +567,7 @@ class PlatformBase( # pylint: disable=too-many-public-methods self._BOARDS_CACHE[board_id] = config bdirs = [ - util.get_projectboards_dir(), + get_projectboards_dir(), join(util.get_home_dir(), "boards"), join(self.get_dir(), "boards"), ] diff --git a/platformio/project/config.py b/platformio/project/config.py index 46a99425..737ea89a 100644 --- a/platformio/project/config.py +++ b/platformio/project/config.py @@ -26,8 +26,7 @@ try: except ImportError: import configparser as ConfigParser -CONFIG_HEADER = """ -; PlatformIO Project Configuration File +CONFIG_HEADER = """;PlatformIO Project Configuration File ; ; Build options: build flags, source filter ; Upload options: custom upload port, speed and extra flags @@ -36,6 +35,7 @@ CONFIG_HEADER = """ ; ; Please visit documentation for the other options and examples ; https://docs.platformio.org/page/projectconf.html + """ KNOWN_PLATFORMIO_OPTIONS = [ @@ -200,10 +200,15 @@ class ProjectConfig(object): section = "env:" + env return self._parser.options(section) - def items(self, section=None, env=None): + def items(self, section=None, env=None, as_dict=False): assert section or env if not section: section = "env:" + env + if as_dict: + return { + option: self.get(section, option) + for option in self.options(section) + } return [(option, self.get(section, option)) for option in self.options(section)] @@ -298,7 +303,6 @@ class ProjectConfig(object): return True def save(self, path=None): - with open(path or self.path, "wb") as fp: - fp.write(CONFIG_HEADER.strip()) - fp.write("\n\n") + with open(path or self.path, "w") as fp: + fp.write(CONFIG_HEADER) self._parser.write(fp) diff --git a/platformio/project/helpers.py b/platformio/project/helpers.py new file mode 100644 index 00000000..d7c19595 --- /dev/null +++ b/platformio/project/helpers.py @@ -0,0 +1,139 @@ +# Copyright (c) 2014-present PlatformIO +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import sys +from hashlib import sha1 +from os import walk +from os.path import abspath, dirname, expanduser, isdir, isfile, join + +from platformio import __version__ +from platformio.project.config import ProjectConfig + +PY2 = sys.version_info[0] == 2 + + +def get_project_dir(): + return os.getcwd() + + +def is_platformio_project(project_dir=None): + if not project_dir: + project_dir = get_project_dir() + return isfile(join(project_dir, "platformio.ini")) + + +def find_project_dir_above(path): + if isfile(path): + path = dirname(path) + if is_platformio_project(path): + return path + if isdir(dirname(path)): + return find_project_dir_above(dirname(path)) + return None + + +def get_project_optional_dir(name, default=None): + paths = None + var_name = "PLATFORMIO_%s" % name.upper() + if var_name in os.environ: + paths = os.getenv(var_name) + else: + config = ProjectConfig.get_instance( + join(get_project_dir(), "platformio.ini")) + if (config.has_section("platformio") + and config.has_option("platformio", name)): + paths = config.get("platformio", name) + if not paths: + return default + + items = [] + for item in paths.split(", "): + if item.startswith("~"): + item = expanduser(item) + items.append(abspath(item)) + paths = ", ".join(items) + + while "$PROJECT_HASH" in paths: + project_dir = get_project_dir() + paths = paths.replace( + "$PROJECT_HASH", + sha1(project_dir if PY2 else project_dir.encode()).hexdigest() + [:10]) + + return paths + + +def get_projectlib_dir(): + return get_project_optional_dir("lib_dir", join(get_project_dir(), "lib")) + + +def get_projectlibdeps_dir(): + return get_project_optional_dir("libdeps_dir", + join(get_project_dir(), ".piolibdeps")) + + +def get_projectsrc_dir(): + return get_project_optional_dir("src_dir", join(get_project_dir(), "src")) + + +def get_projectinclude_dir(): + return get_project_optional_dir("include_dir", + join(get_project_dir(), "include")) + + +def get_projecttest_dir(): + return get_project_optional_dir("test_dir", join(get_project_dir(), + "test")) + + +def get_projectboards_dir(): + return get_project_optional_dir("boards_dir", + join(get_project_dir(), "boards")) + + +def get_projectbuild_dir(force=False): + path = get_project_optional_dir("build_dir", + join(get_project_dir(), ".pioenvs")) + try: + if not isdir(path): + os.makedirs(path) + except Exception as e: # pylint: disable=broad-except + if not force: + raise Exception(e) + return path + + +def get_projectdata_dir(): + return get_project_optional_dir("data_dir", join(get_project_dir(), + "data")) + + +def calculate_project_hash(): + check_suffixes = (".c", ".cc", ".cpp", ".h", ".hpp", ".s", ".S") + chunks = [__version__] + for d in (get_projectsrc_dir(), get_projectlib_dir()): + if not isdir(d): + continue + for root, _, files in walk(d): + for f in files: + path = join(root, f) + if path.endswith(check_suffixes): + chunks.append(path) + chunks_to_str = ",".join(sorted(chunks)) + if sys.platform == "win32": + # Fix issue with useless project rebuilding for case insensitive FS. + # A case of disk drive can differ... + chunks_to_str = chunks_to_str.lower() + return sha1(chunks_to_str if PY2 else chunks_to_str.encode()).hexdigest() diff --git a/platformio/util.py b/platformio/util.py index 8df17ec9..a68d7607 100644 --- a/platformio/util.py +++ b/platformio/util.py @@ -12,6 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. +# pylint: disable=too-many-ancestors + import json import os import platform @@ -23,7 +25,6 @@ import sys import time from functools import wraps from glob import glob -from hashlib import sha1 from os.path import (abspath, basename, dirname, expanduser, isdir, isfile, join, normpath, splitdrive) from shutil import rmtree @@ -34,8 +35,12 @@ import requests from platformio import __apiurl__, __version__, exception from platformio.project.config import ProjectConfig +from platformio.project.helpers import ( # pylint: disable=unused-import + get_project_dir, get_project_optional_dir, get_projectboards_dir, + get_projectbuild_dir, get_projectlib_dir, get_projectsrc_dir, + get_projecttest_dir, is_platformio_project) -# pylint: disable=too-many-ancestors +# FIXME: check platformio.project.helpers imports PY2 = sys.version_info[0] == 2 if PY2: @@ -173,37 +178,6 @@ def pioversion_to_intstr(): return [int(i) for i in vermatch.group(1).split(".")[:3]] -def get_project_optional_dir(name, default=None): - paths = None - var_name = "PLATFORMIO_%s" % name.upper() - if var_name in os.environ: - paths = os.getenv(var_name) - else: - config = ProjectConfig.get_instance( - join(get_project_dir(), "platformio.ini")) - if (config.has_section("platformio") - and config.has_option("platformio", name)): - paths = config.get("platformio", name) - if not paths: - return default - - items = [] - for item in paths.split(", "): - if item.startswith("~"): - item = expanduser(item) - items.append(abspath(item)) - paths = ", ".join(items) - - while "$PROJECT_HASH" in paths: - project_dir = get_project_dir() - paths = paths.replace( - "$PROJECT_HASH", - sha1(project_dir if PY2 else project_dir.encode()).hexdigest() - [:10]) - - return paths - - def get_home_dir(): home_dir = get_project_optional_dir("home_dir", join(expanduser("~"), ".platformio")) @@ -240,75 +214,6 @@ def get_source_dir(): return dirname(curpath) -def get_project_dir(): - return os.getcwd() - - -def find_project_dir_above(path): - if isfile(path): - path = dirname(path) - if is_platformio_project(path): - return path - if isdir(dirname(path)): - return find_project_dir_above(dirname(path)) - return None - - -def is_platformio_project(project_dir=None): - if not project_dir: - project_dir = get_project_dir() - return isfile(join(project_dir, "platformio.ini")) - - -def get_projectlib_dir(): - return get_project_optional_dir("lib_dir", join(get_project_dir(), "lib")) - - -def get_projectlibdeps_dir(): - return get_project_optional_dir("libdeps_dir", - join(get_project_dir(), ".piolibdeps")) - - -def get_projectsrc_dir(): - return get_project_optional_dir("src_dir", join(get_project_dir(), "src")) - - -def get_projectinclude_dir(): - return get_project_optional_dir("include_dir", - join(get_project_dir(), "include")) - - -def get_projecttest_dir(): - return get_project_optional_dir("test_dir", join(get_project_dir(), - "test")) - - -def get_projectboards_dir(): - return get_project_optional_dir("boards_dir", - join(get_project_dir(), "boards")) - - -def get_projectbuild_dir(force=False): - path = get_project_optional_dir("build_dir", - join(get_project_dir(), ".pioenvs")) - try: - if not isdir(path): - os.makedirs(path) - except Exception as e: # pylint: disable=broad-except - if not force: - raise Exception(e) - return path - - -# compatibility with PIO Core+ -get_projectpioenvs_dir = get_projectbuild_dir - - -def get_projectdata_dir(): - return get_project_optional_dir("data_dir", join(get_project_dir(), - "data")) - - def load_project_config(path=None): # FIXME: Remove if not path or isdir(path): path = join(path or get_project_dir(), "platformio.ini") diff --git a/tests/commands/test_init.py b/tests/commands/test_init.py index eecb25f3..1d7d699e 100644 --- a/tests/commands/test_init.py +++ b/tests/commands/test_init.py @@ -58,7 +58,7 @@ def test_init_ide_without_board(clirunner, tmpdir): with tmpdir.as_cwd(): result = clirunner.invoke(cmd_init, ["--ide", "atom"]) assert result.exit_code == -1 - assert isinstance(result.exception, exception.BoardNotDefined) + assert isinstance(result.exception, exception.ProjectEnvsNotAvailable) def test_init_ide_atom(clirunner, validate_cliresult, tmpdir):