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

--requirements-file doesn't work with pyproject.toml #94

Open
jamesbraza opened this issue Jan 12, 2025 · 6 comments
Open

--requirements-file doesn't work with pyproject.toml #94

jamesbraza opened this issue Jan 12, 2025 · 6 comments

Comments

@jamesbraza
Copy link
Contributor

With https://github.com/Future-House/aviary/tree/v0.14.0, flake8==7.1.1, and flake8-requirements[pyproject]==2.2.1, running in the repo root:

flake8 --requirements-file=packages/gsm8k packages/gsm8k/src
[tool.flake8.known-modules]
fh-llm-client = ["llmclient"]
fhaviary = ["aviary"]

I get the following I900s:

packages/gsm8k/src/aviary/envs/gsm8k/env.py:7:1: I900 'datasets' not listed as a requirement
packages/gsm8k/src/aviary/envs/gsm8k/env.py:8:1: I900 'pydantic' not listed as a requirement
packages/gsm8k/src/aviary/envs/gsm8k/env.py:22:5: I900 'pandas' not listed as a requirement

However, they are actually in the dependencies list: https://github.com/Future-House/aviary/blob/v0.14.0/packages/gsm8k/pyproject.toml#L9-L13

What is going wrong here?

@jamesbraza jamesbraza changed the title Not picking up pyproject.toml's dependencies when using --requirements-file --requirements-file doesn't work with pyproject.toml Jan 12, 2025
@jamesbraza
Copy link
Contributor Author

I think it's because --requirements-file sets requirements_file, which leads to not checking for pyproject.toml: https://github.com/arkq/flake8-requirements/blob/v2.2.1/src/flake8_requirements/checker.py#L734-L735

@arkq
Copy link
Owner

arkq commented Jan 14, 2025

I think it's because --requirements-file sets requirements_file, which leads to not checking for pyproject.toml

Yes, that's exactly what happens. There is no logic for merging dependencies from different configuration files. To be honest I'm not sure whether such behavior would be correct, because either you are installing dependencies via requirements.txt file or via project setup file. If I'm wrong please correct me, because recently I'm not following all the news in the Python ecosystem...

@arkq
Copy link
Owner

arkq commented Jan 14, 2025

flake8 --requirements-file=packages/gsm8k packages/gsm8k/src

Oooo, I think I see what is going on in here. You are trying to check dependencies in packages/gsm8k/src subdirectory, while being in the project's root directory which also has pyproject.toml... I'm afraid that there is no option which would allow that. Indeed there is the option for specifying the location of the "requirements.txt" file, because location of that file is not covered by any standard, but the location of pyproject.toml is well defined (I think) - it has to be in the project's root directory.

@jamesbraza
Copy link
Contributor Author

Hi @arkq no problem, and thanks for confirming.

You are trying to check dependencies in packages/gsm8k/src subdirectory, while being in the project's root directory which also has pyproject.toml

Yep you got it.

Fwiw, this structure is not some DIY structure, it comes recommended by uv. Check uv's docs for this: https://docs.astral.sh/uv/concepts/projects/workspaces/#workspace-sources. Basically you can have multiple pyproject.toml at different levels of the project.

So for that we'd want to support flake8 --requirements-file=packages/bird-feeder packages/bird-feeder/src, where --requirements-file points to a nested pyproject.toml (not a requirements.txt).

@arkq
Copy link
Owner

arkq commented Jan 14, 2025

Basically you can have multiple pyproject.toml at different levels of the project.

OK, so that is defined by the root pyproject.toml which shall have tool.uv.sources and tool.uv.workspace defined. If such, I think that we would need a support for that tool rather than a generic "--pyproject-file=" options. When linting one of the nested packages file, correct pyproject.toml should be selected automatically.

If you are willing to do some coding, I'd be more than happy to review it and merge. Otherwise, I'm afraid that currently I'm out of time for developing such feature. The basic idea would be to detect tool.uv.sources and tool.uv.workspace and keep the list of packages directories. Then when one of these is checked, use get_pyproject_toml*(root_dir) (now static) functions to fetch required data. Of course you might have some batter idea/concept, because I've just glanced at it.

@jamesbraza
Copy link
Contributor Author

So each pyproject.toml has to have its own dependencies specified, so they can be seen as standalone. Thus, a short-term workaround for flake8 --requirements-file not working with TOML is to:

  1. Duplicate the flake8 config into packages/gsm8k/pyproject.toml
  2. Duplicate dev dependencies (e.g. pytest) from repo root's pyproject.toml, if needed
  3. cd to the subdirectory packages/gsm8k
  4. Run flake8 from there

The basic idea would be to detect tool.uv.sources and tool.uv.workspace and keep the list of packages directories

As far as inspecting tool.uv.sources:

  • Pro: can invoke flake8 just once to check all packages' requirements
    • Can avoid duplication of dev dependencies (e.g. pytest)
  • Con: eventually have to support reading configurations for other management tools such as Poetry, PDM, or Pipenv

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants