Skip to content

Commit

Permalink
Merge pull request #156 from espressif/fix/small_fixes
Browse files Browse the repository at this point in the history
Fix/small fixes
  • Loading branch information
hfudev authored Sep 10, 2024
2 parents d1eec0b + 44ec035 commit cee8538
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 38 deletions.
3 changes: 0 additions & 3 deletions docs/conf_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,6 @@
# use fixed version instead
mermaid_version = '10.6.1'

# building docs
os.environ['BUILDING_DOCS'] = '1'

autodoc_default_options = {
'members': True,
'member-order': 'bysource',
Expand Down
6 changes: 2 additions & 4 deletions idf_build_apps/args.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
from .utils import (
InvalidCommand,
Self,
drop_none_kwargs,
files_matches_patterns,
semicolon_separated_str_to_list,
to_absolute_path,
Expand Down Expand Up @@ -907,9 +908,6 @@ def add_arguments_to_parser(argument_cls: t.Type[GlobalArguments], parser: argpa
def _snake_case_to_cli_arg_name(s: str) -> str:
return f'--{s.replace("_", "-")}'

def _drop_none(d: dict) -> dict:
return {k: v for k, v in d.items() if v is not None}

for name, f in name_fields_dict.items():
_meta = FieldMetadata(**f.metadata)

Expand All @@ -930,7 +928,7 @@ def _drop_none(d: dict) -> dict:
args.append(_meta.shorthand)

# kwargs passed to add_argument
kwargs = _drop_none(
kwargs = drop_none_kwargs(
{
'help': desp,
'action': _meta.action,
Expand Down
45 changes: 17 additions & 28 deletions idf_build_apps/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import os
import re
import sys
import tempfile
import typing as t

from .utils import (
Expand All @@ -16,35 +15,27 @@

LOGGER = logging.getLogger(__name__)

_BUILDING_DOCS = bool(os.getenv('BUILDING_DOCS'))
if _BUILDING_DOCS:
print('Building Docs... Faking lots of constant values')


if _BUILDING_DOCS:
_idf_env = tempfile.gettempdir()
else:
_idf_env = os.getenv('IDF_PATH') or ''
if not _idf_env:
raise SystemExit('environment variable IDF_PATH must be set')


_idf_env = os.getenv('IDF_PATH') or ''
if not _idf_env:
LOGGER.warning('IDF_PATH environment variable is not set. Entering test mode...')
LOGGER.warning('- Setting IDF_PATH to current directory...')
IDF_PATH = os.path.abspath(_idf_env)
IDF_PY = os.path.join(IDF_PATH, 'tools', 'idf.py')
IDF_SIZE_PY = os.path.join(IDF_PATH, 'tools', 'idf_size.py')
PROJECT_DESCRIPTION_JSON = 'project_description.json'
DEFAULT_SDKCONFIG = 'sdkconfig.defaults'


sys.path.append(os.path.join(IDF_PATH, 'tools', 'idf_py_actions'))
if _BUILDING_DOCS:
_idf_py_constant_py = object()
else:
try:
_idf_py_constant_py = importlib.import_module('constants')
except ModuleNotFoundError:
LOGGER.warning('Cannot import constants from idf_py_actions')
_idf_py_constant_py = object()
_idf_py_actions = os.path.join(IDF_PATH, 'tools', 'idf_py_actions')
sys.path.append(_idf_py_actions)
try:
_idf_py_constant_py = importlib.import_module('constants')
except ModuleNotFoundError:
LOGGER.warning(
'- Set supported/preview targets to empty list... (ESP-IDF constants.py module not found under %s)',
_idf_py_actions,
)
_idf_py_constant_py = object() # type: ignore
SUPPORTED_TARGETS = getattr(_idf_py_constant_py, 'SUPPORTED_TARGETS', [])
PREVIEW_TARGETS = getattr(_idf_py_constant_py, 'PREVIEW_TARGETS', [])
ALL_TARGETS = SUPPORTED_TARGETS + PREVIEW_TARGETS
Expand All @@ -53,7 +44,8 @@
def _idf_version_from_cmake() -> t.Tuple[int, int, int]:
version_path = os.path.join(IDF_PATH, 'tools', 'cmake', 'version.cmake')
if not os.path.isfile(version_path):
raise ValueError(f'File {version_path} does not exist')
LOGGER.warning('- Setting ESP-IDF version to 1.0.0... (ESP-IDF version.cmake not exists at %s)', version_path)
return 1, 0, 0

regex = re.compile(r'^\s*set\s*\(\s*IDF_VERSION_([A-Z]{5})\s+(\d+)')
ver = {}
Expand All @@ -70,10 +62,7 @@ def _idf_version_from_cmake() -> t.Tuple[int, int, int]:
raise ValueError(f'Cannot find ESP-IDF version in {version_path}')


if _BUILDING_DOCS:
IDF_VERSION_MAJOR, IDF_VERSION_MINOR, IDF_VERSION_PATCH = 1, 0, 0
else:
IDF_VERSION_MAJOR, IDF_VERSION_MINOR, IDF_VERSION_PATCH = _idf_version_from_cmake()
IDF_VERSION_MAJOR, IDF_VERSION_MINOR, IDF_VERSION_PATCH = _idf_version_from_cmake()

IDF_VERSION = to_version(f'{IDF_VERSION_MAJOR}.{IDF_VERSION_MINOR}.{IDF_VERSION_PATCH}')

Expand Down
7 changes: 4 additions & 3 deletions idf_build_apps/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
from .utils import (
AutocompleteActivationError,
InvalidCommand,
drop_none_kwargs,
get_parallel_start_stop,
to_list,
)
Expand Down Expand Up @@ -343,14 +344,14 @@ def main():
sys.exit(0)

if args.action == 'dump-manifest-sha':
arguments = DumpManifestShaArguments.from_dict(vars(args))
arguments = DumpManifestShaArguments.from_dict(drop_none_kwargs(vars(args)))
Manifest.from_files(arguments.manifest_files).dump_sha_values(arguments.output)
sys.exit(0)

if args.action == 'find':
arguments = FindArguments.from_dict(vars(args))
arguments = FindArguments.from_dict(drop_none_kwargs(vars(args)))
else:
arguments = BuildArguments.from_dict(vars(args))
arguments = BuildArguments.from_dict(drop_none_kwargs(vars(args)))

# real call starts here
# build also needs to find first
Expand Down
4 changes: 4 additions & 0 deletions idf_build_apps/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,3 +383,7 @@ def __hash__(self) -> int:
hash_list.append(v)

return hash((type(self), *tuple(hash_list)))


def drop_none_kwargs(d: dict) -> dict:
return {k: v for k, v in d.items() if v is not None}

0 comments on commit cee8538

Please sign in to comment.