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

Adds black and pre-commit hooks #239

Merged
merged 35 commits into from Aug 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
03bf430
Moved /ewatercycle to /src/ewatercycle + adjust config to match
sverhoeven Aug 10, 2021
910c075
Add black to dev deps
sverhoeven Aug 10, 2021
9607f3e
Configure black to also format notebooks
sverhoeven Aug 10, 2021
bd3d472
Added black and friends as pre-commit hooks and to ci
sverhoeven Aug 10, 2021
d9a6fa5
Files changes by `pre-commit run --all-files` command
sverhoeven Aug 10, 2021
b3f7013
Use nbqa-black to format notebooks instead of black
sverhoeven Aug 11, 2021
565eb19
On release run pre-commit on all files
sverhoeven Aug 11, 2021
ca821b6
Disable flake8 until its errors are fixed
sverhoeven Aug 11, 2021
c6b42e7
Merge remote-tracking branch 'origin/main' into 111-black
sverhoeven Aug 11, 2021
22adbe7
Added flake8 plugins
sverhoeven Aug 11, 2021
107afa5
Make isort, pylint and flake8 compatible with black
sverhoeven Aug 12, 2021
9141a5d
Use tabs in makefile
sverhoeven Aug 12, 2021
ba8cba8
Replace prospector with pre-commit
sverhoeven Aug 12, 2021
7a4bab4
Prefer `@pytest.fixture` over `@pytest.fixture()`
sverhoeven Aug 12, 2021
7f27ade
Added pylint and bunch of flake8 plugins to pre commit config
sverhoeven Aug 12, 2021
33cafd1
Move config from arg to file + pytest-fixture config inverted
sverhoeven Aug 12, 2021
13d2d42
Disable pylint and fix flake8 errors first
sverhoeven Aug 12, 2021
c74b2f5
Ignore docstring checks in tests/ + Move google doc style to where py…
sverhoeven Aug 12, 2021
35afd99
Fix flake8 errors
sverhoeven Aug 12, 2021
096ea90
Reduce flake8 warnings
sverhoeven Aug 12, 2021
59abbe3
Fix doc generator + Fix bunch of lint warnings
sverhoeven Aug 12, 2021
05938c8
More of the same
sverhoeven Aug 12, 2021
a69a5c9
Fixing lint errors in grdc
sverhoeven Aug 12, 2021
6695108
Make flake8 just print errors instead of dying
sverhoeven Aug 12, 2021
ddbd76e
Fix line lengths in ewatercycle.models
Peter9192 Aug 16, 2021
f5b3fc6
Fix line lengths in config
Peter9192 Aug 16, 2021
644e14d
Fix line lengths in ewatercycle.parameter_sets
Peter9192 Aug 16, 2021
6786f7a
fix line lengths in ewatercycle.forcing
Peter9192 Aug 16, 2021
e6b91cf
Fix remaining line lengths in ewatercycle package
Peter9192 Aug 16, 2021
0f5bf78
noqa instead of pylint-specific
Peter9192 Aug 16, 2021
8e47e24
Fix line lengths in tests
Peter9192 Aug 16, 2021
b0f5f8d
fix error message
Peter9192 Aug 16, 2021
a6f0436
Force showing of warnings of nbqa-flake8
sverhoeven Aug 17, 2021
04723c5
Update .pre-commit-config.yaml
sverhoeven Aug 17, 2021
70f957d
Merge branch '111-black' of github.com:eWaterCycle/ewatercycle into 1…
sverhoeven Aug 17, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions .editorconfig
Expand Up @@ -25,3 +25,6 @@ indent_size = 2

[*.{md,Rmd}]
trim_trailing_whitespace = false

[Makefile]
indent_style = tab
35 changes: 16 additions & 19 deletions .github/workflows/ci.yml
@@ -1,13 +1,10 @@
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions

name: Python package

on:
push:
branches: [main]
pull_request:
types: [opened, synchronize, reopened]
types: [opened, synchronize, reopened]

