Skip to content

Commit

Permalink
Merge branch 'main' into slash-command-token
Browse files Browse the repository at this point in the history
  • Loading branch information
seisman committed Jan 4, 2024
2 parents e6b64c8 + 3f9d14b commit 219fa20
Show file tree
Hide file tree
Showing 29 changed files with 205 additions and 170 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/benchmarks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ jobs:
echo $CONDA/bin >> $GITHUB_PATH
conda install --solver=libmamba gmt=6.4.0 python=3.12 \
numpy pandas xarray netCDF4 packaging \
geopandas pytest pytest-benchmark pytest-mpl
geopandas pytest pytest-mpl
python -m pip install -U pytest-codspeed setuptools
# Download cached remote files (artifacts) from GitHub
Expand Down
15 changes: 9 additions & 6 deletions .github/workflows/cache_data.yaml
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
# Cache GMT remote data files and uploads as artifacts
# Cache GMT remote data files and upload as artifacts
#
# This workflow downloads data files needed by PyGMT tests/documentation from
# the GMT data server and uploads as workflow artifacts which can be accessed
# by other GitHub Actions workflows.
#
# It is scheduled to run every Sunday at 12:00 (UTC). If new remote files are
# needed urgently, maintainers can manually uncomment the 'pull_request:' line
# below to refresh the cache.
# needed urgently, maintainers can update the workflow file or
# 'pygmt/helpers/caching.py' file to refresh the cache.
#
name: Cache data

