From b44aa89bf8fe1ebe52bbd8717f938ae290ab3dfb Mon Sep 17 00:00:00 2001 From: Wei Ji <23487320+weiji14@users.noreply.github.com> Date: Sat, 26 Mar 2022 01:00:41 -0400 Subject: [PATCH 1/8] Replace flake8 with flakeheaven So that we can remove the setup.cfg file and have everything in pyproject.toml! Temporarily installing flakeheaven using pip until conda-forge package is ready. --- .github/workflows/format-command.yml | 2 +- .github/workflows/style_checks.yaml | 4 ++-- Makefile | 6 +++--- doc/contributing.md | 4 ++-- environment.yml | 3 ++- pyproject.toml | 6 ++++++ setup.cfg | 5 ----- 7 files changed, 16 insertions(+), 14 deletions(-) delete mode 100644 setup.cfg diff --git a/.github/workflows/format-command.yml b/.github/workflows/format-command.yml index a94bcd603cb..6c8e476c738 100644 --- a/.github/workflows/format-command.yml +++ b/.github/workflows/format-command.yml @@ -26,7 +26,7 @@ jobs: # Install formatting tools - name: Install formatting tools run: | - pip install black blackdoc docformatter flake8 isort + pip install black blackdoc docformatter flakeheaven isort sudo apt-get install dos2unix # Run "make format" and commit the change to the PR branch diff --git a/.github/workflows/style_checks.yaml b/.github/workflows/style_checks.yaml index 90344bd048e..0831c859ff8 100644 --- a/.github/workflows/style_checks.yaml +++ b/.github/workflows/style_checks.yaml @@ -26,10 +26,10 @@ jobs: - name: Install packages run: | - pip install black blackdoc docformatter flake8 pylint isort + pip install black blackdoc docformatter flakeheaven pylint isort sudo apt-get install dos2unix - - name: Formatting check (black, blackdoc, docformatter, flake8 and isort) + - name: Formatting check (black, blackdoc, docformatter, flakeheaven and isort) run: make check - name: Linting (pylint) diff --git a/Makefile b/Makefile index 30b78c92093..6330f769254 100644 --- a/Makefile +++ b/Makefile @@ -8,7 +8,7 @@ BLACK_FILES=$(PROJECT) setup.py doc/conf.py examples BLACKDOC_OPTIONS=--line-length 79 DOCFORMATTER_FILES=$(PROJECT) setup.py doc/conf.py examples DOCFORMATTER_OPTIONS=--recursive --pre-summary-newline --make-summary-multi-line --wrap-summaries 79 --wrap-descriptions 79 -FLAKE8_FILES=$(PROJECT) setup.py doc/conf.py examples +FLAKEHEAVEN_FILES=$(PROJECT) setup.py doc/conf.py examples LINT_FILES=$(PROJECT) setup.py doc/conf.py help: @@ -19,7 +19,7 @@ help: @echo " test run the test suite (including some doctests) and report coverage" @echo " fulltest run the test suite (including all doctests) and report coverage" @echo " format run black, blackdoc, docformatter and isort to automatically format the code" - @echo " check run code style and quality checks (black, blackdoc, docformatter, flake8 and isort)" + @echo " check run code style and quality checks (black, blackdoc, docformatter, flakeheaven and isort)" @echo " lint run pylint for a deeper (and slower) quality check" @echo " clean clean up build and generated files" @echo " distclean clean up build and generated files, including project metadata files" @@ -64,7 +64,7 @@ check: docformatter --check $(DOCFORMATTER_OPTIONS) $(DOCFORMATTER_FILES) black --check $(BLACK_FILES) blackdoc --check $(BLACKDOC_OPTIONS) $(BLACK_FILES) - flake8 $(FLAKE8_FILES) + flakeheaven lint $(FLAKEHEAVEN_FILES) lint: pylint $(LINT_FILES) diff --git a/doc/contributing.md b/doc/contributing.md index 6fe55a909fd..00d7c1abb9d 100644 --- a/doc/contributing.md +++ b/doc/contributing.md @@ -475,14 +475,14 @@ words bridged only by consonants, such as `distcalc`, and `crossprofile`. This convention is not applied by the code checking tools, but the PyGMT maintainers will comment on any pull requests as needed. -We also use [flake8](http://flake8.pycqa.org/en/latest/) and +We also use [flakeheaven](https://flakeheaven.readthedocs.io) and [pylint](https://www.pylint.org/) to check the quality of the code and quickly catch common errors. The [`Makefile`](https://github.com/GenericMappingTools/pygmt/blob/main/Makefile) contains rules for running both checks: ```bash -make check # Runs black, blackdoc, docformatter, flake8 and isort (in check mode) +make check # Runs black, blackdoc, docformatter, flakeheaven and isort (in check mode) make lint # Runs pylint, which is a bit slower ``` diff --git a/environment.yml b/environment.yml index fc56d1a4954..e4da3c55888 100644 --- a/environment.yml +++ b/environment.yml @@ -23,7 +23,6 @@ dependencies: - black - blackdoc - docformatter - - flake8 - isort>=5 - pylint # Dev dependencies (unit testing) @@ -38,3 +37,5 @@ dependencies: - sphinx-copybutton - sphinx-gallery - sphinx_rtd_theme + - pip: + - flakeheaven diff --git a/pyproject.toml b/pyproject.toml index 68d2fb48c9f..a8938e42bf8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,12 @@ [tool.coverage.run] omit = ["*/tests/*", "*pygmt/__init__.py"] +[tool.flakeheaven] +ignore = ["E203", "E266", "E501", "W503", "F401", "E741"] +max_line_length = 88 +max-doc-length = 79 +show_source = true + [tool.pytest.ini_options] minversion = "6.0" addopts = "--verbose --durations=0 --durations-min=0.2 --doctest-modules --mpl --mpl-results-path=results" diff --git a/setup.cfg b/setup.cfg deleted file mode 100644 index 2c09e8bed23..00000000000 --- a/setup.cfg +++ /dev/null @@ -1,5 +0,0 @@ -[flake8] -ignore = E203, E266, E501, W503, F401, E741 -max-line-length = 88 -#max-complexity = 10 -max-doc-length = 79 From 2e6495cc17e76c972e2ed18bd762ff2c575433d9 Mon Sep 17 00:00:00 2001 From: Wei Ji <23487320+weiji14@users.noreply.github.com> Date: Tue, 10 May 2022 11:17:29 -0400 Subject: [PATCH 2/8] Install flakeheaven from conda-forge instead of pypi --- environment.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/environment.yml b/environment.yml index e4da3c55888..d55a86e2446 100644 --- a/environment.yml +++ b/environment.yml @@ -23,6 +23,7 @@ dependencies: - black - blackdoc - docformatter + - flakeheaven - isort>=5 - pylint # Dev dependencies (unit testing) @@ -37,5 +38,3 @@ dependencies: - sphinx-copybutton - sphinx-gallery - sphinx_rtd_theme - - pip: - - flakeheaven From 942135b423dc398428a707a27a42415416fdebb3 Mon Sep 17 00:00:00 2001 From: Wei Ji <23487320+weiji14@users.noreply.github.com> Date: Wed, 15 Jun 2022 12:01:02 -0400 Subject: [PATCH 3/8] Change config dashes to underscores --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 6b963ab1fd4..7f6cff9d782 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -12,7 +12,7 @@ omit = ["*/tests/*", "*pygmt/__init__.py"] [tool.flakeheaven] ignore = ["E203", "E266", "E501", "W503", "F401", "E741"] max_line_length = 88 -max-doc-length = 79 +max_doc_length = 79 show_source = true [tool.pytest.ini_options] From 61fb34fc376fc972102ab215195e7cc7c8267d32 Mon Sep 17 00:00:00 2001 From: Wei Ji <23487320+weiji14@users.noreply.github.com> Date: Sun, 10 Jul 2022 22:59:56 -0400 Subject: [PATCH 4/8] Invalidate flakeheaven cache Ref https://github.com/flakeheaven/flakeheaven/issues/71 --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 6330f769254..0ce1377ec6b 100644 --- a/Makefile +++ b/Makefile @@ -64,7 +64,7 @@ check: docformatter --check $(DOCFORMATTER_OPTIONS) $(DOCFORMATTER_FILES) black --check $(BLACK_FILES) blackdoc --check $(BLACKDOC_OPTIONS) $(BLACK_FILES) - flakeheaven lint $(FLAKEHEAVEN_FILES) + FLAKEHEAVEN_CACHE_TIMEOUT=0 flakeheaven lint $(FLAKEHEAVEN_FILES) lint: pylint $(LINT_FILES) From 30a926728c984146df4abe7f44b08fb31610cf65 Mon Sep 17 00:00:00 2001 From: Wei Ji <23487320+weiji14@users.noreply.github.com> Date: Sun, 10 Jul 2022 23:32:51 -0400 Subject: [PATCH 5/8] Ignore pycodestyle and pyflakes errors in flakeheaven plugins section Ref https://flakeheaven.readthedocs.io/en/latest/config.html#ignored-options --- pyproject.toml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 8bd9496a47d..7bc9de20639 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -10,11 +10,14 @@ fallback_version = "999.999.999+unknown" omit = ["*/tests/*", "*pygmt/__init__.py"] [tool.flakeheaven] -ignore = ["E203", "E266", "E501", "W503", "F401", "E741"] max_line_length = 88 max_doc_length = 79 show_source = true +[tool.flakeheaven.plugins] +pycodestyle = ["+*", "-E266", "-E501", "-W503"] +pyflakes = ["+*", "-F401"] + [tool.pytest.ini_options] minversion = "6.0" addopts = "--verbose --durations=0 --durations-min=0.2 --doctest-modules --mpl --mpl-results-path=results" From 7b32a52ba6595f03cb1f632e201632db65ebb159 Mon Sep 17 00:00:00 2001 From: Wei Ji <23487320+weiji14@users.noreply.github.com> Date: Thu, 18 Aug 2022 08:46:37 -0400 Subject: [PATCH 6/8] Pin minimum flakeheaven version to 3.0.0 Includes a fix that forwards max_line_length to pylint plugin. Co-Authored-By: Dongdong Tian --- environment.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/environment.yml b/environment.yml index 23abbc15e02..d3ed43a02b4 100644 --- a/environment.yml +++ b/environment.yml @@ -23,7 +23,7 @@ dependencies: - black - blackdoc - docformatter - - flakeheaven + - flakeheaven>=3 - isort>=5 - pylint # Dev dependencies (unit testing) From 6822d87ffd2860ddf1690acf15c5e35c70798083 Mon Sep 17 00:00:00 2001 From: Wei Ji <23487320+weiji14@users.noreply.github.com> Date: Thu, 18 Aug 2022 08:56:01 -0400 Subject: [PATCH 7/8] Enforce pycodestyle E266 Too many leading '#' for block comment Removed some double ## in colorbar gallery example to allow this check to pass. --- examples/gallery/embellishments/colorbar.py | 6 +++--- pyproject.toml | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/gallery/embellishments/colorbar.py b/examples/gallery/embellishments/colorbar.py index b6320261fbc..edfbdd5ecb6 100644 --- a/examples/gallery/embellishments/colorbar.py +++ b/examples/gallery/embellishments/colorbar.py @@ -26,11 +26,11 @@ fig = pygmt.Figure() fig.basemap(region=[0, 3, 6, 9], projection="x3c", frame=["af", "WSne+tColorbars"]) -## Create a colorbar designed for seismic tomography - roma +# Create a colorbar designed for seismic tomography - roma # Colorbar is placed at bottom center (BC) by default if no position is given fig.colorbar(cmap="roma", frame=["x+lVelocity", "y+lm/s"]) -## Create a colorbar showing the scientific rainbow - batlow +# Create a colorbar showing the scientific rainbow - batlow fig.colorbar( cmap="batlow", # Colorbar positioned at map coordinates (g) longitude/latitude 0.3/8.7, @@ -41,7 +41,7 @@ scale=100, ) -## Create a colorbar suitable for surface topography - oleron +# Create a colorbar suitable for surface topography - oleron fig.colorbar( cmap="oleron", # Colorbar position justified outside map frame (J) at Middle Right (MR), diff --git a/pyproject.toml b/pyproject.toml index 7bc9de20639..98e76481f6a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -15,7 +15,7 @@ max_doc_length = 79 show_source = true [tool.flakeheaven.plugins] -pycodestyle = ["+*", "-E266", "-E501", "-W503"] +pycodestyle = ["+*", "-E501", "-W503"] pyflakes = ["+*", "-F401"] [tool.pytest.ini_options] From 7dd65fa945b648c443b0dd03055253e54b709437 Mon Sep 17 00:00:00 2001 From: Wei Ji <23487320+weiji14@users.noreply.github.com> Date: Thu, 18 Aug 2022 10:40:15 -0400 Subject: [PATCH 8/8] Ignore pyflakes F401 'Module imported but unused' for __init__.py only Be more specific rather than globally enabling the exception. Documentation at https://flakeheaven.readthedocs.io/en/latest/config.html#example --- pyproject.toml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 98e76481f6a..a74b65d7345 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -16,7 +16,10 @@ show_source = true [tool.flakeheaven.plugins] pycodestyle = ["+*", "-E501", "-W503"] -pyflakes = ["+*", "-F401"] +pyflakes = ["+*"] + +[tool.flakeheaven.exceptions."**/__init__.py"] +pyflakes = ["-F401"] [tool.pytest.ini_options] minversion = "6.0"