From ee0341e137f6a8dcf90d5a744e334f66b9d6d60a Mon Sep 17 00:00:00 2001 From: Evgeny Zinoviev Date: Sun, 11 Jun 2023 01:34:08 +0300 Subject: fix platformio.ini generation --- bin/pio_ini.py | 26 +++++++++++++++++--------- include/py/homekit/config/__init__.py | 3 ++- include/py/homekit/pio/products.py | 4 ++-- 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/bin/pio_ini.py b/bin/pio_ini.py index 34ad395..2926234 100755 --- a/bin/pio_ini.py +++ b/bin/pio_ini.py @@ -8,17 +8,19 @@ from pprint import pprint from argparse import ArgumentParser, ArgumentError from homekit.pio import get_products, platformio_ini from homekit.pio.exceptions import ProductConfigNotFoundError +from homekit.config import CONFIG_DIRECTORIES def get_config(product: str) -> dict: - config_path = os.path.join( - os.getenv('HOME'), '.config', - 'homekit_pio', f'{product}.yaml' - ) - if not os.path.exists(config_path): - raise ProductConfigNotFoundError(f'{config_path}: product config not found') - - with open(config_path, 'r') as f: + path = None + for directory in CONFIG_DIRECTORIES: + config_path = os.path.join(directory, 'pio', f'{product}.yaml') + if os.path.exists(config_path) and os.path.isfile(config_path): + path = config_path + break + if not path: + raise ProductConfigNotFoundError(f'pio/{product}.yaml not found') + with open(path, 'r') as f: return yaml.safe_load(f) @@ -83,7 +85,8 @@ def bsd_get(product_config: dict, defines[f'CONFIG_{define_name}'] = f'HOMEKIT_{attr_value.upper()}' return if kwargs['type'] == 'bool': - defines[f'CONFIG_{define_name}'] = True + if attr_value is True: + defines[f'CONFIG_{define_name}'] = True return defines[f'CONFIG_{define_name}'] = str(attr_value) bsd_walk(product_config, f) @@ -124,6 +127,11 @@ if __name__ == '__main__': raise ArgumentError(None, f'target {arg.target} not found for product {product}') bsd, bsd_enums = bsd_get(product_config, arg) + print('>>> bsd:') + pprint(bsd) + print('>>> bsd_enums:') + pprint(bsd_enums) + ini = platformio_ini(product_config=product_config, target=arg.target, build_specific_defines=bsd, diff --git a/include/py/homekit/config/__init__.py b/include/py/homekit/config/__init__.py index 2fa5214..8fedfa6 100644 --- a/include/py/homekit/config/__init__.py +++ b/include/py/homekit/config/__init__.py @@ -5,7 +5,8 @@ from .config import ( Translation, config, is_development_mode, - setup_logging + setup_logging, + CONFIG_DIRECTORIES ) from ._configs import ( LinuxBoardsConfig, diff --git a/include/py/homekit/pio/products.py b/include/py/homekit/pio/products.py index 388da03..c4fcd73 100644 --- a/include/py/homekit/pio/products.py +++ b/include/py/homekit/pio/products.py @@ -8,8 +8,8 @@ from collections import OrderedDict _logger = logging.getLogger(__name__) _products_dir = os.path.join( os.path.dirname(__file__), - '..', '..', '..', - 'platformio' + '..', '..', '..', '..', + 'pio' ) -- cgit v1.2.3