on:
# Uncomment the 'pull_request' line below to manually re-cache data artifacts
# pull_request:
pull_request:
# Make any changes to the following files to refresh the cache
paths:
- 'pygmt/helpers/caching.py'
- '.github/workflows/cache_data.yaml'
# Schedule runs on 12 noon every Sunday
schedule:
- cron: '0 12 * * 0'
Expand Down Expand Up @@ -61,7 +64,7 @@ jobs:
# Download remote files
- name: Download remote data
run: |
python -c "from pygmt.helpers.testing import download_test_data; download_test_data()"
python -c "from pygmt.helpers.caching import cache_data; cache_data()"
# Upload the downloaded files as artifacts to GitHub
- name: Upload artifacts to GitHub
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci_docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ jobs:
channels:
- conda-forge
- nodefaults
cache-downloads: true
cache-downloads: false
cache-environment: true
create-args: >-
python=3.12
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci_tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ jobs:
channels:
- conda-forge
- nodefaults
cache-downloads: true
cache-downloads: false
cache-environment: true
create-args: >-
python=${{ matrix.python-version }}${{ matrix.optional-packages }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci_tests_dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ jobs:
channels:
- conda-forge
- nodefaults
cache-downloads: true
cache-downloads: false
cache-environment: true
create-args: >-
python=3.12
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci_tests_legacy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ jobs:
channels:
- conda-forge
- nodefaults
cache-downloads: true
cache-downloads: false
cache-environment: true
create-args: >-
python=3.9
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/format-command.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
# Install formatting tools
- name: Install formatting tools
run: |
python -m pip install docformatter ruff
python -m pip install ruff
python -m pip list
sudo apt-get install dos2unix
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/style_checks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ jobs:

- name: Install packages
run: |
python -m pip install docformatter ruff
python -m pip install ruff
python -m pip list
sudo apt-get install dos2unix
- name: Formatting check (docformatter, ruff)
- name: Formatting check (ruff)
run: make check

- name: Ensure files use UNIX line breaks and have 644 permission
Expand Down
6 changes: 2 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 docformatter and ruff to automatically format the code"
@echo " check run code style and quality checks (docformatter and ruff)"
@echo " format run ruff to automatically format the code"
@echo " check run ruff to check code style and quality"
@echo " codespell run codespell to check common misspellings"
@echo " typecheck run mypy for static type check"
@echo " clean clean up build and generated files"
Expand Down Expand Up @@ -60,12 +60,10 @@ test_no_images: PYTEST_ARGS=-o addopts="--verbose --durations=0 --durations-min=
test_no_images: _runtest

format:
docformatter --in-place $(FORMAT_FILES)
ruff check --fix $(FORMAT_FILES)
ruff format $(FORMAT_FILES)

check:
docformatter --check $(FORMAT_FILES)
ruff check $(FORMAT_FILES)
ruff format --check $(FORMAT_FILES)

Expand Down
16 changes: 6 additions & 10 deletions doc/contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ arguments and return values.

While the maximum line length for code is automatically set by ruff, docstrings
must be formatted manually. To play nicely with Jupyter and IPython, **keep docstrings
limited to 79 characters** per line.
limited to 88 characters** per line.

### Standards for Example Code

Expand Down Expand Up @@ -471,14 +471,10 @@ code, be sure to follow the general guidelines in the

### Code Style

We use some tools to format the code so we don't have to think about it:

- [docformatter](https://github.com/myint/docformatter)
- [ruff](https://docs.astral.sh/ruff)

These tools loosely follow the [PEP8](http://pep8.org) guide but with a few
differences. Regardless, you won't have to worry about formatting the code yourself.
Before committing, run it to automatically format your code:
We use the [ruff](https://docs.astral.sh/ruff) tool to format the code, so we
don't have to think about it. It loosely follow the [PEP8](http://pep8.org) guide
but with a few differences. Regardless, you won't have to worry about formatting
the code yourself. Before committing, run it to automatically format your code:

```bash
make format
Expand Down Expand Up @@ -511,7 +507,7 @@ The [`Makefile`](https://github.com/GenericMappingTools/pygmt/blob/main/Makefile
contains rules for running the linter checks:

```bash
make check # Runs docformatter and ruff (in check mode)
make check # Runs ruff in check mode
```

### Testing your Code
Expand Down
1 change: 0 additions & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ dependencies:
- pip
# Dev dependencies (style checks)
- codespell
- docformatter>=1.7.2
- ruff>=0.1.9
# Dev dependencies (unit testing)
- matplotlib
Expand Down
3 changes: 3 additions & 0 deletions examples/gallery/3d_plots/grdview_surface.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
# Define an interesting function of two variables, see:
# https://en.wikipedia.org/wiki/Ackley_function
def ackley(x, y):
"""
Ackley function.
"""
return (
-20 * np.exp(-0.2 * np.sqrt(0.5 * (x**2 + y**2)))
- np.exp(0.5 * (np.cos(2 * np.pi * x) + np.cos(2 * np.pi * y)))
Expand Down
4 changes: 1 addition & 3 deletions examples/gallery/lines/vector_styles.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
The :meth:`pygmt.Figure.plot` method can plot Cartesian, circular, and
geographic vectors. The ``style`` parameter controls vector attributes.
See also
:doc:`Vector attributes example </gallery/lines/vector_heads_tails>`.
See also :doc:`Vector attributes example </gallery/lines/vector_heads_tails>`.
"""

# %%
Expand Down
8 changes: 6 additions & 2 deletions examples/tutorials/advanced/working_with_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,11 @@
)


# Define a function for plotting the single slices
@pn.depends(central_lon=slider_lon)
def view(central_lon):
"""
Define a function for plotting the single slices.
"""
# Create a new instance or object of the pygmt.Figure() class
fig = pygmt.Figure()
fig.coast(
Expand Down Expand Up @@ -112,9 +114,11 @@ def view(central_lon):
)


# Define a function for plotting the single slices
@pn.depends(central_lon=slider_lon)
def view(central_lon):
"""
Define a function for plotting the single slices.
"""
# Create a new instance or object of the pygmt.Figure() class
fig = pygmt.Figure()
# Set up a colormap for the elevation in meters
Expand Down
4 changes: 3 additions & 1 deletion pygmt/figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ def __init__(self):
self._activate_figure()

def __del__(self):
# Clean up the temporary directory that stores the previews
"""
Clean up the temporary directory that stores the previews.
"""
if hasattr(self, "_preview_dir"):
self._preview_dir.cleanup()

Expand Down
87 changes: 87 additions & 0 deletions pygmt/helpers/caching.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
"""
Functions for download remote data files as cache.
"""
from pygmt.src import which


def cache_data():
"""
Download GMT remote data files used in PyGMT tests and docs as cache files.
"""
# List of datasets to download
datasets = [
# Earth relief grids
"@earth_gebco_01d_g",
"@earth_gebcosi_01d_g",
"@earth_gebcosi_15m_p",
"@earth_relief_01d_p",
"@earth_relief_01d_g",
"@earth_relief_30m_p",
"@earth_relief_30m_g",
"@earth_relief_10m_p",
"@earth_relief_10m_g",
"@earth_relief_05m_p",
"@earth_relief_05m_g",
"@earth_synbath_01d_g",
# List of tiles of 03s srtm data.
# Names like @N35E135.earth_relief_03s_g.nc are for internal use only.
# The naming scheme may change. DO NOT USE IT IN YOUR SCRIPTS.
"@N30W120.earth_relief_15s_p.nc",
"@N35E135.earth_relief_03s_g.nc",
"@N37W120.earth_relief_03s_g.nc",
"@N00W090.earth_relief_03m_p.nc",
"@N00E135.earth_relief_30s_g.nc",
"@N00W010.earth_relief_15s_p.nc", # Specific grid for 15s test
"@N04W010.earth_relief_03s_g.nc", # Specific grid for 03s test
# Earth synbath relief grid
"@S15W105.earth_synbath_30s_p.nc",
# Earth seafloor age grids
"@earth_age_01d_g",
"@N00W030.earth_age_01m_g.nc", # Specific grid for 01m test
# Earth geoid grids
"@earth_geoid_01d_g",
"@N00W030.earth_geoid_01m_g.nc", # Specific grid for 01m test
# Earth magnetic anomaly grids
"@earth_mag_01d_g",
"@S30W060.earth_mag_02m_p.nc", # Specific grid for 02m test
"@earth_mag4km_01d_g",
"@S30W120.earth_mag4km_02m_p.nc", # Specific grid for 02m test
# Earth mask grid
"@earth_mask_01d_g",
# Earth free-air anomaly grids
"@earth_faa_01d_g",
"@N00W030.earth_faa_01m_p.nc", # Specific grid for 01m test
# Earth vertical gravity gradient grids
"@earth_vgg_01d_g",
"@N00W030.earth_vgg_01m_p.nc", # Specific grid for 01m test
# Earth WDMAM grids
"@earth_wdmam_01d_g",
"@S90E000.earth_wdmam_03m_g.nc", # Specific grid for 03m test
# Earth day/night grids
"@earth_day_01d_p",
# Other cache files
"@capitals.gmt",
"@circuit.png",
"@earth_relief_20m_holes.grd",
"@EGM96_to_36.txt",
"@MaunaLoa_CO2.txt",
"@RidgeTest.shp",
"@RidgeTest.shx",
"@RidgeTest.dbf",
"@RidgeTest.prj",
"@Table_5_11.txt",
"@Table_5_11_mean.xyz",
"@fractures_06.txt",
"@hotspots.txt",
"@ridge.txt",
"@mars370d.txt",
"@srtm_tiles.nc", # needed for 03s and 01s relief data
"@static_earth_relief.nc",
"@ternary.txt",
"@test.dat.nc",
"@tut_bathy.nc",
"@tut_quakes.ngdc",
"@tut_ship.xyz",
"@usgs_quakes_22.txt",
]
which(fname=datasets, download="a")
2 changes: 1 addition & 1 deletion pygmt/helpers/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ def fmt_docstring(module_func):
- J = projection
- R = region
<BLANKLINE>
"""
""" # noqa: D410,D411
filler_text = {}

if hasattr(module_func, "aliases"):
Expand Down
6 changes: 6 additions & 0 deletions pygmt/helpers/tempfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,15 @@ def __init__(self, prefix="pygmt-", suffix=".txt"):
self.name = tmpfile.name

def __enter__(self):
"""
Do nothing but return the object.
"""
return self

def __exit__(self, *args):
"""
Remove the temporary file.
"""
if os.path.exists(self.name):
os.remove(self.name)

Expand Down
Loading

0 comments on commit 219fa20

Please sign in to comment.