fix(tools): Enabled removing requirements.* files

This commit is contained in:
Marek Fiala
2025-05-16 17:34:32 +02:00
parent 85009a769d
commit 0849421d97
2 changed files with 50 additions and 6 deletions

View File

@@ -37,6 +37,21 @@ except ImportError:
PYTHON_PACKAGE_RE = re.compile(r'[^<>=~]+')
def validate_requirement_list(file_path: str) -> str:
"""Validate that a requirement file exists and is readable."""
if not os.path.isfile(file_path):
raise argparse.ArgumentTypeError(
f'Requirement file {file_path} not found\n'
'Please make sure the file path is correct.\n'
'In case the file was removed, please run the export script again, to update the environment.'
)
try:
open(file_path, encoding='utf-8').close()
except IOError as e:
raise argparse.ArgumentTypeError(f'Cannot read requirement file {file_path}: {e}')
return file_path
# The version and requires function from importlib.metadata in python prior
# 3.10 does perform distribution name normalization before searching for
# package distribution. This might cause problems for package with dot in its
@@ -66,12 +81,21 @@ def get_requires(name: str) -> Optional[list]:
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='ESP-IDF Python package dependency checker')
parser.add_argument('--requirements', '-r',
help='Path to a requirements file (can be used multiple times)',
action='append', default=[])
parser.add_argument('--constraints', '-c', default=[],
help='Path to a constraints file (can be used multiple times)',
action='append')
parser.add_argument(
'--requirements',
'-r',
help='Path to a requirements file (can be used multiple times)',
action='append',
default=[],
type=validate_requirement_list,
)
parser.add_argument(
'--constraints',
'-c',
default=[],
help='Path to a constraints file (can be used multiple times)',
action='append',
)
args = parser.parse_args()
required_set = set()