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

Add pre-commit configuration #756

Closed
wants to merge 4 commits into from

Conversation

Guts
Copy link
Contributor

@Guts Guts commented Jan 5, 2022

In this PR

  • add classical git hooks through pre-commit to prevent "simple" issues when pushing code
  • add basic flake8 git hook, reusing configuration from setup.cfg and selecting most important flags
  • add specific section for https://pre-commit.ci/ - recommended because it automates hook updates and quick fixes when it's possible. This requires that a member with write permissions registers the repository on the application.
  • add required as extra dependencies into setup.py for development

Goal

A little step to improve code reliability.

Related issues

Related to #755

@Guts
Copy link
Contributor Author

Guts commented Jan 5, 2022

ping @jelmer and @ix5

language: python
files: ^isso/.*\.py$
types: [python]
args: ["--config=setup.cfg", "--select=E9,F63,F7,F82"]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't this severely limiting what errors we'll get?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not to be too frustrating at the time of the commit or a PR.
If you prefer, we can enlarge this selection or apply everything.

Copy link
Member

@ix5 ix5 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like your effort, @Guts. This certainly seems like something that could help catch little slip-ups in a fast-paced development environment.
I've left a few comments in the code.

In general though, I think running linting tools should be up to the discretion of individual committers. We don't want to force them to install yet another framework on their machine (with auto-downloaded hook repos from a to their eyes untrusted Github source).

I'm perfectly fine with recommending running flake8 before committing. flake8 is being run as CI on PRs already.

I'm also a bit confused because pre-commit seems to be two things at the same time:

  • A framework for running "hooks" from its GitHub hook repository (which needs to be updated regularly) by creating a virtualenv (which I can't find any info about)
  • A CI cloud service (free?) which requires push access for its bot to contributors' branches to push what it thinks are trivial fixes

The first one, as I've stated above, should in my opinion reside with individual contributors. We shouldn't force anyone to use it, but having the config for people who might want it seems a good idea.
The second one seems a bit intrusive. It's another unknown actor to trust. For my taste, the whole "sprinkle some packages on it" vibe of nodejs is not something I'd want to bring to this project. But then again, I'd not be entirely opposed to it. Waiting for other maintainers' opinions on this.

Don't get me wrong, I'm very much grateful for your efforts @Guts, but it seems this project will soon be 90% configs for some type of devops service while actual, structural or architectural issues are left hanging. If this helps us write unit tests or invites more contributors, that's a positive outcome. But as they say, adding fancy new things is easy, fixing bugs is hard ;)

hooks:
- id: flake8
language: python
files: ^isso/.*\.py$
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this catch isso/foo/bar.py as well? I'm not familiar with the regexp(?) engine that interprets this, but will .* match subfolders (slashes) too?

hooks:
- id: check-added-large-files
args: ['--maxkb=500']
- id: check-executables-have-shebangs
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't have any bash scripts afaik

args: ['--maxkb=500']
- id: check-executables-have-shebangs
- id: check-case-conflict
- id: check-yaml
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have YAML files apart from the ansible example?

@@ -0,0 +1,39 @@
exclude: "node_modules|.venv|isso/tests"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't we want tests formatted correctly as well?

types: [python]
args: ["--config=setup.cfg", "--select=E9,F63,F7,F82"]

# Specific part for https://pre-commit.ci
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Am I understanding this correctly that there'll be a little bot auto-committing to this repo? I'd rather avoid this. Proposing changes is fine, but commit rights seem a bit overkill.
Or will this only auto-commit what it thinks are fixes to the branches of PR authors which we can then squash?

@jelmer
Copy link
Member

jelmer commented Jan 6, 2022

In general though, I think running linting tools should be up to the discretion of individual committers. We don't want to force them to install yet another framework on their machine (with auto-downloaded hook repos from a to their eyes untrusted Github source).

I'm perfectly fine with recommending running flake8 before committing. flake8 is being run as CI on PRs already.

Hmm, I'd forgotten about that. Adding flake8 to the "dev" dependencies seems reasonable. I'm not sure that the pre-commit config really adds much in that case.

-1 on automatic updates by third party bots from me as well.

Jelmer

@ix5 ix5 added the feature label Feb 24, 2022
@ix5 ix5 added this to the backburner milestone Feb 24, 2022
@ix5 ix5 closed this Jun 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants