Skip to content

Commit e65fa0a

Browse files
committed
Merge branch 'fix/compote_upload_without_idf' into 'main'
fix: filterwarning "Running in an environment without IDF" while uploading Closes PACMAN-964 See merge request espressif/idf-component-manager!429
2 parents 4bbdacd + 8f32948 commit e65fa0a

File tree

4 files changed

+36
-24
lines changed

4 files changed

+36
-24
lines changed

idf_component_manager/core.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
)
4949
from idf_component_tools.manager import (
5050
ManifestManager,
51+
UploadMode,
5152
)
5253
from idf_component_tools.manifest import (
5354
WEB_DEPENDENCY_REGEX,
@@ -404,7 +405,7 @@ def pack_component(
404405
manifest_manager = ManifestManager(
405406
self.path,
406407
name,
407-
upload_mode=True,
408+
upload_mode=UploadMode.component,
408409
version=version,
409410
repository=repository,
410411
commit_sha=commit_sha,
@@ -561,7 +562,7 @@ def upload_component(
561562
manifest = ManifestManager(
562563
tempdir,
563564
name,
564-
upload_mode=True,
565+
upload_mode=UploadMode.component,
565566
repository=repository,
566567
commit_sha=commit_sha,
567568
repository_path=repository_path,

idf_component_tools/manager.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD
22
# SPDX-License-Identifier: Apache-2.0
3-
3+
import enum
44
import os
55
import typing as t
66
from pathlib import Path
@@ -14,6 +14,12 @@
1414
from .manifest.models import Manifest
1515

1616

17+
class UploadMode(str, enum.Enum):
18+
false = 'false'
19+
component = 'component'
20+
example = 'example'
21+
22+
1723
class ManifestManager:
1824
"""
1925
Parser for manifest files in the project.
@@ -24,7 +30,7 @@ def __init__(
2430
path: str,
2531
name: str,
2632
*,
27-
upload_mode: bool = False,
33+
upload_mode: UploadMode = UploadMode.false,
2834
# override fields
2935
version: t.Optional[str] = None,
3036
repository: t.Optional[str] = None,

idf_component_tools/manifest/models.py

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

67
from pydantic import (
@@ -50,13 +51,11 @@
5051
validation_error_to_str,
5152
)
5253

54+
from ..manager import UploadMode
5355
from ..semver import Version
5456
from .constants import COMPILED_FULL_SLUG_REGEX, known_targets
5557
from .if_parser import IfClause, parse_if_clause
5658

57-
if t.TYPE_CHECKING:
58-
pass
59-
6059

6160
class OptionalDependency(BaseModel):
6261
# use alias since `if` is a keyword
@@ -345,15 +344,15 @@ class Manifest(BaseModel):
345344
discussion: UrlField = None # type: ignore
346345
repository_info: RepositoryInfoField = None # type: ignore
347346

348-
_upload_mode: bool = False
347+
_upload_mode: UploadMode = UploadMode.false
349348

350349
def __init__(
351350
self,
352351
**kwargs,
353352
):
354353
super().__init__(**kwargs)
355354

356-
self._upload_mode = kwargs.pop('upload_mode', False)
355+
self._upload_mode = kwargs.pop('upload_mode', UploadMode.false)
357356

358357
self.validate_post_init()
359358

@@ -382,7 +381,7 @@ def validate_post_init(self) -> None:
382381
if not self.repository and self.repository_info:
383382
raise ValueError('Invalid field "repository". Must set when "repository_info" is set')
384383

385-
if self._upload_mode:
384+
if self._upload_mode != UploadMode.false:
386385
self._validate_while_uploading()
387386

388387
def model_dump(
@@ -472,7 +471,7 @@ def validate_manifest(
472471
cls,
473472
obj: t.Any,
474473
*,
475-
upload_mode: bool = False,
474+
upload_mode: UploadMode = UploadMode.false,
476475
return_with_object: bool = False,
477476
# pydantic options
478477
strict: t.Optional[bool] = None,
@@ -487,12 +486,18 @@ def validate_manifest(
487486

488487
obj['upload_mode'] = upload_mode
489488
try:
490-
res = super().model_validate(
491-
obj,
492-
strict=strict,
493-
from_attributes=from_attributes,
494-
context=context,
495-
)
489+
with warnings.catch_warnings():
490+
if upload_mode != UploadMode.false:
491+
warnings.filterwarnings(
492+
'ignore', message='^Running in an environment without IDF.'
493+
)
494+
495+
res = super().model_validate(
496+
obj,
497+
strict=strict,
498+
from_attributes=from_attributes,
499+
context=context,
500+
)
496501
except ValidationError as e:
497502
errors = e.errors(include_url=False)
498503

tests/manifest/test_validator.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import pytest
88

99
from idf_component_manager.dependencies import detect_unused_components
10-
from idf_component_tools.manager import ManifestManager
10+
from idf_component_tools.manager import ManifestManager, UploadMode
1111
from idf_component_tools.manifest import SLUG_REGEX, OptionalRequirement, SolvedComponent
1212
from idf_component_tools.manifest.constants import DEFAULT_KNOWN_TARGETS, known_targets
1313
from idf_component_tools.manifest.if_parser import parse_if_clause
@@ -110,7 +110,7 @@ def test_validate_targets_unknown(self, valid_manifest):
110110

111111
assert not errors
112112

113-
errors = Manifest.validate_manifest(valid_manifest, upload_mode=True)
113+
errors = Manifest.validate_manifest(valid_manifest, upload_mode=UploadMode.component)
114114

115115
assert errors == ['Invalid field "targets". Unknown targets: "asdf,esp123"']
116116

@@ -153,12 +153,12 @@ def test_validate_version_list(self, valid_manifest):
153153
assert not errors
154154

155155
def test_check_required_keys(self, valid_manifest):
156-
errors = Manifest.validate_manifest(valid_manifest, upload_mode=True)
156+
errors = Manifest.validate_manifest(valid_manifest, upload_mode=UploadMode.component)
157157

158158
assert not errors
159159

160160
def test_check_required_keys_empty_manifest(self):
161-
errors = Manifest.validate_manifest({}, upload_mode=True)
161+
errors = Manifest.validate_manifest({}, upload_mode=UploadMode.component)
162162

163163
assert errors == [
164164
'Invalid field "version". Must set while uploading component to the registry'
@@ -443,7 +443,7 @@ def test_validate_optional_dependency_success(
443443
self, valid_optional_dependency_manifest_with_idf
444444
):
445445
errors = Manifest.validate_manifest(
446-
valid_optional_dependency_manifest_with_idf, upload_mode=True
446+
valid_optional_dependency_manifest_with_idf, upload_mode=UploadMode.component
447447
)
448448

449449
assert not errors
@@ -470,7 +470,7 @@ def test_validate_optional_dependency_invalid(
470470
'if'
471471
] = invalid_str
472472
errors = Manifest.validate_manifest(
473-
valid_optional_dependency_manifest_with_idf, upload_mode=True
473+
valid_optional_dependency_manifest_with_idf, upload_mode=UploadMode.component
474474
)
475475

476476
assert errors == expected_errors
@@ -500,7 +500,7 @@ def test_validate_optional_dependency_invalid_derived(
500500
'if'
501501
] = invalid_str
502502
errors = Manifest.validate_manifest(
503-
valid_optional_dependency_manifest_with_idf, upload_mode=True
503+
valid_optional_dependency_manifest_with_idf, upload_mode=UploadMode.component
504504
)
505505

506506
assert errors == expected_errors

0 commit comments

Comments
 (0)