GenericMappingTools / pygmt

A Python interface for the Generic Mapping Tools.
https://www.pygmt.org
BSD 3-Clause "New" or "Revised" License
759 stars 220 forks source link

Move the `pygmt.show_versions` function to a separate file? #3276

Closed seisman closed 5 months ago

seisman commented 5 months ago

The "Style Checks" workflow fails with ruff 0.4.6 because the show_versions() function has too many branches (https://github.com/GenericMappingTools/pygmt/actions/runs/9277819313/job/25527714073):

ruff check pygmt doc/conf.py examples
pygmt/__init__.py:80:5: PLR0915 Too many statements (57 > 50)
   |
80 | def show_versions(file=sys.stdout):
   |     ^^^^^^^^^^^^^ PLR09[15](https://github.com/GenericMappingTools/pygmt/actions/runs/9277819313/job/25527714073#step:5:16)
81 |     """
82 |     Print various dependency versions which are useful when submitting bug reports.
   |

Found 1 error.
make: *** [Makefile:66: check] Error 1
Error: Process completed with exit code 2.

The show_versions() function is also long with ~100 lines. Perhaps we should move it out of the pygmt/__init__.py file. Maybe pygmt/show_versions.py?

https://github.com/GenericMappingTools/pygmt/blob/09e23522f99f80b724a572850198a01aa0d986e4/pygmt/__init__.py#L80

weiji14 commented 5 months ago

Oops, didn't see this when I opened #3277. I managed to fit things under 50 statements to fix the lint error, but we could move the show_versions() function if needed?

seisman commented 5 months ago

I prefer to move the show_versions function to:

  1. Keep the pygmt/__init__.py file shorter
  2. Move the private functions like _get_ghostscript_version out of the show_versions function so that we can better test them.
weiji14 commented 5 months ago

Ok, I can move the function. Looking around, maybe we can put it under _show_versions.py following https://github.com/corteva/rioxarray/blob/0.15.5/rioxarray/_show_versions.py and https://github.com/scikit-learn/scikit-learn/blob/1.5.0/sklearn/utils/_show_versions.py? Other libraries like xarray puts it under util/print_versions.py, and pandas puts it under utils/_print_versions.py