-
Notifications
You must be signed in to change notification settings - Fork 18
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
Request: configurability of project root (for imports), or respecting flake8 --config
as root
#45
Comments
You will have to add custom mappings. See this: https://github.com/Arkq/flake8-requirements#customization |
Okay I have added the # Map namespace packages to imports for flake8-requirements
# SEE: https://github.com/Arkq/flake8-requirements#customization
known-modules = foo-bar:[foo.bar],foo-baz:[foo.baz],foo-spam:[foo.spam] In actuality, I have a lot of namespace repos, and this known-modules =
foo-bar:[foo.bar],
foo-baz:[foo.baz],
foo-spam:[foo.spam], Also, one other question. My python package is inside in a - repo: "https://gitlab.com/pycqa/flake8"
rev: 3.9.2
hooks:
- id: flake8
name: flake8 src
alias: flake8-src
files: ^src/
args:
- "--config"
- src/setup.cfg
additional_dependencies:
- flake8-docstrings
- flake8-bugbear
- flake8-requirements Unfortunately, I find
It seems like the core problem is The workaround for this repo root issue (per pre-commit/pre-commit#1417 (comment)) is to invoke - repo: local
hooks:
- id: flake8
name: flake8 src package
alias: flake8-src
language: system
entry: bash -c "cd src && flake8" |
Sorry for such a late reply, but somehow I've missed your comment... GitHub does not send notification when comment is edited :/
Yes, that might be the issue here... This plug-in checks for python project root directory on the first
In |
I've made one check with such setup:
Test: $ flake8
./main.py:1:51: E501 line too long (65 > 50 characters)
$ flake8 subproject
$ cd subproject
subproject $ flake8
./extra.py:1:31: E501 line too long (37 > 30 characters) So, even flake8 itself reads configuration from the current directory. For consistency, I think, flake8-requirements should do the same thing. |
This is close, but I think you're missing a detail. Note in my So in your repro above, the 2nd line should pass
So what can be done? Perhaps |
Hmm... maybe you are right. But I'm thinking of a case where the config for flake8 is kept separately from the repo/project itself. So, setting the root of the project based on config might lead to issues as well... I'm more inclined to search for project's root on every file scan (not only of flake8 startup). This will decrease performance, but I'm not sure how much... Alternatively, such approach (searching for project's root on every file scan) might be enabled on demand by flake8 option. I'll have to check that on some big python repo. |
That makes sense, good point. I agree it's not the right solution to assume the
I also agree here, I don't like the possibility of a performance hit due to inference. Perhaps another option is be adding an additional argument |
I agree with this one. Is there a way to have multiline definition of known-modules? |
flake8 --config
as root
I work at a company that uses native namespace packages for multiple internal packages.
Let's say our namespace is
foo
, so in a given packagefoo-ham
we have import statements like:And in the
foo-ham
repo'ssetup.py
we will have:Currently,
flake8-requirements
reports:How can I get
flake8-requirements
to properly understand native namespace packages?The text was updated successfully, but these errors were encountered: