-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feat]: Add lint-requirements command #545
Conversation
This LGTM |
829b8ab
to
d03eb08
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there's some debugging output to remove, but other than that it looks good. I'd like @paradigm to review, too, since he has reviewed other drafts.
501bd62
to
5e76d8a
Compare
|
||
# Get all the files to check in a list | ||
files_to_check = list( | ||
itertools.chain.from_iterable(glob.glob(path) for path in input_files_path) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By the time the linter is invoked, the shell will have expanded the wildcard for us, so we don't need this glob call.
|
||
@click.command() | ||
@click.argument("input_files_path", nargs=-1, type=click.Path(exists=False)) | ||
def lint_requirements(input_files_path: str) -> None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def lint_requirements(input_files_path: str) -> None: | |
def lint_requirements(input_files_path: list[click.Path]) -> None: |
7caf39f
to
2ada5b7
Compare
flag = True | ||
|
||
for path in input_files_path: | ||
parsed_lines = requirements_file.parse_requirements_file(str(path)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to convert this to string because the function parse_requirements_file
only accepts str | pathlib.Path
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is fine. For future reference, https://github.com/python-wheel-build/fromager/blob/main/src/fromager/clickext.py#L10 defines a class that can convert click.Path() to pathlib.Path(). We use that in a few other places.
This commit adds the
lint-requirements
command to fromager.This command can be used to check the formatting of
requirements.txt
andconstraints.txt
along with the entries in these files being valid or not.The command can process multiple files at the same time.
Usage:
fromager lint-requirements "path/to/constraints.txt" "path/to/requirements.txt"
Signed-off by Rohan Devasthale