Skip to content

Commit

Permalink
Use Burocrata to check and add license notices (#469)
Browse files Browse the repository at this point in the history
Replaces the custom script in `tools`. Simplified the `Makefile` and
GitHub Actions workflow to check style and format, instead of running
individual tools separately. Ultimately, all of the formatting tools
just need to be run if they fail, doesn't matter which.
  • Loading branch information
leouieda committed Mar 8, 2024
1 parent 1511905 commit 6400975
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 166 deletions.
1 change: 1 addition & 0 deletions .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ exclude =
.git,
__pycache__,
.ipynb_checkpoints,
doc/_build,
per-file-ignores =
# disable unused-imports errors on __init__.py
__init__.py: F401
Expand Down
58 changes: 5 additions & 53 deletions .github/workflows/style.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ on:

###############################################################################
jobs:
black:
name: black [format]
format:
runs-on: ubuntu-latest
steps:
- name: Checkout
Expand All @@ -37,10 +36,9 @@ jobs:
run: pip freeze

- name: Check code format
run: make black-check
run: make check-format

isort:
name: isort [format]
style:
runs-on: ubuntu-latest
steps:
- name: Checkout
Expand All @@ -51,53 +49,7 @@ jobs:
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: "3.10"

- name: Install requirements
run: pip install -r env/requirements-style.txt

- name: List installed packages
run: pip freeze

- name: Check code format
run: make isort-check

flake8:
name: flake8 [style]
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
persist-credentials: false

- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: "3.10"

- name: Install requirements
run: pip install -r env/requirements-style.txt

- name: List installed packages
run: pip freeze

- name: Check code style
run: make flake8

license:
name: license notice [style]
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
persist-credentials: false

- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: "3.10"
python-version: "3.11"

- name: Install requirements
run: pip install -r env/requirements-style.txt
Expand All @@ -106,4 +58,4 @@ jobs:
run: pip freeze

- name: Check code style
run: make license-check
run: make check-style
28 changes: 9 additions & 19 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ PROJECT=harmonica
TESTDIR=tmp-test-dir-with-unique-name
PYTEST_ARGS=--cov-config=../.coveragerc --cov-report=term-missing --cov=$(PROJECT) --doctest-modules --doctest-continue-on-failure -v --pyargs
NUMBATEST_ARGS=--doctest-modules -v --pyargs -m use_numba
STYLE_CHECK_FILES=$(PROJECT) examples doc/conf.py tools
STYLE_CHECK_FILES=$(PROJECT) examples doc

help:
@echo "Commands:"
Expand Down Expand Up @@ -39,29 +39,19 @@ test_numba:
cd $(TESTDIR); NUMBA_DISABLE_JIT=0 MPLBACKEND='agg' pytest $(NUMBATEST_ARGS) $(PROJECT)
rm -rvf $(TESTDIR)

format: license isort black

check: isort-check black-check license-check flake8

black:
format:
isort $(STYLE_CHECK_FILES)
black $(STYLE_CHECK_FILES)
burocrata --extension=py $(STYLE_CHECK_FILES)

black-check:
black --check $(STYLE_CHECK_FILES)
check: check-format check-style

isort:
isort $(STYLE_CHECK_FILES)

isort-check:
check-format:
isort --check $(STYLE_CHECK_FILES)
black --check $(STYLE_CHECK_FILES)
burocrata --check --extension=py $(STYLE_CHECK_FILES)

license:
python tools/license_notice.py

license-check:
python tools/license_notice.py --check

flake8:
check-style:
flake8 $(STYLE_CHECK_FILES)

clean:
Expand Down
1 change: 1 addition & 0 deletions env/requirements-style.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ flake8-rst-docstrings==0.3.*
flake8-simplify==0.19.*
flake8-unused-arguments==0.0.12
pep8-naming==0.13.*
burocrata==0.2.*
2 changes: 2 additions & 0 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,5 @@ dependencies:
- flake8-simplify==0.19.*
- flake8-unused-arguments==0.0.12
- pep8-naming==0.13.*
- pip:
- burocrata==0.2.*
9 changes: 9 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,12 @@ markers = [
[tool.isort]
profile = "black"
multi_line_output = 3

[tool.burocrata]
notice = '''
# Copyright (c) 2018 The Harmonica Developers.
# Distributed under the terms of the BSD 3-Clause License.
# SPDX-License-Identifier: BSD-3-Clause
#
# This code is part of the Fatiando a Terra project (https://www.fatiando.org)
#'''
94 changes: 0 additions & 94 deletions tools/license_notice.py

This file was deleted.

0 comments on commit 6400975

Please sign in to comment.