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

Replace flake8 and pylint with ruff #416

Closed
wants to merge 9 commits into from
Closed

Conversation

jongbinjung
Copy link
Collaborator

In case we're still interested in #337

Tried my best to accommodate existing code style.

Also added review dog to github actions, so that it's easier to see broken things in the PR directly

Copy link

Coverage after merging jb/use-ruff into master will be

99.44%

Coverage Report for Changed Files
FileStmtsBranchesFuncsLinesUncovered Lines
tests
   test_cells_and_edges.py100%100%100%100%
   test_error_codes.py100%100%100%100%
   test_h3.py100%100%100%100%
   test_length_area.py100%100%100%100%
   util.py100%100%100%100%
tests/polyfill
   test_h3.py100%100%100%100%
   test_polyfill.py100%100%100%100%
   test_polyfill_ordering.py100%100%100%100%
   test_to_multipoly.py100%100%100%100%
tests/test_apis
   test_basic_int.py100%100%100%100%
   test_basic_str.py100%100%100%100%
   test_collection_inputs.py100%100%100%100%

Copy link

Coverage after merging jb/use-ruff into master will be

99.44%

Coverage Report for Changed Files
FileStmtsBranchesFuncsLinesUncovered Lines
tests
   test_cells_and_edges.py100%100%100%100%
   test_error_codes.py100%100%100%100%
   test_h3.py100%100%100%100%
   test_length_area.py100%100%100%100%
   util.py100%100%100%100%
tests/polyfill
   test_h3.py100%100%100%100%
   test_polyfill.py100%100%100%100%
   test_polyfill_ordering.py100%100%100%100%
   test_to_multipoly.py100%100%100%100%
tests/test_apis
   test_basic_int.py100%100%100%100%
   test_basic_str.py100%100%100%100%
   test_collection_inputs.py100%100%100%100%

Copy link

Coverage after merging jb/use-ruff into master will be

99.44%

Coverage Report for Changed Files
FileStmtsBranchesFuncsLinesUncovered Lines
tests
   test_cells_and_edges.py100%100%100%100%
   test_error_codes.py100%100%100%100%
   test_h3.py100%100%100%100%
   test_length_area.py100%100%100%100%
   util.py100%100%100%100%
tests/polyfill
   test_h3.py100%100%100%100%
   test_polyfill.py100%100%100%100%
   test_polyfill_ordering.py100%100%100%100%
   test_polygon_class.py100%100%100%100%
   test_to_multipoly.py100%100%100%100%
tests/test_apis
   test_basic_int.py100%100%100%100%
   test_basic_str.py100%100%100%100%
   test_collection_inputs.py100%100%100%100%
   test_numpy_int.py100%100%100%100%

Copy link

Coverage after merging jb/use-ruff into master will be

99.43%

Coverage Report for Changed Files
FileStmtsBranchesFuncsLinesUncovered Lines
tests
   test_cells_and_edges.py100%100%100%100%
   test_error_codes.py100%100%100%100%
   test_h3.py100%100%100%100%
   test_length_area.py100%100%100%100%
   util.py100%100%100%100%
tests/polyfill
   test_h3.py100%100%100%100%
   test_polyfill.py100%100%100%100%
   test_polyfill_ordering.py100%100%100%100%
   test_polygon_class.py100%100%100%100%
   test_to_multipoly.py100%100%100%100%
tests/test_apis
   test_basic_int.py100%100%100%100%
   test_basic_str.py100%100%100%100%
   test_collection_inputs.py100%100%100%100%
   test_numpy_int.py100%100%100%100%

Copy link

Coverage after merging jb/use-ruff into master will be

99.43%

Coverage Report for Changed Files
FileStmtsBranchesFuncsLinesUncovered Lines
tests
   test_cells_and_edges.py100%100%100%100%
   test_error_codes.py100%100%100%100%
   test_h3.py100%100%100%100%
   test_length_area.py100%100%100%100%
   util.py100%100%100%100%
tests/polyfill
   test_h3.py100%100%100%100%
   test_polyfill.py100%100%100%100%
   test_polyfill_ordering.py100%100%100%100%
   test_polygon_class.py100%100%100%100%
   test_to_multipoly.py100%100%100%100%
tests/test_apis
   test_basic_int.py100%100%100%100%
   test_basic_str.py100%100%100%100%
   test_collection_inputs.py100%100%100%100%
   test_numpy_int.py100%100%100%100%

Copy link
Contributor

@ajfriend ajfriend left a comment

Choose a reason for hiding this comment

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

I do like adding ruff! And I can mess with the style options later :)

I'm not familiar with review dog. Despite the nice onomatopoeic pairing, can we split out the review dog change to a different PR?

Copy link

Coverage after merging jb/use-ruff into master will be

99.43%

Coverage Report for Changed Files
FileStmtsBranchesFuncsLinesUncovered Lines
tests
   test_cells_and_edges.py100%100%100%100%
   test_error_codes.py100%100%100%100%
   test_h3.py100%100%100%100%
   test_length_area.py100%100%100%100%
   util.py100%100%100%100%
tests/polyfill
   test_h3.py100%100%100%100%
   test_polyfill.py100%100%100%100%
   test_polyfill_ordering.py100%100%100%100%
   test_polygon_class.py100%100%100%100%
   test_to_multipoly.py100%100%100%100%
tests/test_apis
   test_basic_int.py100%100%100%100%
   test_basic_str.py100%100%100%100%
   test_collection_inputs.py100%100%100%100%
   test_numpy_int.py100%100%100%100%

