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

Python Linting With black #358

Merged
merged 8 commits into from
Nov 4, 2024
Merged

Python Linting With black #358

merged 8 commits into from
Nov 4, 2024

Conversation

TimothyWillard
Copy link
Contributor

@TimothyWillard TimothyWillard commented Oct 24, 2024

Describe your changes.

This pull request:

  1. Adds a GitHub action to use for code linting. For now only applies the black formatter to python code, but general enough that it could be expanded in the future (i.e. using more detailed tools like pylint or ruff or linting for other files like yaml, [Feature request]: YAML Linting #343, or R).
  2. Applies the black formatter to the python files contained in the repo. The exact command used was black . --line-length 92 --extend-exclude flepimop/gempyor_pkg/src/gempyor/steps_rk4.py.
  3. This PR also uses the --verbose option with the black formatter, I view this as a temporary thing as we transition to formatting code and as folks get used to it we can then get rid of it since it is a bit too much output for a GitHub action.

Open questions:

  1. What do we think of the changed files, aesthetically do they look good?
  2. I'll update the docs with whatever we end up settling on, but are there better ways to encourage use? Git pre-commit hooks are an option but then have to figure out how to support windows, could use a package for managing those like pre-commit but that requires a new tool, or could write some pre-push script but then have to maintain the same actions in more than one place. Thoughts (can also push to an issue if too gnarly for this PR)?
  3. I excluded the steps_rk4.py that was mentioned by name in the previous PR Initial python linting #282 (comment). I'm sympathetic to the fact that this file is hard to read when line lengths are shorter, but I think this is a sign that it needs to be refactored at some point which is beyond the scope of this issue. For now we can skip it and then address in a dedicated issue?

What does your pull request address? Tag relevant issues.

This pull request starts to address GH-279 and replaces GH-282 (I was concerned about making the right git maneuvers to get that into shape since it is over two months old so opting to close instead).

Tag relevant team members.

@emprzy @fang19911030 @jcblemai @pearsonca @saraloo @shauntruelove

Added an initial GitHub action for linting, currently only contains
black formatter for python, but general enough for other linting in the
future.
The exact command ran was `black . --line-length 92 --extend-exclude
flepimop/gempyor_pkg/src/gempyor/steps_rk4.py`.
@TimothyWillard TimothyWillard force-pushed the GH-279/linting-with-black branch from 6f9bd15 to 3331eb8 Compare October 24, 2024 14:57
@TimothyWillard TimothyWillard added enhancement Request for improvement or addition of new feature(s). gempyor Concerns the Python core. low priority Low priority. quick issue Short or easy fix. labels Oct 24, 2024
Copy link
Contributor

@pearsonca pearsonca left a comment

Choose a reason for hiding this comment

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

code formatting looks fine - one note about the action itself in comment below (for other's to chime in on as well).

One additional ask: can we have an "easy mode" either script or documentation update about how to apply the check on the local end?

Comment on lines 3 to 14
on:
workflow_dispatch:
push:
paths:
- '**/*.py'
branches:
- main
pull_request:
paths:
- '**/*.py'
branches:
- main
Copy link
Contributor

Choose a reason for hiding this comment

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

what do we think about restricting this to the package materials, but expanding it to more branches?

I definitely want less non-library code in the repo moving forward, and linting is generally good, but ... seems like it might be an unnecessary headache for operations for the library-adjacent code, while letting too much mess accumulate in library for the operational branches that we want to merge back in.

@pearsonca
Copy link
Contributor

code formatting looks fine - one note about the action itself in comment below (for other's to chime in on as well).

One additional ask: can we have an "easy mode" either script or documentation update about how to apply the check on the local end?

So to offer opinion on open Qs:

  1. Yes
  2. pre-commit hook works for me - probably fine to ignore development on windows machines. is the plan here to have linting be potentially merge-blocking as well? if that's the case, everyone can still see the CI, just a bit more work for the already more annoying dev platform to contribute
  3. yep, separate issue. I remain slighly agog that we have our own RK4 implementation at all.

@TimothyWillard
Copy link
Contributor Author

Offline discussion between @jcblemai, @pearsonca, and I:

  • Pre-commit hook is good and simple, can support Mac+Linux first and if needed add Windows support in a separate issue (will require assistance of someone who knows windows dev).
  • Want to trigger the action on:
    • Pushes to any branch for files contained in a package (only gempyor at this point) for quick feedback while folks work.
    • Pull requests to main for all python files.
  • It's important to note that linting does not block pushing/merging, that would be at reviewer discretion, but provides strong encouragement.

jcblemai
jcblemai previously approved these changes Oct 25, 2024
Action now triggers on a push to any branch that modifies gempyor for
quick feedback and pull request with any modified python files.
Added a quick pre-commit hook that will apply the black formatter with
the same params used in the GitHub action.
Updated the documentation to reflect the new usage of `black` and how to
use the pre commit git hook.
pearsonca
pearsonca previously approved these changes Oct 25, 2024
Copy link
Contributor

@pearsonca pearsonca left a comment

Choose a reason for hiding this comment

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

Looks good. Doc add re process is nice.

jcblemai
jcblemai previously approved these changes Oct 25, 2024
@TimothyWillard TimothyWillard dismissed stale reviews from jcblemai and pearsonca via 8e67ca8 October 30, 2024 16:10
jcblemai
jcblemai previously approved these changes Oct 30, 2024
emprzy
emprzy previously approved these changes Oct 30, 2024
TimothyWillard added a commit that referenced this pull request Oct 31, 2024
In anticipation of GH-358, minimize future work.
Copy link
Collaborator

@MacdonaldJoshuaCaleb MacdonaldJoshuaCaleb left a comment

Choose a reason for hiding this comment

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

This is a really nice quality of life feature, thanks for working on this

Add a utility per @fang19911030 request to apply `black` with the same
settings that the GitHub action uses.
Copy link
Contributor

@saraloo saraloo left a comment

Choose a reason for hiding this comment

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

Thanks, this looks good to me. Just noting agreement that we should adapt something similar for R code too later down the line.

@TimothyWillard TimothyWillard merged commit 1bd4a94 into main Nov 4, 2024
3 checks passed
@TimothyWillard TimothyWillard deleted the GH-279/linting-with-black branch November 4, 2024 17:56
TimothyWillard added a commit that referenced this pull request Nov 4, 2024
In anticipation of GH-358, minimize future work.
TimothyWillard added a commit that referenced this pull request Nov 8, 2024
In anticipation of GH-358, minimize future work.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Request for improvement or addition of new feature(s). gempyor Concerns the Python core. low priority Low priority. quick issue Short or easy fix.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants