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

Provide a pre-commit hook for hatch fmt #1223

Open
ghisvail opened this issue Jan 26, 2024 · 4 comments
Open

Provide a pre-commit hook for hatch fmt #1223

ghisvail opened this issue Jan 26, 2024 · 4 comments

Comments

@ghisvail
Copy link

I am using Hatch for project management in my Python projects, and recently adopted hatch fmt instead of directly calling Ruff previously. I also use pre-commit in my CI workflows to run several linters project-wide. Right now, I use Hatch for formatting locally and Ruff in the CI run of pre-commit.

Ruff was recently updated (version 0.1.14) and its config now produces a different outcome than Hatch, since the latter depends on an older version (version 0.1.8 if I understood correctly). I can force Hatch to use an updated version of Ruff with:

# pyproject.toml

[tool.hatch.envs.hatch-static-analysis]
dependencies = ["ruff==0.1.14"]

so that both Ruff and Hatch are in agreement. It's not awful, but there is now a redundancy between Hatch's configuration and Ruff's pre-commit setup.

Instead, I was wondering whether a pre-commit hook could be introduced for Hatch to just run hatch fmt, with or without an updated version of Ruff based on the dependencies setting above.

Cheers, and thanks for your wonderful work on Hatch.

@fleming79
Copy link

I noticed this issue with pre-commit and was wondering maybe you can replace the ruff pre-commit hook with the a local that calls Hatch instead of Ruff?

I tried this and it worked for my use case. ref

pre-committ-config.yaml

repos:
  - repo: local
    hooks:
      - id: ruff-format-hatch-settings
        name: hatch-ruff
        language: system
        entry: hatch fmt
        pass_filenames: false
        verbose: true

@ofek
Copy link
Collaborator

ofek commented Jan 31, 2024

I am open to this but do not have any idea where to begin as I do not use pre-commit.

@fleming79
Copy link

Perhaps this article is useful?

@mikita-sakalouski
Copy link

I am open to this but do not have any idea where to begin as I do not use pre-commit.

@ofek Please have a look at #1740

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

4 participants