"def plot_shape_and_cells(shape, res=9):\n",
" fig, axs = plt.subplots(1,2, figsize=(10,5), sharex=True, sharey=True)\n",
Copy link
Contributor

Choose a reason for hiding this comment

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

🙄

" (37.778, -122.507),\n",
" (37.733, -122.501)\n",
"]\n",
"outer = [(37.804, -122.412), (37.778, -122.507), (37.733, -122.501)]\n",
Copy link
Contributor

Choose a reason for hiding this comment

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

Worse.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The way a lot of these auto formatters work is that you can add a trailing comma to the last element to force it to have one element per line.

@@ -429,7 +433,13 @@
"poly1 = h3.LatLngPoly([(37.804, -122.412), (37.778, -122.507), (37.733, -122.501)])\n",
"poly2 = h3.LatLngPoly(\n",
" [(37.803, -122.408), (37.736, -122.491), (37.738, -122.380), (37.787, -122.39)],\n",
" [(37.760, -122.441), (37.772, -122.427), (37.773, -122.404), (37.758, -122.401), (37.745, -122.428)]\n",
Copy link
Contributor

Choose a reason for hiding this comment

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

I was about to complain about this, but its inconsistent with what I just said above. 😬

_out_collection,
_out_scalar,
)
Copy link
Contributor

Choose a reason for hiding this comment

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

🙄

Comment on lines +358 to +363
'892830828c7ffff',
'892830828d7ffff',
'8928308289bffff',
'89283082813ffff',
'8928308288fffff',
'89283082883ffff',
Copy link
Contributor

Choose a reason for hiding this comment

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

This is better :)

@@ -400,7 +398,7 @@ def test_multipoly_checks():
def test_3d_geo():
loop = lnglat_open()

loop2d = [(lng, lat) for lng, lat in loop]
loop2d = [(lng, lat) for lng, lat in loop]
Copy link
Contributor

Choose a reason for hiding this comment

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

Worse

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Why? Is there any benefit of having the for in the two loops aligned?

Comment on lines +14 to +16
[31.57, -94.26],
[42.94, -89.38],
[42.68, -110.61],
Copy link
Contributor

Choose a reason for hiding this comment

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

Worse. But i do like that it added the trailing comma :)

[42.32, -91.80],
[41.37, -98.61]
]
hole2 = [[41.37, -98.61], [40.04, -91.80], [42.32, -91.80], [41.37, -98.61]]
Copy link
Contributor

Choose a reason for hiding this comment

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

Worse

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes. Adding the trailing comma will auto fmt this to be element-per-line.

@@ -68,7 +61,7 @@ def test_h3shape_to_cells():
'832b1afffffffff',
'832b1efffffffff',
'832ba9fffffffff',
'832badfffffffff'
'832badfffffffff',
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice

@ajfriend
Copy link
Contributor

I like the idea of ruff, but I don't know if I like these particular rules. Can we start with a minimal ruff config that changes almost nothing, and we can add rules from there?

Maybe just start with the most important rules?

  • double quotes to single quotes
  • trailing commas

:P

Copy link
Collaborator Author

@jongbinjung jongbinjung left a comment

Choose a reason for hiding this comment

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

The formatter (cf. linter) which does the automatic formatting isn't really configurable. The linter is, but if we're just going to use the linter and not autofmt, might as well stick with flake8.

But, I think the issues you pointed out are:

  • Per-element line breaks for collections that are within line length: This can be forced with trailing commas
  • Aligning on the decimal
  • Whitespace preference

The latter two—while not really supported—seem to only come up in tests, where there's a lot of personal "touches" to describe/build test data. So, we could just have the formatter skip unit tests?

" (37.778, -122.507),\n",
" (37.733, -122.501)\n",
"]\n",
"outer = [(37.804, -122.412), (37.778, -122.507), (37.733, -122.501)]\n",
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The way a lot of these auto formatters work is that you can add a trailing comma to the last element to force it to have one element per line.

@@ -400,7 +398,7 @@ def test_multipoly_checks():
def test_3d_geo():
loop = lnglat_open()

loop2d = [(lng, lat) for lng, lat in loop]
loop2d = [(lng, lat) for lng, lat in loop]
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Why? Is there any benefit of having the for in the two loops aligned?

[42.32, -91.80],
[41.37, -98.61]
]
hole2 = [[41.37, -98.61], [40.04, -91.80], [42.32, -91.80], [41.37, -98.61]]
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes. Adding the trailing comma will auto fmt this to be element-per-line.

@ajfriend
Copy link
Contributor

OK, so it sounds like what I'm looking for is just using ruff check --fix, but not ruff format. I'd prefer to start with that, with a minimal set of options that don't change the code much and growing from there. I don't mind dropping the existing options if there's an issue.

ajfriend added a commit that referenced this pull request Oct 27, 2024
ajfriend added a commit that referenced this pull request Oct 27, 2024
* Build 3.13 wheels

* bump to pypa/[email protected]

* a few more 3.13s

* uses: actions/[email protected]

* actions/[email protected]

* docker/[email protected]

* actions/[email protected]

* actions/[email protected]

* pypa/[email protected]

* Steal from #416

* note PR
@ajfriend ajfriend mentioned this pull request Oct 27, 2024
@ajfriend
Copy link
Contributor

Ruff has started to bring me some joy with #428

@ajfriend
Copy link
Contributor

Thanks for this! I stole some ideas and used them in #428

@ajfriend ajfriend closed this Oct 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants