Skip to content

Commit b298db1

Browse files
committed
Merge branch 'feat/drop_root_level_commit_sha' into 'main'
feat!: drop support of root level `commit_sha` in the manifest file Closes PACMAN-927 See merge request espressif/idf-component-manager!418
2 parents 41935b2 + 1d0d7c3 commit b298db1

File tree

10 files changed

+57
-41
lines changed

10 files changed

+57
-41
lines changed

docs/en/reference/manifest_file.rst

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -231,37 +231,32 @@ Example:
231231
232232
repository: "https://example.com/component.git"
233233
234-
If your component is not in the root of the repository, specify the path to the component in the repository with the ``repository_info`` field.
234+
``repository_info``
235+
===================
236+
237+
The additional information of the repository.
238+
239+
This field is optional. But when it's set, ``repository`` field must be set as well.
240+
241+
If your component is not in the root of the repository, specify the path to the component in the ``path`` field.
235242

236243
.. code:: yaml
237244
238245
repository: "https://example.com/component.git"
239246
repository_info:
240-
commit_sha: "1234567890abcdef1234567890abcdef12345678"
241247
path: "path/to/component"
242248
243-
``commit_sha``
244-
==============
245-
246-
A SHA checksum for the Git commit of the component you intend to use.
247-
248-
This field is optional.
249-
250-
If used, place it under the ``repository_info`` field (recommended), or used along with the ``repository`` field.
251-
252-
Can be passed as an argument to the ``compote component upload --commit-sha [commit_sha]`` command.
253-
254-
Examples:
255-
256-
.. code:: yaml
257-
258-
commit_sha: "1234567890abcdef1234567890abcdef12345678"
249+
You may also put a Git Commit SHA of the component you intend to use in the ``commit_sha`` field.
259250

260251
.. code:: yaml
261252
262253
repository_info:
263254
commit_sha: "1234567890abcdef1234567890abcdef12345678"
264255
256+
Can be passed as an argument to the ``compote component upload --commit-sha [commit_sha]`` command.
257+
258+
Both ``path`` and ``commit_sha`` sub-fields are optional.
259+
265260
``documentation``
266261
=================
267262

