diff --git a/idf_component_tools/manifest/models.py b/idf_component_tools/manifest/models.py index 02e833d..081799a 100644 --- a/idf_component_tools/manifest/models.py +++ b/idf_component_tools/manifest/models.py @@ -135,7 +135,11 @@ class DependencyItem(BaseModel): path: str = None # type: ignore git: str = None # type: ignore registry_url: str = Field( - default=None, validation_alias=AliasChoices('service_url', 'registry_url') + default=None, + validation_alias=AliasChoices( + 'registry_url', + 'service_url', + ), ) # type: ignore rules: t.List[OptionalDependency] = None # type: ignore matches: t.List[OptionalDependency] = None # type: ignore diff --git a/idf_component_tools/manifest/schemas.py b/idf_component_tools/manifest/schemas.py index 161aae6..ffb4474 100644 --- a/idf_component_tools/manifest/schemas.py +++ b/idf_component_tools/manifest/schemas.py @@ -12,6 +12,12 @@ # `if` is aliased MANIFEST_JSON_SCHEMA = Manifest.model_json_schema(by_alias=True) +# we have one rename in the manifest model +# dependencies-*-service_url-type:string -> dependencies-*-registry_url-type:string +# manually add it in the json schema +MANIFEST_JSON_SCHEMA['$defs']['DependencyItem']['properties']['service_url'] = MANIFEST_JSON_SCHEMA[ + '$defs' +]['DependencyItem']['properties']['registry_url'] def _flatten_json_schema_keys(schema, stack=None): diff --git a/idf_component_tools/sources/web_service.py b/idf_component_tools/sources/web_service.py index 175dce3..e447ca7 100644 --- a/idf_component_tools/sources/web_service.py +++ b/idf_component_tools/sources/web_service.py @@ -97,7 +97,10 @@ def download_archive(url: str, download_dir: str, save_original_filename: bool = class WebServiceSource(BaseSource): registry_url: str = Field( default=IDF_COMPONENT_REGISTRY_URL, - validation_alias=AliasChoices('service_url', 'registry_url'), + validation_alias=AliasChoices( + 'registry_url', + 'service_url', + ), ) # type: ignore type: Literal['service'] = 'service' # type: ignore pre_release: bool = None # type: ignore diff --git a/tests/test_prepare_dep_dirs.py b/tests/test_prepare_dep_dirs.py new file mode 100644 index 0000000..18767cc --- /dev/null +++ b/tests/test_prepare_dep_dirs.py @@ -0,0 +1,58 @@ +# SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD +# SPDX-License-Identifier: Apache-2.0 +import os +import textwrap +from pathlib import Path + +import yaml + +from idf_component_manager.core import ComponentManager +from idf_component_manager.prepare_components.prepare import _component_list_file + + +def _generate_lock_file(project_dir: Path, yaml_str: str, build_dir: str = 'build'): + managed_components_list_file = project_dir / build_dir / 'managed_components_list.temp.cmake' + local_components_list_file = project_dir / build_dir / 'local_components_list.temp.yml' + + os.makedirs(project_dir / 'main') + (project_dir / 'main' / 'CMakeLists.txt').touch() + + (project_dir / 'main' / 'idf_component.yml').write_text(textwrap.dedent(yaml_str)) + + os.makedirs(project_dir / build_dir) + + ComponentManager( + path=str(project_dir), + interface_version=2, + ).prepare_dep_dirs( + managed_components_list_file=str(managed_components_list_file), + component_list_file=_component_list_file('build'), + local_components_list_file=str(local_components_list_file), + ) + + +def test_dependencies_with_registry_url(tmp_path, monkeypatch): + monkeypatch.setenv('CI_TESTING_IDF_VERSION', '5.4.0') + monkeypatch.setenv('IDF_TARGET', 'esp32') + monkeypatch.setenv('IDF_PATH', '/tmp') + + _generate_lock_file( + tmp_path, + """ + dependencies: + example/cmp: + version: "*" + registry_url: "https://components-staging.espressif.com" + """, + ) + + assert (tmp_path / 'dependencies.lock').exists() + with open(tmp_path / 'dependencies.lock') as f: + lock_data = yaml.safe_load(f) + + assert lock_data['dependencies']['example/cmp'] + assert ( + lock_data['dependencies']['example/cmp']['source']['registry_url'] + == 'https://components-staging.espressif.com' + ) + assert lock_data['dependencies']['example/cmp']['source']['type'] == 'service'