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

Add Python linter to github actions #1100

Merged
merged 10 commits into from
Jul 29, 2023
Merged

Add Python linter to github actions #1100

merged 10 commits into from
Jul 29, 2023

Conversation

lshamis
Copy link
Contributor

@lshamis lshamis commented Jul 29, 2023

Adding black to the CI as requested here: #949
This PR only adds the check, it does not format. That would make this change larger than I'd like.

Note, that it finds unusual code in tools/star_rod_idx_to_c.py:422

error: cannot format tools/star_rod_idx_to_c.py: cannot use --safe with this file; failed to parse source file AST: f-string: invalid syntax (<unknown>, line 422)

Copy link
Member

@ethteck ethteck left a comment

Choose a reason for hiding this comment

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

Thanks for the PR! A few pieces of feedback

Also, does the new check pass currently? If not, this pr should probably introduce the changes required for it to do so

.github/workflows/lint.yaml Outdated Show resolved Hide resolved
.github/workflows/lint.yaml Outdated Show resolved Hide resolved
.github/workflows/lint.yaml Outdated Show resolved Hide resolved
@ethteck
Copy link
Member

ethteck commented Jul 29, 2023

Also, black is a formatter rather than a linter. For linting, we use mypy. Though I imagine getting that set up and fixing all issues is a lot more work, so we can tackle that later. I'd just rename the pr / step in the yaml to say format rather than lint

@lshamis
Copy link
Contributor Author

lshamis commented Jul 29, 2023

Also, black is a formatter rather than a linter. For linting, we use mypy. Though I imagine getting that set up and fixing all issues is a lot more work, so we can tackle that later. I'd just rename the pr / step in the yaml to say format rather than lint

Renamed py_lint -> py_format
Changed name Python format and lint -> Python format

@lshamis
Copy link
Contributor Author

lshamis commented Jul 29, 2023

Also, does the new check pass currently? If not, this pr should probably introduce the changes required for it to do so

If you like, I can include the ~60 files that would be reformatted.

It would still not pass, though, due to tools/star_rod_idx_to_c.py:422
That line doesn't look like valid Python to me.

@ethteck
Copy link
Member

ethteck commented Jul 29, 2023

Could you add the files, and then I'll fix the issue with that one script?

@lshamis
Copy link
Contributor Author

lshamis commented Jul 29, 2023

Could you add the files, and then I'll fix the issue with that one script?

Done

@ethteck
Copy link
Member

ethteck commented Jul 29, 2023

Since we have the "Lint" workflow off (since c linting is a bag of worms we haven't really figured out yet for this project), this won't run after we merge it. I think it'd be fine if we made a Python Lint workflow (a new yaml) and put this there, which we could enable. Would you like me to do that, or do you want to?

@ethteck
Copy link
Member

ethteck commented Jul 29, 2023

I'm also observing that only the most recent instance --exclude takes effect. So if I exclude diff.py last, it'll exclude that, and if I exclude another thing last, diff.py says it'll be reformatted. I think we want --extend-exclude for subsequent uses of that flag

@marijnvdwerf
Copy link
Collaborator

Wouldn't excludes usually be defined in pyproject.toml? That way you can also run black locally and have it ignore the same files as CI.

@ethteck
Copy link
Member

ethteck commented Jul 29, 2023

I'm not sure, but this isn't really a python project so it seems weird to have such a file for it. I also wouldn't know how to set it up to work with black, but I guess if someone wants to do that, that's cool

@lshamis
Copy link
Contributor Author

lshamis commented Jul 29, 2023

I'm not going to be able to make any changes for another day or so. Feel free to make any further changes and commit without me.

@ethteck
Copy link
Member

ethteck commented Jul 29, 2023

shounds good. Thanks for this effort! Definitely long overdue

@ethteck ethteck requested a review from bates64 July 29, 2023 16:48
@ethteck ethteck linked an issue Jul 29, 2023 that may be closed by this pull request
@bates64
Copy link
Member

bates64 commented Jul 29, 2023

Wouldn't excludes usually be defined in pyproject.toml? That way you can also run black locally and have it ignore the same files as CI.

This would be worth doing before merge I think, to support other editors

@bates64
Copy link
Member

bates64 commented Jul 29, 2023

good pr though, thanks!

@ethteck ethteck merged commit ae66312 into pmret:main Jul 29, 2023
2 checks passed
ethteck added a commit that referenced this pull request Jul 29, 2023
* Add Python linter to github actions

* wip

* Add back splat_ext

* Format files

* C++ -> C

* format 2 files

* split workflow into separate file, line length 120, fix excludes

* -l 120 in ci

* update black locally and apply formatting changes

* pyproject.toject

---------

Co-authored-by: Ethan Roseman <ethteck@gmail.com>
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.

Python scripts aren't formatted using Black
4 participants