Skip to content
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

Use ruff format to ensure UNIX line endings in Python files #2770

Merged
merged 7 commits into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 = [
]
Copy link
Member

Choose a reason for hiding this comment

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

See https://docs.astral.sh/ruff/configuration/.

select should be in the [tool.ruff.lint] section and [tool.ruff.per-file-ignores] should be [tool.ruff.lint.per-file-ignores].

I think it also make sense to sort the section by the following order:

[tool.ruff]

[tool.ruff.lint]

[tool.ruff.lint.per-file-ignores]

[tool.ruff.format]

# tool-specific configurations
[tool.ruff.isort]

[tool.ruff.pycodestyle]

We probably also want to require ruff>=0.1.3.

Copy link
Member Author

@weiji14 weiji14 Nov 16, 2023

Choose a reason for hiding this comment

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

Hmm, did they change the TOML config settings recently? I see pycodestyle is now under tool.ruff.lint.pycodestyle, and isort is under tool.ruff.lint.isort. Let me fix these up.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done in 8c58089.

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
Loading