mirror of
https://github.com/esphome/esphome.git
synced 2026-06-24 12:53:26 +00:00
[espidf] Drop version field from generated idf_component.yml (#16511)
This commit is contained in:
committed by
Jesse Hills
parent
9fdad68138
commit
ecf823b871
@@ -2488,9 +2488,8 @@ def _write_sdkconfig():
|
||||
|
||||
def _platformio_library_to_dependency(library: Library) -> tuple[str, dict[str, str]]:
|
||||
dependency: dict[str, str] = {}
|
||||
name, version, path = generate_idf_component(library)
|
||||
name, _version, path = generate_idf_component(library)
|
||||
dependency["override_path"] = str(path)
|
||||
dependency["version"] = version
|
||||
return name, dependency
|
||||
|
||||
|
||||
|
||||
@@ -154,41 +154,6 @@ class IDFComponent:
|
||||
self.path = self.source.download(self.get_sanitized_name(), force=force)
|
||||
|
||||
|
||||
def _sanitize_version(version: str) -> str:
|
||||
"""
|
||||
Sanitize a version string by removing common requirement prefixes or a leading v.
|
||||
|
||||
Args:
|
||||
version: Version string to clean.
|
||||
|
||||
Returns:
|
||||
Cleaned version string without common requirement symbols.
|
||||
"""
|
||||
version = version.strip()
|
||||
|
||||
prefixes = (
|
||||
"^",
|
||||
"~=",
|
||||
"~",
|
||||
">=",
|
||||
"<=",
|
||||
"==",
|
||||
"!=",
|
||||
">",
|
||||
"<",
|
||||
"=",
|
||||
"v",
|
||||
"V",
|
||||
)
|
||||
|
||||
for p in prefixes:
|
||||
if version.startswith(p):
|
||||
version = version[len(p) :]
|
||||
break
|
||||
|
||||
return version.strip()
|
||||
|
||||
|
||||
def _get_package_from_pio_registry(
|
||||
username: str | None, pkgname: str, requirements: str
|
||||
) -> tuple[str, str, str | None, str | None]:
|
||||
@@ -396,7 +361,8 @@ def _convert_library_to_component(library: Library) -> IDFComponent:
|
||||
|
||||
# Repository is provided directly
|
||||
if library.repository:
|
||||
# Parse repository URL to extract name and version
|
||||
# Parse repository URL: path becomes the component name, fragment
|
||||
# becomes the git ref stored on GitSource.
|
||||
split_result = urlsplit(library.repository)
|
||||
if not split_result.fragment.strip():
|
||||
raise ValueError(f"Missing ref in URL {library.repository}")
|
||||
@@ -405,8 +371,10 @@ def _convert_library_to_component(library: Library) -> IDFComponent:
|
||||
name = str(split_result.path).strip("/")
|
||||
name = name.removesuffix(".git")
|
||||
|
||||
# Sanitize version
|
||||
version = _sanitize_version(split_result.fragment)
|
||||
# IDF Component Manager only accepts "*", a 40-char commit hash, or
|
||||
# semver here. The actual git ref is preserved in GitSource.ref;
|
||||
# override_path makes this field cosmetic at build time.
|
||||
version = "*"
|
||||
repository = urlunsplit(split_result._replace(fragment=""))
|
||||
|
||||
source = GitSource(str(repository), split_result.fragment)
|
||||
@@ -619,9 +587,6 @@ def generate_idf_component_yml(component: IDFComponent) -> str:
|
||||
if description:
|
||||
data["description"] = description
|
||||
|
||||
# Do not use the version from library.json/library.properties; it may be incorrect.
|
||||
data["version"] = component.version
|
||||
|
||||
repository = component.data.get("repository", {}).get("url", None)
|
||||
if repository:
|
||||
data["repository"] = repository
|
||||
@@ -631,20 +596,11 @@ def generate_idf_component_yml(component: IDFComponent) -> str:
|
||||
if "dependencies" not in data:
|
||||
data["dependencies"] = {}
|
||||
|
||||
# Add this dependency to dependencies
|
||||
dep = {}
|
||||
dep["version"] = dependency.version
|
||||
|
||||
# Should use dependency.path as override path
|
||||
try:
|
||||
dep["override_path"] = str(dependency.path)
|
||||
except RuntimeError as e:
|
||||
# No local path: only a GitSource can substitute its URL.
|
||||
if not isinstance(dependency.source, GitSource):
|
||||
raise e
|
||||
dep["git"] = dependency.source.url
|
||||
|
||||
data["dependencies"][dependency.get_sanitized_name()] = dep
|
||||
# Every dependency goes through _generate_idf_component →
|
||||
# component.download() before this runs, so .path is always set.
|
||||
data["dependencies"][dependency.get_sanitized_name()] = {
|
||||
"override_path": str(dependency.path),
|
||||
}
|
||||
|
||||
return yaml_util.dump(data)
|
||||
|
||||
|
||||
@@ -203,7 +203,7 @@ def test_generate_idf_component_yml_basic(tmp_component):
|
||||
tmp_component.data = {"description": "test", "repository": {"url": "http://aaa"}}
|
||||
result = generate_idf_component_yml(tmp_component)
|
||||
|
||||
assert result == "description: test\nversion: 1.0.0\nrepository: http://aaa\n"
|
||||
assert result == "description: test\nrepository: http://aaa\n"
|
||||
|
||||
|
||||
def test_generate_idf_component_yml_with_dependencies(tmp_component, tmp_path):
|
||||
@@ -217,18 +217,16 @@ def test_generate_idf_component_yml_with_dependencies(tmp_component, tmp_path):
|
||||
|
||||
assert (
|
||||
result
|
||||
== f"""version: 1.0.0
|
||||
dependencies:
|
||||
== f"""dependencies:
|
||||
dep:
|
||||
version: '1.0'
|
||||
override_path: {dep.path}
|
||||
"""
|
||||
)
|
||||
|
||||
|
||||
def test_generate_idf_component_yml_missing_path_reraises(tmp_component):
|
||||
# A dep without a path and without a recognised source should re-raise
|
||||
# the underlying RuntimeError instead of silently producing a bad manifest.
|
||||
def test_generate_idf_component_yml_missing_path_raises(tmp_component):
|
||||
# A dep without a path is a contract violation — every dep is expected
|
||||
# to have been downloaded before YAML generation. Raise loudly.
|
||||
dep = IDFComponent("foo/bar", "1.0", source=None)
|
||||
|
||||
tmp_component.dependencies = [dep]
|
||||
@@ -422,8 +420,20 @@ def test_convert_library_with_repository():
|
||||
result = _convert_library_to_component(lib)
|
||||
|
||||
assert result.name == "foo/bar"
|
||||
assert result.version == "1.2.3"
|
||||
assert result.version == "*"
|
||||
assert isinstance(result.source, GitSource)
|
||||
assert result.source.ref == "v1.2.3"
|
||||
|
||||
|
||||
def test_convert_library_with_branch_ref():
|
||||
lib = Library("name", None, "https://github.com/foo/bar.git#some-branch")
|
||||
|
||||
result = _convert_library_to_component(lib)
|
||||
|
||||
assert result.name == "foo/bar"
|
||||
assert result.version == "*"
|
||||
assert isinstance(result.source, GitSource)
|
||||
assert result.source.ref == "some-branch"
|
||||
|
||||
|
||||
def test_convert_library_missing_ref():
|
||||
|
||||
Reference in New Issue
Block a user