jobs:
build:
Expand All @@ -19,18 +16,18 @@ jobs:
fail-fast: false
name: Run tests in conda environment ${{ matrix.python-version }}
steps:
- uses: actions/checkout@v2
- uses: conda-incubator/setup-miniconda@v2
with:
activate-environment: ewatercycle
environment-file: environment.yml
python-version: ${{ matrix.python-version }}
miniconda-version: "latest"
channels: conda-forge
- name: Install dependencies
shell: bash -l {0}
run: |
pip3 install -e .[dev]
- name: Test with pytest
run: pytest
shell: bash -l {0}
- uses: actions/checkout@v2
- uses: conda-incubator/setup-miniconda@v2
with:
activate-environment: ewatercycle
environment-file: environment.yml
python-version: ${{ matrix.python-version }}
miniconda-version: "latest"
channels: conda-forge
- name: Install dependencies
shell: bash -l {0}
run: |
pip3 install -e .[dev]
- name: Test with pytest
run: pytest
shell: bash -l {0}
56 changes: 30 additions & 26 deletions .github/workflows/sonar.yml
Expand Up @@ -4,34 +4,38 @@ on:
push:
branches: [main]
pull_request:
types: [opened, synchronize, reopened]
types: [opened, synchronize, reopened]

jobs:
sonarcloud:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Set up Python
uses: conda-incubator/setup-miniconda@v2
with:
activate-environment: ewatercycle
environment-file: environment.yml
python-version: 3.8
miniconda-version: "latest"
channels: conda-forge
- name: Install dependencies
shell: bash -l {0}
run: |
pip3 install -e .[dev]
- name: Tests with coverage
run: pytest --cov --cov-report term --cov-report xml --junitxml=xunit-result.xml
shell: bash -l {0}
- name: Correct coverage paths
run: sed -i "s+$PWD/++g" coverage.xml
- name: SonarCloud Scan
uses: sonarsource/sonarcloud-github-action@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Set up Python
uses: conda-incubator/setup-miniconda@v2
with:
activate-environment: ewatercycle
environment-file: environment.yml
python-version: 3.8
miniconda-version: "latest"
channels: conda-forge
- name: Install dependencies
shell: bash -l {0}
run: |
pip3 install -e .[dev]
- name: Run pre commit hooks like linters and black formatter
uses: pre-commit/action@v2.0.3
- name: Tests with coverage
run: |
pytest --cov --cov-report term --cov-report xml \
--junitxml=xunit-result.xml
shell: bash -l {0}
- name: Correct coverage paths
run: sed -i "s+$PWD/++g" coverage.xml
- name: SonarCloud Scan
uses: sonarsource/sonarcloud-github-action@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
98 changes: 98 additions & 0 deletions .pre-commit-config.yaml
@@ -0,0 +1,98 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.4.0
hooks:
- id: check-added-large-files
- id: check-ast
- id: check-case-conflict
- id: check-merge-conflict
- id: debug-statements
- id: end-of-file-fixer
- id: trailing-whitespace
args: [--markdown-linebreak-ext=md]
- repo: https://github.com/adrienverge/yamllint
rev: "v1.26.0"
hooks:
- id: yamllint
- repo: https://github.com/asottile/setup-cfg-fmt
rev: v1.17.0
hooks:
- id: setup-cfg-fmt
- repo: https://github.com/psf/black
rev: 21.7b0
hooks:
- id: black
- repo: https://github.com/PyCQA/isort
rev: "5.9.3"
hooks:
- id: isort
# TODO renable when errors are fixed/ignored
# - repo: https://github.com/pycqa/pylint
# rev: "v2.9.6"
# hooks:
# - id: pylint
# TODO renable when errors are fixed/ignored
- repo: https://gitlab.com/pycqa/flake8
rev: "3.9.2"
hooks:
- id: flake8
additional_dependencies:
&fd [
flake8-annotations-complexity,
flake8-bandit,
flake8-blind-except,
flake8-bugbear,
flake8-builtins,
flake8-cognitive-complexity,
flake8-comprehensions,
flake8-docstrings,
flake8-eradicate,
flake8-executable,
flake8-expression-complexity,
flake8-if-expr,
flake8-implicit-str-concat,
flake8-logging-format,
flake8-pathlib,
flake8-print,
flake8-pytest,
flake8-pytest-style,
# flake8-quotes, # conflicts with blacks double quote preference
flake8-raise,
flake8-return,
flake8-typing-imports,
flake8-variables-names,
flake8==3.9.2,
pandas-vet,
pep8-naming,
# wemake-python-styleguide, # conflicts with black
yesqa,
]
verbose: true
args: &fa [--statistics, --exit-zero]
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.910
hooks:
- id: mypy
additional_dependencies: [types-python-dateutil]
- repo: https://github.com/nbQA-dev/nbQA
rev: 1.1.0
hooks:
- id: nbqa-black
# Match version of black used for .py and .ipynb
additional_dependencies: [black==21.7b0]
- id: nbqa-isort
additional_dependencies: [isort==5.9.3]
- id: nbqa-mypy
additional_dependencies: [mypy==0.910]
# TODO renable when errors are fixed/ignored
- id: nbqa-flake8
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could it be that the notebooks (in docs) are not picked up by these checks?

