Skip to content

Commit fc69f69

Browse files
committed
Merge branch 'fix/enable_remove_requirements_file' into 'master'
fix(tools): handle missing `requirements.*.txt` files for enabled features Closes IDF-12849 See merge request espressif/esp-idf!39218
2 parents 8ab564a + 39cbbab commit fc69f69

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

tools/check_python_dependencies.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,21 @@
4040
PYTHON_PACKAGE_RE = re.compile(r'[^<>=~]+')
4141

4242

43+
def validate_requirement_list(file_path: str) -> str:
44+
"""Validate that a requirement file exists and is readable."""
45+
if not os.path.isfile(file_path):
46+
raise argparse.ArgumentTypeError(
47+
f'Requirement file {file_path} not found\n'
48+
'Please make sure the file path is correct.\n'
49+
'In case the file was removed, please run the export script again, to update the environment.'
50+
)
51+
try:
52+
open(file_path, encoding='utf-8').close()
53+
except IOError as e:
54+
raise argparse.ArgumentTypeError(f'Cannot read requirement file {file_path}: {e}')
55+
return file_path
56+
57+
4358
# The version and requires function from importlib.metadata in python prior
4459
# 3.10 does perform distribution name normalization before searching for
4560
# package distribution. This might cause problems for package with dot in its
@@ -75,6 +90,7 @@ def get_requires(name: str) -> Optional[list]:
7590
help='Path to a requirements file (can be used multiple times)',
7691
action='append',
7792
default=[],
93+
type=validate_requirement_list,
7894
)
7995
parser.add_argument(
8096
'--constraints',

tools/idf_tools.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1559,6 +1559,25 @@ def update_features(self, add: Tuple[str, ...] = (), remove: Tuple[str, ...] = (
15591559
features.add('core')
15601560
self._features = list(features)
15611561

1562+
def check_feature_requirements_files(self) -> None:
1563+
"""
1564+
Check if feature requirements files exist.
1565+
If not, remove the feature from the features list.
1566+
"""
1567+
features_to_remove: Tuple[str, ...] = ()
1568+
for feature in self._features:
1569+
if not os.path.isfile(feature_to_requirements_path(feature)):
1570+
info(
1571+
'\n'.join(
1572+
[
1573+
f"Feature file '{feature_to_requirements_path(feature)}' does not exist.",
1574+
f'Removing feature {feature}',
1575+
]
1576+
)
1577+
)
1578+
features_to_remove += (feature,)
1579+
self.update_features(remove=features_to_remove)
1580+
15621581
@property
15631582
def targets(self) -> List[str]:
15641583
return self._targets
@@ -1947,6 +1966,7 @@ def process_and_check_features(idf_env_obj: IDFEnv, features_str: str) -> List[s
19471966
raise SystemExit(1)
19481967

19491968
idf_env_obj.get_active_idf_record().update_features(tuple(new_features), tuple(remove_features))
1969+
idf_env_obj.get_active_idf_record().check_feature_requirements_files()
19501970
return idf_env_obj.get_active_idf_record().features
19511971

19521972

0 commit comments

Comments
 (0)