Skip to content

Enable ruff's pep8-naming (N) rules #2877

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Dec 15, 2023
Merged

Enable ruff's pep8-naming (N) rules #2877

merged 6 commits into from
Dec 15, 2023

Conversation

seisman
Copy link
Member

@seisman seisman commented Dec 14, 2023

Description of proposed changes
Enable pep8-naming rules to make sure that function/class/variable names follow the PEP8 conventions. This PR fixes the following errors.

ruff check pygmt examples --extend-select=N
pygmt/exceptions.py:38:7: N818 Exception name `GMTInvalidInput` should be named with an Error suffix
   |
38 | class GMTInvalidInput(GMTError):
   |       ^^^^^^^^^^^^^^^ N818
39 |     """
40 |     Raised when the input of a function/method is invalid.
   |

pygmt/exceptions.py:50:7: N818 Exception name `GMTImageComparisonFailure` should be named with an Error suffix
   |
50 | class GMTImageComparisonFailure(AssertionError):
   |       ^^^^^^^^^^^^^^^^^^^^^^^^^ N818
51 |     """
52 |     Raised when a comparison between two images fails.
   |

pygmt/helpers/testing.py:76:5: N806 Variable `ALLOWED_CHARS` in function should be lowercase
   |
74 |     >>> shutil.rmtree(path="tmp_result_images")  # cleanup folder if tests pass
75 |     """
76 |     ALLOWED_CHARS = set(string.digits + string.ascii_letters + "_-[]()")
   |     ^^^^^^^^^^^^^ N806
77 |     KEYWORD_ONLY = inspect.Parameter.KEYWORD_ONLY
   |

pygmt/helpers/testing.py:77:5: N806 Variable `KEYWORD_ONLY` in function should be lowercase
   |
75 |     """
76 |     ALLOWED_CHARS = set(string.digits + string.ascii_letters + "_-[]()")
77 |     KEYWORD_ONLY = inspect.Parameter.KEYWORD_ONLY
   |     ^^^^^^^^^^^^ N806
78 | 
79 |     def decorator(func):
   |

pygmt/src/config.py:9:7: N801 Class name `config` should use CapWords convention 
   |
 9 | class config:
   |       ^^^^^^ N801
10 |     """
11 |     Set GMT defaults globally or locally.
   |

pygmt/src/grdhisteq.py:22:7: N801 Class name `grdhisteq` should use CapWords convention 
   |
22 | class grdhisteq:
   |       ^^^^^^^^^ N801
23 |     r"""
24 |     Perform histogram equalization for a grid.
   |

pygmt/src/triangulate.py:20:7: N801 Class name `triangulate` should use CapWords convention 
   |
20 | class triangulate:
   |       ^^^^^^^^^^^ N801
21 |     """
22 |     Delaunay triangulation or Voronoi partitioning and gridding of Cartesian
   |

Found 7 errors.

@seisman seisman added maintenance Boring but important stuff for the core devs needs review This PR has higher priority and needs review. labels Dec 14, 2023
@seisman seisman added this to the 0.11.0 milestone Dec 14, 2023
Copy link
Member

@yvonnefroehlich yvonnefroehlich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably N has to be added to the pyproject.toml:

pygmt/pyproject.toml

Lines 101 to 116 in 43f8c63

select = [
"B", # flake8-bugbear
"E", # pycodestyle
"F", # pyflakes
"FA", # flake8-future-annotations
"FLY", # flynt
"I", # isort
"ISC", # flake8-implicit-str-concat
"NPY", # numpy
"PD", # pandas-vet
"PIE", # flake8-pie
"PL", # pylint
"SIM", # flake8-simplify
"UP", # pyupgrade
"W", # pycodestyle warnings
]

@seisman
Copy link
Member Author

seisman commented Dec 14, 2023

Probably N has to be added to the pyproject.toml:

pygmt/pyproject.toml

Lines 101 to 116 in 43f8c63

select = [
"B", # flake8-bugbear
"E", # pycodestyle
"F", # pyflakes
"FA", # flake8-future-annotations
"FLY", # flynt
"I", # isort
"ISC", # flake8-implicit-str-concat
"NPY", # numpy
"PD", # pandas-vet
"PIE", # flake8-pie
"PL", # pylint
"SIM", # flake8-simplify
"UP", # pyupgrade
"W", # pycodestyle warnings
]

thanks for catching it. Fixed now.

@seisman seisman merged commit e3d59b2 into main Dec 15, 2023
@seisman seisman deleted the ruff/N branch December 15, 2023 09:33
@seisman seisman removed the needs review This PR has higher priority and needs review. label Dec 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
maintenance Boring but important stuff for the core devs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants