Skip to content

Commit

Permalink
Use ruff format to ensure UNIX line endings in Python files (#2770)
Browse files Browse the repository at this point in the history
* Use ruff format to ensure UNIX line endings in python files
* Position some inline comments differently to make ruff linter happy
* Run ruff check, then ruff format
* Put configs under tool.ruff.lint and sort toml alphabetically
  • Loading branch information
weiji14 committed Nov 16, 2023
1 parent 6ae2072 commit b873c36
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 16 deletions.
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,14 @@ format:
black $(FORMAT_FILES)
blackdoc $(FORMAT_FILES)
ruff check --fix $(FORMAT_FILES)
ruff format $(FORMAT_FILES)

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

codespell:
@codespell
Expand Down
3 changes: 2 additions & 1 deletion pygmt/tests/test_basemap.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ def test_basemap_utm_projection(projection):
works.
"""
projection = projection.replace(
"EPSG_", "EPSG:" # workaround Windows not allowing colons in filenames
"EPSG_",
"EPSG:", # workaround Windows not allowing colons in filenames
)
fig = Figure()
fig.basemap(region=[-52, -50, -12, -11], projection=projection, frame="afg")
Expand Down
20 changes: 10 additions & 10 deletions pygmt/tests/test_clib_loading.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,9 @@ def test_two_broken_libraries(self, mock_ctypes): # pylint: disable=unused-argu
with pytest.raises(GMTCLibNotFoundError, match=msg_regex):
load_libgmt(lib_fullnames=lib_fullnames)

def test_load_brokenlib_invalidpath(
def test_load_brokenlib_invalidpath( # pylint: disable=unused-argument
self, mock_ctypes
): # pylint: disable=unused-argument
):
"""
Case 2: broken library + invalid path.
Expand All @@ -176,36 +176,36 @@ def test_load_brokenlib_invalidpath(
with pytest.raises(GMTCLibNotFoundError, match=msg_regex):
load_libgmt(lib_fullnames=lib_fullnames)

def test_brokenlib_invalidpath_workinglib(
def test_brokenlib_invalidpath_workinglib( # pylint: disable=unused-argument
self, mock_ctypes
): # pylint: disable=unused-argument
):
"""
Case 3: broken library + invalid path + working library.
"""
lib_fullnames = [self.faked_libgmt1, self.invalid_path, self.loaded_libgmt]
assert check_libgmt(load_libgmt(lib_fullnames=lib_fullnames)) is None

def test_invalidpath_brokenlib_workinglib(
def test_invalidpath_brokenlib_workinglib( # pylint: disable=unused-argument
self, mock_ctypes
): # pylint: disable=unused-argument
):
"""
Case 4: invalid path + broken library + working library.
"""
lib_fullnames = [self.invalid_path, self.faked_libgmt1, self.loaded_libgmt]
assert check_libgmt(load_libgmt(lib_fullnames=lib_fullnames)) is None

def test_workinglib_brokenlib_invalidpath(
def test_workinglib_brokenlib_invalidpath( # pylint: disable=unused-argument
self, mock_ctypes
): # pylint: disable=unused-argument
):
"""
Case 5: working library + broken library + invalid path.
"""
lib_fullnames = [self.loaded_libgmt, self.faked_libgmt1, self.invalid_path]
assert check_libgmt(load_libgmt(lib_fullnames=lib_fullnames)) is None

def test_brokenlib_brokenlib_workinglib(
def test_brokenlib_brokenlib_workinglib( # pylint: disable=unused-argument
self, mock_ctypes
): # pylint: disable=unused-argument
):
"""
Case 6: repeating broken libraries + working library.
"""
Expand Down
15 changes: 10 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ wrap-descriptions = 79
[tool.ruff]
line-length = 88 # E501 (line-too-long)
show-source = true

[tool.ruff.format]
line-ending = "lf" # Use UNIX `\n` line endings for all files

[tool.ruff.lint]
select = [
"E", # pycodestyle
"F", # pyflakes
Expand All @@ -99,14 +104,14 @@ select = [
]
ignore = ["E501"] # Avoid enforcing line-length violations

[tool.ruff.pycodestyle]
max-doc-length = 79
[tool.ruff.lint.isort]
known-third-party = ["pygmt"]

[tool.ruff.per-file-ignores]
[tool.ruff.lint.per-file-ignores]
"__init__.py" = ["F401"] # Ignore `F401` (unused-import) in all `__init__.py` files

[tool.ruff.isort]
known-third-party = ["pygmt"]
[tool.ruff.lint.pycodestyle]
max-doc-length = 79

[tool.pytest.ini_options]
minversion = "6.0"
Expand Down

0 comments on commit b873c36

Please sign in to comment.