Skip to content

Commit

Permalink
Merge branch 'fix/dependencies_with_registry_url' into 'main'
Browse files Browse the repository at this point in the history
fix: dependency with registry_url unrecognized correctly

See merge request espressif/idf-component-manager!439
  • Loading branch information
kumekay committed Aug 21, 2024
2 parents d927cbd + be31fac commit 6aca574
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 2 deletions.
6 changes: 5 additions & 1 deletion idf_component_tools/manifest/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions idf_component_tools/manifest/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
5 changes: 4 additions & 1 deletion idf_component_tools/sources/web_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
58 changes: 58 additions & 0 deletions tests/test_prepare_dep_dirs.py
Original file line number Diff line number Diff line change
@@ -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'

0 comments on commit 6aca574

Please sign in to comment.