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

Pre-commit hook doesn't recognize internal packages #103

Open
zeraye opened this issue Nov 14, 2024 · 2 comments
Open

Pre-commit hook doesn't recognize internal packages #103

zeraye opened this issue Nov 14, 2024 · 2 comments

Comments

@zeraye
Copy link

zeraye commented Nov 14, 2024

Pre-commit hook doesn't recognize internal packages. When I lint project using ruff check inside superproject directory everything works fine. But when I run pre-commit, imports from external and internal packages (eg. flask and superpackage) are not separated. This happens because pre-commit doesn't recognize internal and external packages. I tried to cd superproject && ruff check, but this doesn't seem to work. Other solutions with bash -c 'cd ...' seems way too hacky. I also don't want to store inside pyproject.toml list of all internal packages. Is there any elegant solution?

Project structure:

.
└── superproject
    ├── main.py
    ├── pyproject.toml
    └── superpackage
        ├── __init__.py
        ├── __pycache__
        └── test.py

main.py

from flask import json

from superpackage.test import hello_world

# this doesn't matter
print(hello_world())
print(json.dumps({"hello": "world"}))

pyproject.toml

[tool.ruff.lint]
extend-select = ["I"]

[tool.ruff.lint.isort]
combine-as-imports = true

Python 3.12.3
Ruff 0.7.3

@dhruvmanila
Copy link
Member

Can you specify where your .pre-commit-config.yaml file lives? Is it in a directory above superproject or is it inside superproject?

@zeraye
Copy link
Author

zeraye commented Nov 18, 2024

Can you specify where your .pre-commit-config.yaml file lives? Is it in a directory above superproject or is it inside superproject?

Above superproject

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