idf_component_manager/core.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,14 @@ def upload_component(
557557
tempdir = tempfile.mkdtemp()
558558
try:
559559
unpack_archive(archive, tempdir)
560-
manifest = ManifestManager(tempdir, name, upload_mode=True).load()
560+
manifest = ManifestManager(
561+
tempdir,
562+
name,
563+
upload_mode=True,
564+
repository=repository,
565+
commit_sha=commit_sha,
566+
repository_path=repository_path,
567+
).load()
561568
finally:
562569
shutil.rmtree(tempdir)
563570
else:

idf_component_tools/manager.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ def validate(self) -> 'ManifestManager':
9393
self._manifest.repository = self._repository
9494

9595
if self._commit_sha is not None:
96-
self._manifest.commit_sha = self._commit_sha
9796
self._manifest.repository_info = RepositoryInfoField.fromdict({
9897
'commit_sha': self._commit_sha,
9998
'path': self._repository_path,

idf_component_tools/manifest/constants.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
COMPILED_FULL_SLUG_REGEX = re.compile(FULL_SLUG_REGEX)
1515
WEB_DEPENDENCY_REGEX = r'^((?:{slug}/{slug})|(?:{slug}))(.*)$'.format(slug=SLUG_BODY_REGEX)
1616

17-
LINKS = ['repository', 'commit_sha', 'documentation', 'issues', 'discussion', 'url']
17+
LINKS = ['repository', 'documentation', 'issues', 'discussion', 'url']
1818
KNOWN_INFO_METADATA_FIELDS = [
1919
'maintainers',
2020
'description',

idf_component_tools/manifest/models.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,6 @@ class Manifest(BaseModel):
337337
examples: t.List[t.Dict[str, t.Any]] = None # type: ignore
338338
url: UrlField = None # type: ignore
339339
repository: GIT_URL_FIELD = None # type: ignore
340-
commit_sha: str = None # type: ignore
341340
documentation: UrlField = None # type: ignore
342341
issues: UrlField = None # type: ignore
343342
discussion: UrlField = None # type: ignore
@@ -377,8 +376,8 @@ def validate_post_init(self) -> None:
377376
raise ValueError(unknown_keys_errs)
378377

379378
# validate repository and commit sha
380-
if not self.repository and self.commit_sha:
381-
raise ValueError('Invalid field "repository". Must set when "commit_sha" is set')
379+
if not self.repository and self.repository_info:
380+
raise ValueError('Invalid field "repository". Must set when "repository_info" is set')
382381

383382
if self._upload_mode:
384383
self._validate_while_uploading()
@@ -526,7 +525,7 @@ def metadata(self):
526525

527526
@property
528527
def manifest_hash(self) -> str:
529-
return hash_object(self.model_dump_json())
528+
return hash_object(self.model_dump_json(exclude_unset=True))
530529

531530
@property
532531
def repository_path(self) -> t.Optional[str]:

idf_component_tools/sources/git.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,6 @@ def _checkout_git_source(
6666
selected_paths=selected_paths,
6767
)
6868

69-
@property
70-
def component_hash_required(self) -> bool:
71-
return True
72-
7369
@property
7470
def downloadable(self) -> bool:
7571
return True

idf_component_tools/sources/web_service.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -202,10 +202,6 @@ def versions(self, name, spec='*', target=None):
202202

203203
return cmp_with_versions
204204

205-
@property
206-
def component_hash_required(self) -> bool:
207-
return True
208-
209205
@property
210206
def downloadable(self) -> bool:
211207
return True

tests/fixtures/locks/dependencies.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ dependencies:
99
source:
1010
type: idf
1111
version: 4.4.4
12-
manifest_hash: aedea05dfa3ce0abb1435f08e111503b8e4469ec2378069ea3cc7599bccce6f7
12+
manifest_hash: 1ad192c00dd8498c7f6e4264cffdd7b32d0d8dc41d5f1c3674041bc7d54e0083
1313
target: esp32
1414
version: 2.0.0

tests/test_component_manager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ def test_pack_component_with_replacing_manifest_params(tmp_path, release_compone
260260

261261
assert manifest.version == '2.3.5'
262262
assert manifest.links.repository == repository_url
263-
assert manifest.commit_sha == commit_id
263+
assert manifest.repository_info.commit_sha == commit_id
264264

265265

266266
def test_pack_component_with_examples(tmp_path, example_component_path):

tests/test_manifest_common_cases.py

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD
22
# SPDX-License-Identifier: Apache-2.0
33
import typing as t
4+
from copy import deepcopy
45

56
import pytest
67

@@ -19,7 +20,7 @@ def test_manifest_hash(valid_manifest):
1920
manifest = Manifest.fromdict(valid_manifest)
2021
# ONLY UPDATE MANIFEST HASH WHEN IT'S NECESSARY!!!
2122
assert (
22-
manifest.manifest_hash == '1bd6824f65d801ec3014b407dafde5e6cf6020f04f7bfee88b7e7d723da4bac0'
23+
manifest.manifest_hash == '8dd1abf83989a97bcd7590b795f5436169f3a2d74a99c832cb97a2d3e8b44205'
2324
)
2425

2526

@@ -111,17 +112,40 @@ def test_invalid_manifest(manifest, errors):
111112
assert error in produced_errors
112113

113114

114-
def test_validator_commit_sha_and_repo(valid_manifest):
115-
valid_manifest['commit_sha'] = (
116-
'252f10c83610ebca1a059c0bae8255eba2f95be4d1d7bcfa89d7248a82d9f111'
117-
)
115+
def test_validator_repo_info_and_repo(valid_manifest):
116+
original_valid_manifest = deepcopy(valid_manifest)
117+
118+
valid_manifest['repository_info'] = {
119+
'commit_sha': '252f10c83610ebca1a059c0bae8255eba2f95be4d1d7bcfa89d7248a82d9f111'
120+
}
118121
del valid_manifest['repository']
119122
errors = Manifest.validate_manifest(valid_manifest)
123+
assert errors == [
124+
'Invalid field "repository". Must set when "repository_info" is set',
125+
]
120126

127+
valid_manifest = deepcopy(original_valid_manifest)
128+
valid_manifest['repository_info'] = {'path': 'foo/bar'}
129+
del valid_manifest['repository']
130+
errors = Manifest.validate_manifest(valid_manifest)
121131
assert errors == [
122-
'Invalid field "repository". Must set when "commit_sha" is set',
132+
'Invalid field "repository". Must set when "repository_info" is set',
123133
]
124134

135+
valid_manifest = deepcopy(original_valid_manifest)
136+
valid_manifest['repository_info'] = {}
137+
del valid_manifest['repository']
138+
errors = Manifest.validate_manifest(valid_manifest)
139+
assert errors == [
140+
'Invalid field "repository". Must set when "repository_info" is set',
141+
]
142+
143+
valid_manifest = deepcopy(original_valid_manifest)
144+
valid_manifest.pop('repository_info', None)
145+
del valid_manifest['repository']
146+
errors = Manifest.validate_manifest(valid_manifest)
147+
assert errors == []
148+
125149

126150
@pytest.mark.parametrize(
127151
'require_field,public,require',

0 commit comments

Comments
 (0)