From 5830cbf6c212fbde46645178b0125f4d267acab9 Mon Sep 17 00:00:00 2001 From: Mike Taves Date: Thu, 22 May 2025 13:58:24 +1200 Subject: [PATCH 1/3] MNT: replace black and isort with ruff format and lint --- .isort.cfg | 3 --- .pre-commit-config.yaml | 14 +++----------- .stickler.yml | 2 -- CONTRIBUTING.md | 6 +++--- pyproj/__init__.py | 12 ++++++------ pyproj/crs/__init__.py | 4 ++-- pyproj/geod.py | 4 ++-- pyproj/transformer.py | 9 ++++----- pyproject.toml | 10 ++++------ requirements-dev.txt | 3 ++- test/test_doctest_wrapper.py | 6 +++--- test/test_transformer.py | 3 +-- 12 files changed, 30 insertions(+), 46 deletions(-) delete mode 100644 .isort.cfg diff --git a/.isort.cfg b/.isort.cfg deleted file mode 100644 index 130035f78..000000000 --- a/.isort.cfg +++ /dev/null @@ -1,3 +0,0 @@ -[settings] -known_first_party=pyproj,test -profile=black diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 031e2e2fb..e3adc766f 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -8,15 +8,6 @@ repos: - id: check-yaml - id: end-of-file-fixer - id: trailing-whitespace - - repo: https://github.com/psf/black-pre-commit-mirror - rev: 24.2.0 - hooks: - - id: black - - repo: https://github.com/pycqa/isort - rev: 5.13.2 - hooks: - - id: isort - args: [setup.py, pyproj/, test/, docs/] - repo: https://github.com/asottile/blacken-docs rev: 1.16.0 hooks: @@ -38,6 +29,7 @@ repos: hooks: - id: codespell - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.7.1 + rev: v0.11.10 hooks: - - id: ruff + - id: ruff-check + - id: ruff-format diff --git a/.stickler.yml b/.stickler.yml index b16e0e9c8..1eab5d44c 100644 --- a/.stickler.yml +++ b/.stickler.yml @@ -1,6 +1,4 @@ linters: - black: - config: ./pyproject.toml flake8: python: 3 max-line-length: 88 diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 15789e1ea..fd2c1f8f8 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -167,10 +167,10 @@ There are plenty of more advanced testing concepts, like dealing with floating p comparisons, parameterizing tests, testing that exceptions are raised, and more. Have a look at the existing tests to get an idea of some of the common patterns. ## Code Style -pyproj uses the Python code style outlined in [PEP8](https://pep8.org) and [black](https://github.com/python/black). +pyproj uses the Python code style outlined in [PEP8](https://pep8.org) and by [the Ruff formatter](https://docs.astral.sh/ruff/formatter/). We enforce this style as code is added to keep everything clean and uniform. To this end, part of the automated testing for pyproj checks style. To check style -locally within the source directory you can use the ``flake8`` and ``black`` tools. Running it from the root of the source directory is as easy as running ``pre-commit run --all`` in the base of the repository. +locally within the source directory you can use the ``flake8`` and ``ruff format`` tools. Running it from the root of the source directory is as easy as running ``pre-commit run --all`` in the base of the repository. You can also just submit your PR and the kind robots will comment on all style violations as well. It can be a pain to make sure you have the right number of spaces around things, imports in order, and all of the other nits that the bots will find. It is very important though as this consistent style helps us keep pyproj readable, maintainable, and uniform. @@ -192,7 +192,7 @@ Some things that will increase the chance that your pull request is accepted qui * Write tests. * Follow [PEP8](https://pep8.org) for style. (The `flake8` utility can help with this.) -* Use [black](https://github.com/python/black) +* Use [ruff format](https://docs.astral.sh/ruff/formatter/) * Write a [good commit message](https://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html) and consider using commit [conventions](https://www.conventionalcommits.org/). Pull requests will automatically have tests run by Travis. This includes diff --git a/pyproj/__init__.py b/pyproj/__init__.py index 81eb38bd0..8c2cb089f 100644 --- a/pyproj/__init__.py +++ b/pyproj/__init__.py @@ -73,19 +73,19 @@ __version__ = "3.7.2.dev0" __all__ = [ - "Proj", - "Geod", "CRS", + "Geod", + "Proj", "Transformer", - "transform", - "itransform", - "pj_ellps", - "pj_list", "get_ellps_map", "get_prime_meridians_map", "get_proj_operations_map", "get_units_map", + "itransform", + "pj_ellps", + "pj_list", "show_versions", + "transform", ] __proj_version__ = PROJ_VERSION_STR proj_version_str = PROJ_VERSION_STR # pylint: disable=invalid-name diff --git a/pyproj/crs/__init__.py b/pyproj/crs/__init__.py index 960136c17..ffbc138ee 100644 --- a/pyproj/crs/__init__.py +++ b/pyproj/crs/__init__.py @@ -27,8 +27,6 @@ from pyproj.exceptions import CRSError # noqa: F401 pylint: disable=unused-import __all__ = [ - "is_proj", - "is_wkt", "CRS", "BoundCRS", "CompoundCRS", @@ -38,4 +36,6 @@ "GeographicCRS", "ProjectedCRS", "VerticalCRS", + "is_proj", + "is_wkt", ] diff --git a/pyproj/geod.py b/pyproj/geod.py index b3988dd67..b2705e77a 100644 --- a/pyproj/geod.py +++ b/pyproj/geod.py @@ -10,10 +10,10 @@ __all__ = [ "Geod", - "pj_ellps", - "geodesic_version_str", "GeodIntermediateFlag", "GeodIntermediateReturn", + "geodesic_version_str", + "pj_ellps", "reverse_azimuth", ] diff --git a/pyproj/transformer.py b/pyproj/transformer.py index 3e878cb85..ec1f24b82 100644 --- a/pyproj/transformer.py +++ b/pyproj/transformer.py @@ -3,11 +3,11 @@ """ __all__ = [ - "transform", - "itransform", + "AreaOfInterest", "Transformer", "TransformerGroup", - "AreaOfInterest", + "itransform", + "transform", ] import threading import warnings @@ -329,8 +329,7 @@ def __init__( if not isinstance(transformer_maker, TransformerMaker): _clear_proj_error() raise ProjError( - "Transformer must be initialized using: " - "'from_crs' or 'from_pipeline'." + "Transformer must be initialized using: 'from_crs' or 'from_pipeline'." ) self._local = TransformerLocal() diff --git a/pyproject.toml b/pyproject.toml index 0c38cf8b1..aba1ba76a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -62,12 +62,8 @@ include = ["pyproj", "pyproj.*"] [tool.setuptools.dynamic] version = {attr = "pyproj.__version__"} -[tool.black] -target_version = ["py310"] - [tool.ruff] line-length = 88 -target-version = "py310" fix = true [tool.ruff.lint] @@ -78,6 +74,8 @@ select = [ "F", # pycodestyle "E", "W", + # isort + "I", # flake8-2020 "YTT", # flake8-bugbear @@ -101,7 +99,7 @@ select = [ # implicit string concatenation "ISC", # type-checking imports - "TCH", + "TC", # comprehensions "C4", # pygrep-hooks @@ -147,7 +145,7 @@ ignore = [ # Rename unused "B007", # Move standard library import into a type-checking block - "TCH003", + "TC003", # Consider f-string instead of string join "FLY002", # Use a list comprehension to create a transformed list diff --git a/requirements-dev.txt b/requirements-dev.txt index ab6379ee4..8217f8b79 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -1,4 +1,5 @@ cython>=0.28.4 mypy -types-certifi pre-commit +ruff +types-certifi diff --git a/test/test_doctest_wrapper.py b/test/test_doctest_wrapper.py index 47502190d..ce2a92cfb 100644 --- a/test/test_doctest_wrapper.py +++ b/test/test_doctest_wrapper.py @@ -33,9 +33,9 @@ def test_doctests(): expected_failure_count = 6 # if the below line fails, doctests have failed - assert ( - failure_count == expected_failure_count - ), f"{failure_count} of the doctests failed" + assert failure_count == expected_failure_count, ( + f"{failure_count} of the doctests failed" + ) @pytest.mark.network diff --git a/test/test_transformer.py b/test/test_transformer.py index 61d327a1a..13a39add8 100644 --- a/test/test_transformer.py +++ b/test/test_transformer.py @@ -592,8 +592,7 @@ def test_transformer__operations__scope_remarks(): assert transformer.scope is None assert [op.scope for op in transformer.operations] == [ "Engineering survey, topographic mapping.", - "Transformation of GDA94 coordinates that have been derived " - "through GNSS CORS.", + "Transformation of GDA94 coordinates that have been derived through GNSS CORS.", "Engineering survey, topographic mapping.", ] assert [str(op.remarks)[:5].strip() for op in transformer.operations] == [ From cd756d85c418437fa6a6d823fd5b3dd0507936fb Mon Sep 17 00:00:00 2001 From: Mike Taves Date: Fri, 23 May 2025 14:36:54 +1200 Subject: [PATCH 2/3] Remove stickler config --- .stickler.yml | 4 ---- 1 file changed, 4 deletions(-) delete mode 100644 .stickler.yml diff --git a/.stickler.yml b/.stickler.yml deleted file mode 100644 index 1eab5d44c..000000000 --- a/.stickler.yml +++ /dev/null @@ -1,4 +0,0 @@ -linters: - flake8: - python: 3 - max-line-length: 88 From 9bd3affeb1e4a645772e1950011e54245ae6dfc3 Mon Sep 17 00:00:00 2001 From: Mike Taves Date: Sun, 25 May 2025 13:39:12 +1200 Subject: [PATCH 3/3] Remove Black badge from README.md --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index 0e550a9c0..a65c7a1c2 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,6 @@ Python interface to [PROJ](http://proj.org) (cartographic projections and coordi PyPI Downloads Anaconda-Server Badge -Code style: black pre-commit DOI