Skip to content

Commit 7caf39f

Browse files
committed
Remove glob call and error check
1 parent 5e76d8a commit 7caf39f

File tree

1 file changed

+8
-17
lines changed

1 file changed

+8
-17
lines changed

src/fromager/commands/lint_requirements.py

+8-17
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import glob
2-
import itertools
31
import logging
42
import sys
53

@@ -12,36 +10,29 @@
1210

1311

1412
@click.command()
15-
@click.argument("input_files_path", nargs=-1, type=click.Path(exists=False))
16-
def lint_requirements(input_files_path: str) -> None:
13+
@click.argument(
14+
"input_files_path", nargs=-1, required=True, type=click.Path(exists=False)
15+
)
16+
def lint_requirements(input_files_path: list[click.Path]) -> None:
1717
"""
1818
Command to lint the constraints.txt and requirements.txt files
1919
This command takes a single wildcard path string for constraints.txt and requirements.txt.
2020
It checks the formatting of these files and reports issues if found.
2121
"""
22-
# Exit if user does not provide wildcard paths
23-
if not input_files_path:
24-
logger.error("path for requirements.txt or constraints.txt is missing")
25-
sys.exit(1)
26-
27-
# Get all the files to check in a list
28-
files_to_check = list(
29-
itertools.chain.from_iterable(glob.glob(path) for path in input_files_path)
30-
)
3122

32-
if len(files_to_check) == 0:
23+
if len(input_files_path) == 0:
3324
logger.error("no constraints.txt or requirements.txt found in given paths")
3425
sys.exit(1)
3526

3627
flag = True
3728

38-
for file in files_to_check:
39-
parsed_lines = requirements_file.parse_requirements_file(file)
29+
for path in input_files_path:
30+
parsed_lines = requirements_file.parse_requirements_file(str(path))
4031
for line in parsed_lines:
4132
try:
4233
Requirement(line)
4334
except InvalidRequirement as err:
44-
logger.error(f"{file}: {line}: {err}")
35+
logger.error(f"{path}: {line}: {err}")
4536
flag = False
4637

4738
if not flag:

0 commit comments

Comments
 (0)