Skip to content
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

Merged
merged 1 commit into from
Feb 10, 2025

Conversation

rd4398
Copy link
Contributor

@rd4398 rd4398 commented Feb 7, 2025

This commit adds the lint-requirements command to fromager.
This command can be used to check the formatting of requirements.txt and constraints.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

@paradigm
Copy link
Contributor

paradigm commented Feb 7, 2025

This LGTM

Copy link
Member

@dhellmann dhellmann left a 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.


# 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)
Copy link
Member

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:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def lint_requirements(input_files_path: str) -> None:
def lint_requirements(input_files_path: list[click.Path]) -> None:

flag = True

for path in input_files_path:
parsed_lines = requirements_file.parse_requirements_file(str(path))
Copy link
Contributor Author

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

Copy link
Member

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.

@paradigm paradigm merged commit 3f53e93 into python-wheel-build:main Feb 10, 2025
80 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants