From 451cb61d519afb1b835d769dc27bbd80ff18645c Mon Sep 17 00:00:00 2001 From: Wei Ji <23487320+weiji14@users.noreply.github.com> Date: Sun, 15 Oct 2023 22:32:45 +1300 Subject: [PATCH 1/5] Replace flakeheaven and isort with ruff Use ruff to replace both flakeheaven (including pycodestyle and pyflakes rules) and isort. Updated the documentation in `doc/contributing.md` and the Makefile's `format` and `check` commands. GitHub Actions CI format-command and style_checks also install ruff instead of flakeheaven/isort now. --- .github/workflows/format-command.yml | 2 +- .github/workflows/style_checks.yaml | 4 ++-- .gitignore | 2 +- Makefile | 9 ++++---- doc/contributing.md | 6 ++--- environment.yml | 3 +-- pyproject.toml | 33 +++++++++++++++------------- 7 files changed, 30 insertions(+), 29 deletions(-) diff --git a/.github/workflows/format-command.yml b/.github/workflows/format-command.yml index 60917035b0d..5300dd87ff5 100644 --- a/.github/workflows/format-command.yml +++ b/.github/workflows/format-command.yml @@ -32,7 +32,7 @@ jobs: # Install formatting tools - name: Install formatting tools run: | - python -m pip install black blackdoc docformatter flakeheaven isort + python -m pip install black blackdoc docformatter ruff python -m pip list sudo apt-get install dos2unix diff --git a/.github/workflows/style_checks.yaml b/.github/workflows/style_checks.yaml index 2658a52b790..9fb807524be 100644 --- a/.github/workflows/style_checks.yaml +++ b/.github/workflows/style_checks.yaml @@ -34,11 +34,11 @@ jobs: - name: Install packages run: | - python -m pip install black blackdoc docformatter flakeheaven pylint isort + python -m pip install black blackdoc docformatter pylint ruff python -m pip list sudo apt-get install dos2unix - - name: Formatting check (black, blackdoc, docformatter, flakeheaven and isort) + - name: Formatting check (black, blackdoc, docformatter, ruff) run: make check - name: Linting (pylint) diff --git a/.gitignore b/.gitignore index 12ade17828c..c89f876a3ca 100644 --- a/.gitignore +++ b/.gitignore @@ -17,8 +17,8 @@ MANIFEST .coverage coverage.xml htmlcov/ -.flakeheaven_cache/ .pytest_cache/ +.ruff_cache/ results/ result_images/ tmp-test-dir-with-unique-name/ diff --git a/Makefile b/Makefile index cb66f8deb80..3fcab6575ad 100644 --- a/Makefile +++ b/Makefile @@ -15,8 +15,8 @@ help: @echo " fulltest run the test suite (including all doctests)" @echo " doctest run the doctests only" @echo " test_no_images run the test suite (including all doctests) but skip image comparisons" - @echo " format run black, blackdoc, docformatter and isort to automatically format the code" - @echo " check run code style and quality checks (black, blackdoc, docformatter, flakeheaven and isort)" + @echo " format run black, blackdoc, docformatter and ruff to automatically format the code" + @echo " check run code style and quality checks (black, blackdoc, docformatter, ruff)" @echo " codespell run codespell to check common misspellings" @echo " lint run pylint for a deeper (and slower) quality check" @echo " clean clean up build and generated files" @@ -60,17 +60,16 @@ test_no_images: PYTEST_ARGS=-o addopts="--verbose --durations=0 --durations-min= test_no_images: _runtest format: - isort . docformatter --in-place $(FORMAT_FILES) black $(FORMAT_FILES) blackdoc $(FORMAT_FILES) + ruff check --fix $(FORMAT_FILES) check: - isort . --check docformatter --check $(FORMAT_FILES) black --check $(FORMAT_FILES) blackdoc --check $(FORMAT_FILES) - FLAKEHEAVEN_CACHE_TIMEOUT=0 flakeheaven lint $(FORMAT_FILES) + ruff check $(FORMAT_FILES) codespell: @codespell diff --git a/doc/contributing.md b/doc/contributing.md index fffc0a7bc40..c44e80d5ae5 100644 --- a/doc/contributing.md +++ b/doc/contributing.md @@ -476,7 +476,7 @@ We use some tools to format the code so we don't have to think about it: - [Black](https://github.com/psf/black) - [blackdoc](https://github.com/keewis/blackdoc) - [docformatter](https://github.com/myint/docformatter) -- [isort](https://pycqa.github.io/isort/) +- [ruff](https://docs.astral.sh/ruff) Black and blackdoc loosely follows the [PEP8](http://pep8.org) guide but with a few differences. Regardless, you won't have to worry about formatting the code yourself. @@ -499,14 +499,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 [flakeheaven](https://flakeheaven.readthedocs.io) and +We also use [ruff](https://docs.astral.sh/ruff) and [pylint](https://pylint.pycqa.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, flakeheaven and isort (in check mode) +make check # Runs black, blackdoc, docformatter, ruff (in check mode) make lint # Runs pylint, which is a bit slower ``` diff --git a/environment.yml b/environment.yml index 0f65963817c..73b45304436 100644 --- a/environment.yml +++ b/environment.yml @@ -26,9 +26,8 @@ dependencies: - blackdoc - codespell - docformatter>=1.7.2 - - flakeheaven>=3 - - isort>=5 - pylint + - ruff # Dev dependencies (unit testing) - matplotlib - pytest-cov diff --git a/pyproject.toml b/pyproject.toml index 42ec3d330cb..4b5ca958003 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -85,27 +85,30 @@ make-summary-multi-line = true wrap-summaries = 79 wrap-descriptions = 79 -[tool.flakeheaven] -max_line_length = 88 -max_doc_length = 79 -show_source = true +[tool.ruff] +line-length = 88 # E501 (line-too-long) +show-source = true +select = [ + "E", # pycodestyle + "F", # pyflakes + "I", # isort + "W", # pycodestyle warnings +] +ignore = ["E501"] # Avoid enforcing line-length violations + +[tool.ruff.pycodestyle] +max-doc-length = 79 -[tool.flakeheaven.plugins] -pycodestyle = ["+*", "-E501", "-W503"] -pyflakes = ["+*"] +[tool.ruff.per-file-ignores] +"__init__.py" = ["F401"] # Ignore `F401` (unused-import) in all `__init__.py` files -[tool.flakeheaven.exceptions."**/__init__.py"] -pyflakes = ["-F401"] +[tool.ruff.isort] +known-third-party = ["pygmt"] [tool.pytest.ini_options] minversion = "6.0" addopts = "--verbose --durations=0 --durations-min=0.2 --doctest-modules --mpl --mpl-results-path=results" -[tool.isort] -profile = "black" -skip_gitignore = true -known_third_party = "pygmt" - [tool.pylint.MASTER] # Use multiple processes to speed up Pylint. Specifying 0 will auto-detect the # number of processors available to use. @@ -136,5 +139,5 @@ max-module-lines=2000 disable=[ "duplicate-code", "import-error", - "line-too-long", # Already checked by flakeheaven/pycodestyle + "line-too-long", # Already checked by ruff's pycodestyle ] From ece073013fc85887a99ac7ee4b720639dd0867cb Mon Sep 17 00:00:00 2001 From: Wei Ji <23487320+weiji14@users.noreply.github.com> Date: Sun, 15 Oct 2023 22:59:35 +1300 Subject: [PATCH 2/5] Fix W505 line-too-long lint error by moving noqa after the triple quotes Xref https://github.com/astral-sh/ruff/issues/3972 and https://docs.astral.sh/ruff/configuration/#error-suppression. --- .../projections/cyl/cyl_universal_transverse_mercator.py | 4 ++-- pygmt/datasets/earth_age.py | 4 ++-- pygmt/datasets/earth_free_air_anomaly.py | 4 ++-- pygmt/datasets/earth_geoid.py | 4 ++-- pygmt/datasets/earth_magnetic_anomaly.py | 6 +++--- pygmt/datasets/earth_mask.py | 4 ++-- pygmt/datasets/earth_relief.py | 4 ++-- pygmt/datasets/earth_vertical_gravity_gradient.py | 4 ++-- pygmt/datasets/samples.py | 7 +++---- pygmt/src/nearneighbor.py | 4 ++-- 10 files changed, 22 insertions(+), 23 deletions(-) diff --git a/examples/projections/cyl/cyl_universal_transverse_mercator.py b/examples/projections/cyl/cyl_universal_transverse_mercator.py index 27f2299a48d..6d6c6365cf2 100644 --- a/examples/projections/cyl/cyl_universal_transverse_mercator.py +++ b/examples/projections/cyl/cyl_universal_transverse_mercator.py @@ -14,7 +14,7 @@ .. _GMT_utm_zones: -.. figure:: https://docs.generic-mapping-tools.org/latest/_images/GMT_utm_zones.png # noqa: W505 +.. figure:: https://docs.generic-mapping-tools.org/latest/_images/GMT_utm_zones.png :width: 700 px :align: center @@ -34,7 +34,7 @@ The projection is set with **u** or **U**. *zone* sets the zone for the figure, and the figure size is set with *scale* or *width*. -""" +""" # noqa: W505 # %% import pygmt diff --git a/pygmt/datasets/earth_age.py b/pygmt/datasets/earth_age.py index 8182be77b28..42a598819c9 100644 --- a/pygmt/datasets/earth_age.py +++ b/pygmt/datasets/earth_age.py @@ -15,7 +15,7 @@ def load_earth_age(resolution="01d", region=None, registration=None): r""" Load the Earth seafloor crustal age dataset in various resolutions. - .. figure:: https://www.generic-mapping-tools.org/remote-datasets/_images/GMT_earth_age.png # noqa: W505 + .. figure:: https://www.generic-mapping-tools.org/remote-datasets/_images/GMT_earth_age.png :width: 80 % :align: center @@ -91,7 +91,7 @@ def load_earth_age(resolution="01d", region=None, registration=None): ... region=[120, 160, 30, 60], ... registration="gridline", ... ) - """ + """ # noqa: W505 grid = _load_remote_dataset( dataset_name="earth_age", dataset_prefix="earth_age_", diff --git a/pygmt/datasets/earth_free_air_anomaly.py b/pygmt/datasets/earth_free_air_anomaly.py index 8e411e14359..cc07507d752 100644 --- a/pygmt/datasets/earth_free_air_anomaly.py +++ b/pygmt/datasets/earth_free_air_anomaly.py @@ -16,7 +16,7 @@ def load_earth_free_air_anomaly(resolution="01d", region=None, registration=None Load the IGPP Global Earth Free-Air Anomaly datatset in various resolutions. - .. figure:: https://www.generic-mapping-tools.org/remote-datasets/_images/GMT_earth_faa.jpg # noqa: W505 + .. figure:: https://www.generic-mapping-tools.org/remote-datasets/_images/GMT_earth_faa.jpg :width: 80 % :align: center @@ -95,7 +95,7 @@ def load_earth_free_air_anomaly(resolution="01d", region=None, registration=None ... region=[120, 160, 30, 60], ... registration="gridline", ... ) - """ + """ # noqa: W505 grid = _load_remote_dataset( dataset_name="earth_free_air_anomaly", dataset_prefix="earth_faa_", diff --git a/pygmt/datasets/earth_geoid.py b/pygmt/datasets/earth_geoid.py index 104df50e344..27f07f9e29e 100644 --- a/pygmt/datasets/earth_geoid.py +++ b/pygmt/datasets/earth_geoid.py @@ -15,7 +15,7 @@ def load_earth_geoid(resolution="01d", region=None, registration=None): r""" Load the EGM2008 Global Earth Geoid dataset in various resolutions. - .. figure:: https://www.generic-mapping-tools.org/remote-datasets/_images/GMT_earth_geoid.jpg # noqa: W505 + .. figure:: https://www.generic-mapping-tools.org/remote-datasets/_images/GMT_earth_geoid.jpg :width: 80 % :align: center @@ -84,7 +84,7 @@ def load_earth_geoid(resolution="01d", region=None, registration=None): ... region=[120, 160, 30, 60], ... registration="gridline", ... ) - """ + """ # noqa: W505 grid = _load_remote_dataset( dataset_name="earth_geoid", dataset_prefix="earth_geoid_", diff --git a/pygmt/datasets/earth_magnetic_anomaly.py b/pygmt/datasets/earth_magnetic_anomaly.py index 7372ba486d7..4a52f280824 100644 --- a/pygmt/datasets/earth_magnetic_anomaly.py +++ b/pygmt/datasets/earth_magnetic_anomaly.py @@ -24,8 +24,8 @@ def load_earth_magnetic_anomaly( * - Global Earth Magnetic Anomaly Model (EMAG2) - World Digital Magnetic Anomaly Map (WDMAM) - * - .. figure:: https://www.generic-mapping-tools.org/remote-datasets/_images/GMT_earth_mag4km.jpg # noqa: W505 - - .. figure:: https://www.generic-mapping-tools.org/remote-datasets/_images/GMT_earth_wdmam.jpg # noqa: W505 + * - .. figure:: https://www.generic-mapping-tools.org/remote-datasets/_images/GMT_earth_mag4km.jpg + - .. figure:: https://www.generic-mapping-tools.org/remote-datasets/_images/GMT_earth_wdmam.jpg The grids are downloaded to a user data directory (usually ``~/.gmt/server/earth/earth_mag/``, @@ -132,7 +132,7 @@ def load_earth_magnetic_anomaly( >>> grid = load_earth_magnetic_anomaly( ... resolution="20m", registration="gridline", data_source="wdmam" ... ) - """ + """ # noqa: W505 magnetic_anomaly_sources = { "emag2": "earth_mag_", "emag2_4km": "earth_mag4km_", diff --git a/pygmt/datasets/earth_mask.py b/pygmt/datasets/earth_mask.py index 99bb57f51b2..b87250b0010 100644 --- a/pygmt/datasets/earth_mask.py +++ b/pygmt/datasets/earth_mask.py @@ -15,7 +15,7 @@ def load_earth_mask(resolution="01d", region=None, registration=None): r""" Load the GSHHG Global Earth Mask dataset in various resolutions. - .. figure:: https://www.generic-mapping-tools.org/remote-datasets/_images/GMT_earth_mask.png # noqa: W505 + .. figure:: https://www.generic-mapping-tools.org/remote-datasets/_images/GMT_earth_mask.png :width: 80 % :align: center @@ -88,7 +88,7 @@ def load_earth_mask(resolution="01d", region=None, registration=None): >>> # location (170°E, 50°N) is in oceanic area (0) >>> grid.sel(lon=170, lat=50).values array(0, dtype=int8) - """ + """ # noqa: W505 grid = _load_remote_dataset( dataset_name="earth_mask", dataset_prefix="earth_mask_", diff --git a/pygmt/datasets/earth_relief.py b/pygmt/datasets/earth_relief.py index aa7df5cfbca..53e8e45ec9a 100644 --- a/pygmt/datasets/earth_relief.py +++ b/pygmt/datasets/earth_relief.py @@ -23,7 +23,7 @@ def load_earth_relief( Load the Earth relief datasets (topography and bathymetry) in various resolutions. - .. figure:: https://www.generic-mapping-tools.org/remote-datasets/_images/GMT_earth_gebcosi.jpg # noqa: W505 + .. figure:: https://www.generic-mapping-tools.org/remote-datasets/_images/GMT_earth_gebcosi.jpg :width: 80 % :align: center @@ -136,7 +136,7 @@ def load_earth_relief( ... registration="gridline", ... use_srtm=True, ... ) - """ + """ # noqa: W505 # resolutions of original land-only SRTM tiles from NASA land_only_srtm_resolutions = ["03s", "01s"] diff --git a/pygmt/datasets/earth_vertical_gravity_gradient.py b/pygmt/datasets/earth_vertical_gravity_gradient.py index 30ac2c427f4..c0590efbe24 100644 --- a/pygmt/datasets/earth_vertical_gravity_gradient.py +++ b/pygmt/datasets/earth_vertical_gravity_gradient.py @@ -18,7 +18,7 @@ def load_earth_vertical_gravity_gradient( Load the IGPP Global Earth Vertical Gravity Gradient dataset in various resolutions. - .. figure:: https://www.generic-mapping-tools.org/remote-datasets/_images/GMT_earth_vgg.jpg # noqa: W505 + .. figure:: https://www.generic-mapping-tools.org/remote-datasets/_images/GMT_earth_vgg.jpg :width: 80 % :align: center @@ -97,7 +97,7 @@ def load_earth_vertical_gravity_gradient( ... region=[120, 160, 30, 60], ... registration="gridline", ... ) - """ + """ # noqa: W505 grid = _load_remote_dataset( dataset_name="earth_vgg", dataset_prefix="earth_vgg_", diff --git a/pygmt/datasets/samples.py b/pygmt/datasets/samples.py index 7471ad473c4..3d26a039b72 100644 --- a/pygmt/datasets/samples.py +++ b/pygmt/datasets/samples.py @@ -301,7 +301,6 @@ def list_sample_data(): def load_sample_data(name): - # pylint: disable=line-too-long """ Load an example dataset from the GMT server. @@ -317,8 +316,8 @@ def load_sample_data(name): Returns ------- :class:`pandas.DataFrame` or :class:`xarray.DataArray` - Sample dataset loaded as a :class:`pandas.DataFrame` for tabular data or - :class:`xarray.DataArray` for raster data. + Sample dataset loaded as a :class:`pandas.DataFrame` for tabular data + or :class:`xarray.DataArray` for raster data. See Also -------- @@ -345,7 +344,7 @@ def load_sample_data(name): 'usgs_quakes': 'Table of earthquakes from the USGS'} >>> # load the sample bathymetry dataset >>> data = load_sample_data("bathymetry") - """ + """ # noqa: W505 if name not in datasets: raise GMTInvalidInput(f"Invalid dataset name '{name}'.") return datasets[name].func() diff --git a/pygmt/src/nearneighbor.py b/pygmt/src/nearneighbor.py index 53aa9057dde..ba0bada2e8d 100644 --- a/pygmt/src/nearneighbor.py +++ b/pygmt/src/nearneighbor.py @@ -57,7 +57,7 @@ def nearneighbor(data=None, x=None, y=None, z=None, **kwargs): criteria and :math:`r_i` is the distance from the node to the *i*'th data point. If no data weights are supplied then :math:`w_i = 1`. - .. figure:: https://docs.generic-mapping-tools.org/dev/_images/GMT_nearneighbor.png # noqa: W505 + .. figure:: https://docs.generic-mapping-tools.org/dev/_images/GMT_nearneighbor.png :width: 300 px :align: center @@ -146,7 +146,7 @@ def nearneighbor(data=None, x=None, y=None, z=None, **kwargs): ... region=[245, 255, 20, 30], ... search_radius="10m", ... ) - """ + """ # noqa: W505 with GMTTempFile(suffix=".nc") as tmpfile: with Session() as lib: table_context = lib.virtualfile_from_data( From 03e035750e9f67383d54770e0153b012c253f1f4 Mon Sep 17 00:00:00 2001 From: Wei Ji <23487320+weiji14@users.noreply.github.com> Date: Sun, 15 Oct 2023 23:19:06 +1300 Subject: [PATCH 3/5] Use ruff: isort: on instead of isort: on Xref https://docs.astral.sh/ruff/configuration/#action-comments Co-Authored-By: Dongdong Tian --- doc/conf.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/conf.py b/doc/conf.py index 5356ee1adcc..849d5cd0a38 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -7,7 +7,7 @@ import datetime from importlib.metadata import metadata -# isort: off +# ruff: isort: off from sphinx_gallery.sorting import ( # pylint: disable=no-name-in-module ExplicitOrder, ExampleTitleSortKey, @@ -16,7 +16,7 @@ from pygmt import __commit__, __version__ from pygmt.sphinx_gallery import PyGMTScraper -# isort: on +# ruff: isort: on extensions = [ "myst_parser", From a208ca8b1b4afda87ce9728362fdd5373bd80d94 Mon Sep 17 00:00:00 2001 From: Wei Ji <23487320+weiji14@users.noreply.github.com> Date: Mon, 16 Oct 2023 01:25:57 +1300 Subject: [PATCH 4/5] Try removing all noqa: W505 --- .../projections/cyl/cyl_universal_transverse_mercator.py | 2 +- pygmt/datasets/earth_age.py | 5 ++--- pygmt/datasets/earth_free_air_anomaly.py | 2 +- pygmt/datasets/earth_geoid.py | 2 +- pygmt/datasets/earth_magnetic_anomaly.py | 2 +- pygmt/datasets/earth_mask.py | 2 +- pygmt/datasets/earth_relief.py | 2 +- pygmt/datasets/earth_vertical_gravity_gradient.py | 2 +- pygmt/datasets/samples.py | 4 ++-- pygmt/src/nearneighbor.py | 2 +- 10 files changed, 12 insertions(+), 13 deletions(-) diff --git a/examples/projections/cyl/cyl_universal_transverse_mercator.py b/examples/projections/cyl/cyl_universal_transverse_mercator.py index 6d6c6365cf2..1cd0556c303 100644 --- a/examples/projections/cyl/cyl_universal_transverse_mercator.py +++ b/examples/projections/cyl/cyl_universal_transverse_mercator.py @@ -34,7 +34,7 @@ The projection is set with **u** or **U**. *zone* sets the zone for the figure, and the figure size is set with *scale* or *width*. -""" # noqa: W505 +""" # %% import pygmt diff --git a/pygmt/datasets/earth_age.py b/pygmt/datasets/earth_age.py index 42a598819c9..b9496b98d68 100644 --- a/pygmt/datasets/earth_age.py +++ b/pygmt/datasets/earth_age.py @@ -72,8 +72,7 @@ def load_earth_age(resolution="01d", region=None, registration=None): :class:`xarray.DataArray` grid can be accessed via the GMT accessors (i.e., ``grid.gmt.registration`` and ``grid.gmt.gtype`` respectively). However, these properties may be lost after specific grid operations (such - as slicing) and will need to be manually set before passing the grid to any - PyGMT data processing or plotting functions. Refer to + as slicing) and will need to be manually set before passing the grid to any PyGMT data processing or plotting functions. Refer to :class:`pygmt.GMTDataArrayAccessor` for detailed explanations and workarounds. @@ -91,7 +90,7 @@ def load_earth_age(resolution="01d", region=None, registration=None): ... region=[120, 160, 30, 60], ... registration="gridline", ... ) - """ # noqa: W505 + """ grid = _load_remote_dataset( dataset_name="earth_age", dataset_prefix="earth_age_", diff --git a/pygmt/datasets/earth_free_air_anomaly.py b/pygmt/datasets/earth_free_air_anomaly.py index cc07507d752..f1cc1c4f9c8 100644 --- a/pygmt/datasets/earth_free_air_anomaly.py +++ b/pygmt/datasets/earth_free_air_anomaly.py @@ -95,7 +95,7 @@ def load_earth_free_air_anomaly(resolution="01d", region=None, registration=None ... region=[120, 160, 30, 60], ... registration="gridline", ... ) - """ # noqa: W505 + """ grid = _load_remote_dataset( dataset_name="earth_free_air_anomaly", dataset_prefix="earth_faa_", diff --git a/pygmt/datasets/earth_geoid.py b/pygmt/datasets/earth_geoid.py index 27f07f9e29e..140bb39ffe2 100644 --- a/pygmt/datasets/earth_geoid.py +++ b/pygmt/datasets/earth_geoid.py @@ -84,7 +84,7 @@ def load_earth_geoid(resolution="01d", region=None, registration=None): ... region=[120, 160, 30, 60], ... registration="gridline", ... ) - """ # noqa: W505 + """ grid = _load_remote_dataset( dataset_name="earth_geoid", dataset_prefix="earth_geoid_", diff --git a/pygmt/datasets/earth_magnetic_anomaly.py b/pygmt/datasets/earth_magnetic_anomaly.py index 4a52f280824..e9ec6b9a449 100644 --- a/pygmt/datasets/earth_magnetic_anomaly.py +++ b/pygmt/datasets/earth_magnetic_anomaly.py @@ -132,7 +132,7 @@ def load_earth_magnetic_anomaly( >>> grid = load_earth_magnetic_anomaly( ... resolution="20m", registration="gridline", data_source="wdmam" ... ) - """ # noqa: W505 + """ magnetic_anomaly_sources = { "emag2": "earth_mag_", "emag2_4km": "earth_mag4km_", diff --git a/pygmt/datasets/earth_mask.py b/pygmt/datasets/earth_mask.py index b87250b0010..f9fcc4be5ca 100644 --- a/pygmt/datasets/earth_mask.py +++ b/pygmt/datasets/earth_mask.py @@ -88,7 +88,7 @@ def load_earth_mask(resolution="01d", region=None, registration=None): >>> # location (170°E, 50°N) is in oceanic area (0) >>> grid.sel(lon=170, lat=50).values array(0, dtype=int8) - """ # noqa: W505 + """ grid = _load_remote_dataset( dataset_name="earth_mask", dataset_prefix="earth_mask_", diff --git a/pygmt/datasets/earth_relief.py b/pygmt/datasets/earth_relief.py index 53e8e45ec9a..9236753e413 100644 --- a/pygmt/datasets/earth_relief.py +++ b/pygmt/datasets/earth_relief.py @@ -136,7 +136,7 @@ def load_earth_relief( ... registration="gridline", ... use_srtm=True, ... ) - """ # noqa: W505 + """ # resolutions of original land-only SRTM tiles from NASA land_only_srtm_resolutions = ["03s", "01s"] diff --git a/pygmt/datasets/earth_vertical_gravity_gradient.py b/pygmt/datasets/earth_vertical_gravity_gradient.py index c0590efbe24..0eada0a374c 100644 --- a/pygmt/datasets/earth_vertical_gravity_gradient.py +++ b/pygmt/datasets/earth_vertical_gravity_gradient.py @@ -97,7 +97,7 @@ def load_earth_vertical_gravity_gradient( ... region=[120, 160, 30, 60], ... registration="gridline", ... ) - """ # noqa: W505 + """ grid = _load_remote_dataset( dataset_name="earth_vgg", dataset_prefix="earth_vgg_", diff --git a/pygmt/datasets/samples.py b/pygmt/datasets/samples.py index 3d26a039b72..3fb809799a1 100644 --- a/pygmt/datasets/samples.py +++ b/pygmt/datasets/samples.py @@ -330,7 +330,7 @@ def load_sample_data(name): >>> from pprint import pprint >>> from pygmt.datasets import list_sample_data, load_sample_data >>> # use list_sample_data to see the available datasets - >>> pprint(list_sample_data(), width=120) # noqa: W505 + >>> pprint(list_sample_data(), width=120) {'bathymetry': 'Table of ship bathymetric observations off Baja California', 'earth_relief_holes': 'Regional 20 arc-minutes Earth relief grid with holes', 'fractures': 'Table of hypothetical fracture lengths and azimuths', @@ -344,7 +344,7 @@ def load_sample_data(name): 'usgs_quakes': 'Table of earthquakes from the USGS'} >>> # load the sample bathymetry dataset >>> data = load_sample_data("bathymetry") - """ # noqa: W505 + """ if name not in datasets: raise GMTInvalidInput(f"Invalid dataset name '{name}'.") return datasets[name].func() diff --git a/pygmt/src/nearneighbor.py b/pygmt/src/nearneighbor.py index ba0bada2e8d..cc9c1e5befd 100644 --- a/pygmt/src/nearneighbor.py +++ b/pygmt/src/nearneighbor.py @@ -146,7 +146,7 @@ def nearneighbor(data=None, x=None, y=None, z=None, **kwargs): ... region=[245, 255, 20, 30], ... search_radius="10m", ... ) - """ # noqa: W505 + """ with GMTTempFile(suffix=".nc") as tmpfile: with Session() as lib: table_context = lib.virtualfile_from_data( From b36981162654b2c440b7ba71bb5c34f8b3a9dd3c Mon Sep 17 00:00:00 2001 From: Wei Ji <23487320+weiji14@users.noreply.github.com> Date: Mon, 16 Oct 2023 01:34:44 +1300 Subject: [PATCH 5/5] Fix new W505 line-too-long errors Add noqa: W505 back to pygmt/datasets/samples.py, and trim lines in nearneighbor.py. --- pygmt/datasets/earth_age.py | 3 ++- pygmt/datasets/samples.py | 2 +- pygmt/src/nearneighbor.py | 12 ++++++------ 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/pygmt/datasets/earth_age.py b/pygmt/datasets/earth_age.py index b9496b98d68..8fe3c5f4d66 100644 --- a/pygmt/datasets/earth_age.py +++ b/pygmt/datasets/earth_age.py @@ -72,7 +72,8 @@ def load_earth_age(resolution="01d", region=None, registration=None): :class:`xarray.DataArray` grid can be accessed via the GMT accessors (i.e., ``grid.gmt.registration`` and ``grid.gmt.gtype`` respectively). However, these properties may be lost after specific grid operations (such - as slicing) and will need to be manually set before passing the grid to any PyGMT data processing or plotting functions. Refer to + as slicing) and will need to be manually set before passing the grid to any + PyGMT data processing or plotting functions. Refer to :class:`pygmt.GMTDataArrayAccessor` for detailed explanations and workarounds. diff --git a/pygmt/datasets/samples.py b/pygmt/datasets/samples.py index 3fb809799a1..2733b354b92 100644 --- a/pygmt/datasets/samples.py +++ b/pygmt/datasets/samples.py @@ -344,7 +344,7 @@ def load_sample_data(name): 'usgs_quakes': 'Table of earthquakes from the USGS'} >>> # load the sample bathymetry dataset >>> data = load_sample_data("bathymetry") - """ + """ # noqa: W505 if name not in datasets: raise GMTInvalidInput(f"Invalid dataset name '{name}'.") return datasets[name].func() diff --git a/pygmt/src/nearneighbor.py b/pygmt/src/nearneighbor.py index cc9c1e5befd..704958aa7b0 100644 --- a/pygmt/src/nearneighbor.py +++ b/pygmt/src/nearneighbor.py @@ -40,11 +40,11 @@ def nearneighbor(data=None, x=None, y=None, z=None, **kwargs): r""" Grid table data using a "Nearest neighbor" algorithm. - **nearneighbor** reads arbitrarily located (*x*, *y*, *z*\ [, *w*]) triplets - [quadruplets] and uses a nearest neighbor algorithm to assign a weighted - average value to each node that has one or more data points within a search - radius centered on the node with adequate coverage across a subset of the - chosen sectors. The node value is computed as a weighted mean of the + **nearneighbor** reads arbitrarily located (*x*, *y*, *z*\ [, *w*]) + triplets [quadruplets] and uses a nearest neighbor algorithm to assign a + weighted average value to each node that has one or more data points within + a search radius centered on the node with adequate coverage across a subset + of the chosen sectors. The node value is computed as a weighted mean of the nearest point from each sector inside the search radius. The weighting function and the averaging used is given by: @@ -139,7 +139,7 @@ def nearneighbor(data=None, x=None, y=None, z=None, **kwargs): >>> # Load a sample dataset of bathymetric x, y, and z values >>> data = pygmt.datasets.load_sample_data(name="bathymetry") >>> # Create a new grid with 5 arc-minutes spacing in the designated region - >>> # Set search_radius to only consider points within 10 arc-minutes of a node + >>> # Set search_radius to only take points within 10 arc-minutes of a node >>> output = pygmt.nearneighbor( ... data=data, ... spacing="5m",