976
Review Please (programming.dev)
you are viewing a single comment's thread
view the rest of the comments
[-] zalgotext@sh.itjust.works 1 points 7 months ago* (last edited 7 months ago)

Say you have a custom lint you want to use but it only will ever be used for that specific project. You can't just put the lint code in a subdirectory. It has to go in a separate repo.

You can run locally defined hooks with pre-commit, just define them in the repo: local section of the .pre-commit-config.yaml, and have it run a bash/python/whatever script or something that invokes your custom linting, wherever it lives in your file structure.

It will install pylint fine, but if your project does e.g. import yaml, it's not going to set up a venv and install pyyaml for you.

Yeah I misspoke/misremembered there. For Python based stuff, it uses the currently active virtualenv or your global python install, so it relies on you installing your own dependencies. Which isn't really that big a deal imo, because you need to install those dependencies to run/debug/test locally anyways.

[-] FizzyOrange@programming.dev 1 points 7 months ago

You can run locally defined hooks with pre-commit, just define them in the repo: local section of the .pre-commit-config.yaml

Sounds like you're just googling it rather than actually speaking from experience. Suppose I have written a Python lint and it's in my ci/lints/foo folder. How do I tell pre-commit that? (Hint: you can't)

Which isn’t really that big a deal imo

For small Python projects, maybe not. The project I'm working on has multiple sub-projects and those each have their own venvs, pyproject.tomls, etc.

[-] zalgotext@sh.itjust.works 1 points 7 months ago

Sounds like you're just googling it rather than actually speaking from experience.

Like I said, I've used pre-commit for multiple years now. If you can run your lints from a command line, you can configure pre-commit to run them.

The project I'm working on has multiple sub-projects and those each have their own venvs, pyproject.tomls, etc.

Monorepos definitely make things a bit trickier, but again, you absolutely can write a local pre-commit hook that runs a bash command or script that 1.) activates the necessary venv and 2.) runs the lint command. I know this because I've done it, multiple times.

[-] FizzyOrange@programming.dev 1 points 7 months ago

If you can run your lints from a command line, you can configure pre-commit to run them.

Yes but the whole point of pre-commit is it takes care of installing the lints. For most supported languages this requires the lint to be in its own repo. That is very annoying for project-specific lints that you would ideally want to just put in a subdirectory. Does that make sense?

can write a local pre-commit hook that runs a bash command or script that 1.) activates the necessary venv and 2.) runs the lint command. I know this because I’ve done it, multiple times.

Yeah there's not really any point using pre-commit at that point.

this post was submitted on 29 Mar 2024
976 points (98.3% liked)

Programmer Humor

19623 readers
1 users here now

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

founded 1 year ago
MODERATORS