|
1 |
| -import glob |
2 |
| -import itertools |
3 | 1 | import logging
|
4 | 2 | import sys
|
5 | 3 |
|
|
12 | 10 |
|
13 | 11 |
|
14 | 12 | @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: |
17 | 17 | """
|
18 | 18 | Command to lint the constraints.txt and requirements.txt files
|
19 | 19 | This command takes a single wildcard path string for constraints.txt and requirements.txt.
|
20 | 20 | It checks the formatting of these files and reports issues if found.
|
21 | 21 | """
|
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 |
| - ) |
31 | 22 |
|
32 |
| - if len(files_to_check) == 0: |
| 23 | + if len(input_files_path) == 0: |
33 | 24 | logger.error("no constraints.txt or requirements.txt found in given paths")
|
34 | 25 | sys.exit(1)
|
35 | 26 |
|
36 | 27 | flag = True
|
37 | 28 |
|
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)) |
40 | 31 | for line in parsed_lines:
|
41 | 32 | try:
|
42 | 33 | Requirement(line)
|
43 | 34 | except InvalidRequirement as err:
|
44 |
| - logger.error(f"{file}: {line}: {err}") |
| 35 | + logger.error(f"{path}: {line}: {err}") |
45 | 36 | flag = False
|
46 | 37 |
|
47 | 38 | if not flag:
|
|
0 commit comments