This check passes on pre-commit run --all-files for me, but if I do pip install nbqa and then nbqa flake8 docs/*.ipynb I get a list of issues.

Choose a reason for hiding this comment

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

I think the issue is

        args: *fa

, I'm not sure what it's meant to do here, but if you remove it then pre-commit run nbqa-flake8 --all-files will fail too

Copy link
Member Author

Choose a reason for hiding this comment

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

The flake8 hook is verbose by default while nbqa-flake8 was not, I forced it to be verbose so now warnings show up.

The *fa is a YAML alias of YAML anchor defined in flake8 hook with @fa so I do not have to repeat the list of flake8 plugins.

Choose a reason for hiding this comment

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

I didn't know you could do that, thanks! This'll be useful in other projects

additional_dependencies: *fd
args: *fa
verbose: true
# TODO renable when errors are fixed/ignored
# - id: nbqa-pylint
# additional_dependencies: [pylint==2.9.6]
- repo: https://github.com/regebro/pyroma
rev: "3.2"
hooks:
- id: pyroma
29 changes: 0 additions & 29 deletions .prospector.yml

This file was deleted.

14 changes: 8 additions & 6 deletions CONTRIBUTING.md
Expand Up @@ -55,6 +55,7 @@ The sections below outline the steps in each case.
and [here](https://help.github.com/articles/syncing-a-fork/));
4. install the package in editable mode and its dependencies with
`pip3 install -e .[dev]`;
4. make sure pre commit hook is installed by running `pre-commit install`, causes linting and formatting to be applied during commit;
5. make sure the existing tests still work by running `pytest`;
6. make sure the existing documentation can still by generated without
warnings by running `cd docs && make html`. [Pandoc](https://pandoc.org/) is required to generate docs, it can be installed with ``conda install -c conda-forge pandoc`` ;
Expand All @@ -81,24 +82,25 @@ This section is for maintainers of the package.
2. Determine what new version (major, minor or patch) to use. Package uses `semantic versioning <https://semver.org>`_.
3. Run ``bump2version <major|minor|patch>`` to update version in package files.
4. Update CHANGELOG.md with changes between current and new version.
5. Commit & push changes to GitHub.
6. Wait for [GitHub
5. Make sure pre-commit hooks are green for all files by running ``pre-commit run --all-files``.
6. Commit & push changes to GitHub.
7. Wait for [GitHub
actions](https://github.com/eWaterCycle/ewatercycle/actions?query=branch%3Amain+)
to be completed and green.

7. Create a [GitHub release](https://github.com/eWaterCycle/ewatercycle/releases/new)
8. Create a [GitHub release](https://github.com/eWaterCycle/ewatercycle/releases/new)

- Use version as title and tag version.
- As description use intro text from README.md (to give context to
Zenodo record) and changes from CHANGELOG.md

8. Create a PyPI release.
9. Create a PyPI release.

1. Create distribution archives with `python3 -m build`.
2. Upload archives to PyPI with `twine upload dist/*` (use your
personal PyPI account).

9. Verify
10. Verify

1. Has [new Zenodo
record](https://zenodo.org/search?page=1&size=20&q=ewatercycle)
Expand All @@ -109,4 +111,4 @@ This section is for maintainers of the package.
3. Can new version be installed with pip using
`pip3 install ewatercycle==<new version>`?

10. Celebrate
11. Celebrate
1 change: 0 additions & 1 deletion LICENSE
Expand Up @@ -14,4 +14,3 @@ distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.