Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Linting with tox or/and pre-commit#2321

lmilbaum started this conversation inIdeas
Oct 17, 2022· 2 comments· 8 replies
Discussion options

The project is using two liniting frameworks: tox and pre-commit. Each has its own configuration files and a CI workflow.
That is a cause for some friction as the code is duplicated.
A followup from a discussion over#2320 with@JohnVillalovos

You must be logged in to vote

Replies: 2 comments 8 replies

Comment options

Thanks for looking into this@lmilbaum. I agree with@JohnVillalovos I prefer how tox manages the environments over pre-commit's special venv handling, and it gives us a more native way of handling dependencies. I would also prefer to have that as the test & lint runner (or an equivalentenvironment manager).

But I do use pre-commit as it sometimes still catches a few things before CI, and the main idea was to have that for contributors before opening PRs as it's a significant overhead on almost every PR review opened by new contributors and wastes CI resources.

I guess I don't really have a good answer to this, if there was a way for pre-commit to use native python venvs from tox (e.g. the local hook approach), then maybe that'd be the best way. I should saypre-commit made more sense before when we used a javascript-based commit message linter, now we've switched tocz so we're fully on python.

You must be logged in to vote
4 replies
@lmilbaum
Comment options

Those are valid points. Thank you for sharing your insights.
IIUC, triggering pre-commit via tox might be a good compromise. In that case, I think the change I pushed few seconds ago might do the trick.
Triggering the linting locally (DEV environment) will be:tox -e pro-commit

WDYT?

@nejch
Comment options

To me, this still shifts a bit too much towards pre-commit (as we see with removing the requirements). If we could keep these things in pure python we can later make use of proper lockfiles to always ensure reproducible behavior.

Is there any way to tell pre-commit to run its python-based hooks with the current python environment and installed dependencies, instead of tracking its own? That would be ideal.

If it's too much work, I'd maybe remove the duplicates from the pre-commit config instead, and only run the commit message linter from there and any other hooks that do not exist in tox. Then we can instruct contributors to run tox before push, perhaps in a default PR template. Sorry for the detours here.

@lmilbaum
Comment options

To me, this still shifts a bit too much towards pre-commit (as we see with removing the requirements). If we could keep these things in pure python we can later make use of proper lockfiles to always ensure reproducible behavior.

I see eye to eye with you on this. Reproduciable build (behavior) is a must have requirement in CI platform. My quetion would be, whether pinning the project revision (with arev key) isn't already achieving this requirement? And another question, what do you mean by stateing "pure python"?

Is there any way to tell pre-commit to run its python-based hooks with the current python environment and installed dependencies, instead of tracking its own? That would be ideal.

Not sure about that. What if the project revision from the pre-commit config file produces conflict between what needs to be in the environment and what is already installed?

If it's too much work, I'd maybe remove the duplicates from the pre-commit config instead, and only run the commit message linter from there and any other hooks that do not exist in tox. Then we can instruct contributors to run tox before push, perhaps in a default PR template. Sorry for the detours here.

The effort of implementing this option is not significant. I woner though, what would be the user expriance. The user is a project contributor. How frictionless will it be to maintain linting/formatting checks split into two frameworks?

Would switching totox while droppingpre-commit is a valid option?

@nejch
Comment options

And another question, what do you mean by stateing "pure python"?

Sorry, I meant something that we can manage fully using whatever dependency management we already use for our project, whether that ispip freeze all our requirements, poetry, hatch, flit etc.

But I'm ok with just a simple solution. We can drop pre-commit and do everything in tox, IMO, as it'll be more lightweight. We just need to add some clear docs to run selected tox environments before pushing.

The drawback will be a lot of people will have broken commits and will probably struggle locally to rebase interactively, but that's kind of already the case.

Comment options

I guess I don't see this is a major issue having both.

In my mind and in my usage,tox is the source of truth.pre-commit is a "nice to have" feature for those who like to use it.

If we had to choose between both I would strongly vote fortox. But I don't mind both being present.

You must be logged in to vote
4 replies
@nejch
Comment options

Sounds like a good compromise! So@lmilbaum I just wouldnt duplicate the runs in CI then. So we'd keep tox in CI and have the hooks for local use.

Keep in mind the pre-commit step in CI was initially made more to test that the pre-commit hooks actually work, not to run them on every PR. Maybe that was a source of confusion on why both were there. Hence these CI rules:

on:
push:
branches:
-main
paths:
.github/workflows/pre_commit.yml
.pre-commit-config.yaml
pull_request:
branches:
-main
-master
paths:
-.github/workflows/pre_commit.yml
-.pre-commit-config.yaml

So we might need to take some of the standalone checks out or rework a bit.

@JohnVillalovos
Comment options

The benefit to me of havingpre-commit run in CI is that we are testing it. So that way users who do runpre-commit are fairly sure it will work.

And now I see@nejch said that 🙂

@lmilbaum
Comment options

Good discussion :-). Thanks for the engagement. Appologies for nit picking. As a DevOps practioner, this topic is in my core system.
Let me summarize what I understood so far:

The list of requirements:

  1. Having linting/formatting quality gates applied on every code contribution
  2. The linting/formatting quality gates is a dynamic list
  3. Those quality gates should be able to run in DEV and CI environments
  4. It is valueable to validate the quality gates code in CI
  5. Reproducable build - ability to reproduce the exact quality gate run in a DEV environment as it was executed in CI and vice versa
  6. A good contriibutor expriance - DRY (Don't repeat yourself), automatically nvoking those quality gates pre pushing the code shortens the feedback loop

What we have now:

  1. The linting/formatting quality gates maintained in two lists (.pre-commit-config.yaml and tox.ini)
  2. There are quality gates whcih are maintained in one list but not in the other one and vice versa (non liniting/formatting quality gates are excluded from the discussion)
  3. Dependencies are matianed (maually and by renovate) in three or more files: .pre-commit-config.yaml, tox.ini and requrements-*.txt
  4. There could be a mis-alignment between the dependencies used by pre-commit and by tox. Therefor, a pre-commit successful run in DEV can provide a good approximation of succelssful CI run but not 100%.
  5. pre-commit has a built-in capability to be triggered on every commit while tox not
  6. tox has a built-in capability to execute quality gates on multiple environments while pre-commit not - the question would be whether this capability is required for linting/formatting quality gates.
  7. A contributor would invoke two different commands for a complete list of quality gates if two frameworks are used - the question would be whether those can be consolidated to one command.

Hoping this summary covers all what we know. LMK if I missed something.

With that summary, are we good to go with the approach suggested by@nejch

@nejch
Comment options

Sounds good to me! So de-duplicate, and I'm ok to add a tox env that doespre-commit run <lint-only-available-in-pre-commit> to bridge the gap.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Category
Ideas
Labels
None yet
3 participants
@lmilbaum@JohnVillalovos@nejch

[8]ページ先頭

©2009-2025 Movatter.jp