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

Proposal to use pre-commit for continuous integration #78

Merged
merged 9 commits into from
Aug 14, 2023
Merged

Conversation

dachengx
Copy link
Collaborator

@dachengx dachengx commented Aug 13, 2023

What this PR does?

Stop using the wemake-python-styleguide which gives too many errors. And switch to pre-commit's continuous integration.

The advantage of pre-commit is that:

  1. It runs automatically when you git commit.
  2. You will not upload codes that are not aligned with some styles.

The codes are changed only in code style, the requirement of hooks.

Note: black will force you to use double quotes, it actually auto-format for you, so do not worry.

What will this PR improve?

You will see no reviewdog complaining, and pre-commit will do almost all formatting for you, and it is very fast.

How to setup pre-commit?

cd alea
pip install pre-commit
pre-commit install

What will the configuration tell pre-commit to do?

Besides basic whitespace and large files check,

  1. black will auto-format your code, mainly about indent and line-length, and make auto-commit if necessary.
  2. docformatter will auto-format your docstring, following google convention, and make auto-commit if necessary.
  3. mypy will check the typing in your code, it is a bug finder, you still need to fix and commit them.
  4. doc8 will check the docs/*.rst and docs/*.md, it gives the warning of wrong format. Currently, there is no popular auto-formatter for .rst.
  5. flake8 will check the code-style, but in a more lite way than wemake-python-styleguide.

So there will be two pre-commit checks, one check of changed files when you git commit, and one check of all files by pre-commit CI.

How to execute pre-commit locally

When you git commit, it will automatically pre-commit run for the changed files, so actually you would not always run it manually.

If you want to check all the files, run pre-commit run --all-files. If you want to check the difference between the current branch and main, run pre-commit run --from-ref main --to-ref .. If you want to remove the color from the output, add --color never.

black and docformatter will change your code, you still need to make a commit by yourself on the changed part.

For more information, please go to https://pre-commit.com/ and https://pre-commit.ci/.

Inspired by XENONnT/straxen#1192

@dachengx dachengx changed the title Add .pre-commit-config.yaml Proposal to use pre-commit for continuous integration Aug 13, 2023
@coveralls
Copy link

coveralls commented Aug 13, 2023

Pull Request Test Coverage Report for Build 5856811680

  • 98 of 164 (59.76%) changed or added relevant lines in 9 files are covered.
  • 23 unchanged lines in 4 files lost coverage.
  • Overall coverage increased (+0.3%) to 72.491%

Changes Missing Coverage Covered Lines Changed/Added Lines %
alea/models/blueice_extended_model.py 13 14 92.86%
alea/runner.py 27 28 96.43%
alea/simulators.py 10 11 90.91%
alea/model.py 9 11 81.82%
alea/utils.py 9 12 75.0%
alea/parameters.py 10 15 66.67%
alea/template_source.py 16 69 23.19%
Files with Coverage Reduction New Missed Lines %
alea/model.py 1 84.48%
alea/utils.py 1 79.55%
alea/parameters.py 2 85.61%
alea/template_source.py 19 24.19%
Totals Coverage Status
Change from base Build 5834424515: 0.3%
Covered Lines: 780
Relevant Lines: 1076

💛 - Coveralls

@dachengx dachengx added make user-friendly testing Works on testing code labels Aug 13, 2023
@dachengx dachengx requested a review from kdund August 13, 2023 18:46
@dachengx
Copy link
Collaborator Author

@kdund Nothing crucial to be reviewed. Please just see whether you are satisfied with the workflow and CI.

@kdund
Copy link
Collaborator

kdund commented Aug 14, 2023

Seems to work for me for a simple whitespace test

Copy link
Collaborator

@kdund kdund left a comment

Choose a reason for hiding this comment

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

Approved if it only affects linting

@coveralls
Copy link

coveralls commented Dec 4, 2024

Pull Request Test Coverage Report for Build 5848486517

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 159 of 223 (71.3%) changed or added relevant lines in 9 files are covered.
  • 144 unchanged lines in 8 files lost coverage.
  • Overall coverage remained the same at 72.212%

Changes Missing Coverage Covered Lines Changed/Added Lines %
alea/model.py 24 26 92.31%
alea/models/blueice_extended_model.py 29 31 93.55%
alea/runner.py 33 35 94.29%
alea/simulators.py 11 13 84.62%
alea/utils.py 17 20 85.0%
alea/parameters.py 20 24 83.33%
alea/template_source.py 21 70 30.0%
Files with Coverage Reduction New Missed Lines %
alea/examples/gaussian_model.py 1 93.75%
alea/runner.py 1 97.39%
alea/simulators.py 5 91.21%
alea/models/blueice_extended_model.py 7 94.51%
alea/utils.py 12 79.31%
alea/parameters.py 13 85.0%
alea/model.py 22 84.39%
alea/template_source.py 83 24.01%
Totals Coverage Status
Change from base Build 5834424515: 0.0%
Covered Lines: 777
Relevant Lines: 1076

💛 - Coveralls

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
make user-friendly testing Works on testing code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants