-
Notifications
You must be signed in to change notification settings - Fork 49
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
Pre-commit hook doesn't recognize internal packages #103
Comments
Can you specify where your |
Above superproject |
running into the same issue, where the pre-commit yaml also lives above the root of our logic. |
@skullyhoofd if you want an obscure solution: repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.7.3
hooks:
- id: ruff
name: Python Ruff linter for superproject
entry: bash -c 'cd superproject && ruff check . --config pyproject.toml --fix'
language_version: python3.12
types: [python]
files: "superproject"
- id: ruff-format
name: Python Ruff formatter for superproject
entry: bash -c 'cd superproject && ruff format . --config pyproject.toml'
language_version: python3.12
types: [python]
files: "superproject" That's the best solution I'm aware of. Hate this, but it works |
So, just to confirm that this is your project structure?
Can you specify how you're running For me, it doesn't seem to be complaining: /tmp/ruff-pre-commit-test
$ pre-commit run --all-files
ruff.....................................................................Passed
/tmp/ruff-pre-commit-test
$ cd superproject
/tmp/ruff-pre-commit-test/superproject
$ pre-commit run --all-files
ruff.....................................................................Passed |
NOTE: pre-commit-config in the comment above is my current workaround Your project structure is correct. To be more precise: test.py def hello_world():
print("Hello, world!") .pre-commit-config.yaml repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.7.3
hooks:
- id: ruff
name: Python Ruff linter for superproject
args: ["--config", "superproject/pyproject.toml", "--fix"]
language_version: python3.12
types: [python]
files: "superproject"
- id: ruff-format
name: Python Ruff formatter for superproject
args: ["--config", "superproject/pyproject.toml"]
language_version: python3.12
types: [python]
files: "superproject"
❯ pre-commit run --all-files
Python Ruff linter for superproject......................................Failed
- hook id: ruff
- files were modified by this hook
Found 1 error (1 fixed, 0 remaining).
Python Ruff formatter for superproject...................................Passed This is how ruff formatted from flask import json
from superpackage.test import hello_world
# this doesn't matter
print(hello_world())
print(json.dumps({"hello": "world"})) I want this file to be formatted as in my issue description. Ruff doesn't recognize here external (flask) and internal (superpackage) libraries. |
Pre-commit hook doesn't recognize internal packages. When I lint project using
ruff check
insidesuperproject
directory everything works fine. But when I runpre-commit
, imports from external and internal packages (eg.flask
andsuperpackage
) are not separated. This happens becausepre-commit
doesn't recognize internal and external packages. I tried tocd superproject && ruff check
, but this doesn't seem to work. Other solutions withbash -c 'cd ...'
seems way too hacky. I also don't want to store insidepyproject.toml
list of all internal packages. Is there any elegant solution?Project structure:
main.py
pyproject.toml
Python 3.12.3
Ruff 0.7.3
The text was updated successfully, but these errors were encountered: