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 pre-commit #40

Merged
merged 8 commits into from
Mar 11, 2022
Merged

Add pre-commit #40

merged 8 commits into from
Mar 11, 2022

Conversation

Jorricks
Copy link
Contributor

@Jorricks Jorricks commented Mar 8, 2022

Added the following tools to pre-commit:

  • iSort (import formatter)
  • Black (general formatter)
  • Flake8 (style checker)
  • Mypy (type checker)

Furthermore, modified the README.md to contain new instructions.

Two more things are left to do:

  • Run pre-commit on the entire codebase.
  • Add item to changelog.

@Jorricks Jorricks marked this pull request as draft March 8, 2022 08:33
@Jorricks Jorricks changed the title DRAFT Add pre-commit Add pre-commit Mar 8, 2022
run: npm install -g prettier

- name: Run Prettier --check
run: prettier --check ${GITHUB_WORKSPACE}
Copy link
Owner

Choose a reason for hiding this comment

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

If possible it would be nice to keep Prettier in place, for linting the markdown + YAML files.. (maybe you're already on the case for this..)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ahhh yeah I was wondering why this was here.
My mistake, adding it back :)

Copy link
Contributor Author

@Jorricks Jorricks Mar 8, 2022

Choose a reason for hiding this comment

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

I'll see if I can embed it into pre-commit ;)
Added it back as a pre-commit hook. This will help developers detect these mistakes earlier :)

Copy link
Owner

@ewels ewels Mar 8, 2022

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done ✌️ Let me know what you think :)

@ewels ewels mentioned this pull request Mar 8, 2022
@Jorricks Jorricks force-pushed the add-pre-commit branch 2 times, most recently from b56f9ca to f4a14e4 Compare March 11, 2022 07:26
@Jorricks Jorricks marked this pull request as ready for review March 11, 2022 07:31
@Jorricks
Copy link
Contributor Author

Jorricks commented Mar 11, 2022

@ewels I have done all the required refactoring.
Quick summary:

  • Flake8 has many very restrictive rules. To loosen them up a bit, I added some exception in .flake8. Furthermore, have a couple of noqa: exceptions, but only small hand full.
  • MyPy has been added and with the exception of 3 lines (type: ignore), everything was fine ✌️
  • iSort and black worked their magic as well :)

Sorry that I didn't have more time this week to complete this earlier but I'll be off from today onwards for a week (⛷️).
If you have the time, it would be awesome to see if we can merge it today but only if we are 100% sure everything still works :). Otherwise, no rush and let's see in a week ✌️

Copy link
Owner

@ewels ewels left a comment

Choose a reason for hiding this comment

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

Quickly read over the code and I think it looks great! Love how simple the GA workflow is now.

Couple of comments and would like to test the code locally before merging, but I don't see any issues so should be able to merge today 👍🏻

Kind of curious to see how well this will play with my VSCode plugins.. 😅

Comment on lines 44 to 47
r"""
Pretend to download some files from somewhere.

Multi-line help strings are unwrapped until you use a double newline.
Copy link
Owner

Choose a reason for hiding this comment

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

Intention of this example is to not have a double newline.

Suggested change
r"""
Pretend to download some files from somewhere.
Multi-line help strings are unwrapped until you use a double newline.
"""
Pretend to download some files from somewhere.
Multi-line help strings are unwrapped until you use a double newline.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed this back with noqas

@@ -8,7 +8,7 @@
@click.option(
"--input",
type=click.Path(),
help="Input [magenta bold]file[/]. [dim]\[default: a custom default][/]",
help=r"Input [magenta bold]file[/]. [dim]\[default: a custom default][/]",
Copy link
Owner

Choose a reason for hiding this comment

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

Do we really need these r prefixes?

Suggested change
help=r"Input [magenta bold]file[/]. [dim]\[default: a custom default][/]",
help="Input [magenta bold]file[/]. [dim]\[default: a custom default][/]",

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yess flake8 was complaining about the \.. Let me just add a noqa.

Copy link
Owner

Choose a reason for hiding this comment

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

ah ok, I wondered if there was a reason. The r prefix is also fine, I guess it doesn't make any difference here..

Copy link
Contributor Author

Choose a reason for hiding this comment

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

According to flake8, \[ is an invalid escape.

README.md Show resolved Hide resolved
.pre-commit-config.yaml Outdated Show resolved Hide resolved
.pre-commit-config.yaml Outdated Show resolved Hide resolved
.pre-commit-config.yaml Show resolved Hide resolved
@@ -0,0 +1,58 @@
minimum_pre_commit_version: "2.9.2"
Copy link
Owner

Choose a reason for hiding this comment

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

Maybe a few comment lines at the top explaining what this file is and what it's used for, for n00bs like me?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea.

.github/workflows/pre-commit.yml Show resolved Hide resolved
.flake8 Show resolved Hide resolved
@Jorricks
Copy link
Contributor Author

Thanks for all the good comments @ewels ✌️.
Looking forward to hear how it went when you took this branch for a spin.
As long as there are no other major PRs to be merged, I don't see any reason to rush this.

Copy link
Owner

@ewels ewels left a comment

Choose a reason for hiding this comment

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

Nice changes! Couple of minor docs suggestions..

README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Show resolved Hide resolved
README.md Show resolved Hide resolved
Jorricks and others added 3 commits March 11, 2022 16:09
Added links

Co-authored-by: Phil Ewels <phil.ewels@scilifelab.se>
Add extra information

Co-authored-by: Phil Ewels <phil.ewels@scilifelab.se>
Co-authored-by: Phil Ewels <phil.ewels@scilifelab.se>
@ewels
Copy link
Owner

ewels commented Mar 11, 2022

Oops, sorry about the ❌ It's amazingly difficult to write valid markdown in the GitHub PR plain text editor 😆

Note that for next time you can batch suggestions together if you want instead of doing one commit per comment. This option is only available on the Files changed PR tab though, not Overview.

Copy link
Owner

@ewels ewels left a comment

Choose a reason for hiding this comment

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

Great stuff, thank you! 👏🏻

@ewels ewels merged commit 41451ae into ewels:main Mar 11, 2022
@ewels
Copy link
Owner

ewels commented Mar 11, 2022

Hmm, getting this error in the actions CI:

pyproject.toml: [mypy]: Unrecognized option: scripts-are-modules = True

Any ideas?

The tests seem fairly inconsistent for me too..

  • Running locally flake8 was failing but not giving any error messages (GH actions was fine)
  • I keep fixing all the errors and pushing, then more show up.. 🤔 Is this normal?

@Jorricks
Copy link
Contributor Author

Hmm, getting this error in the actions CI:

pyproject.toml: [mypy]: Unrecognized option: scripts-are-modules = True

Any ideas?

The tests seem fairly inconsistent for me too..

  • Running locally flake8 was failing but not giving any error messages (GH actions was fine)
  • I keep fixing all the errors and pushing, then more show up.. 🤔 Is this normal?

Hey @ewels,

Sorry to hear that!
The scripts are modules thing is because I forgot to rename the - to _. That should fix it.

Regarding the errors that are showing up, running pre-commit run --all should in all cases fix everything. If the behavior is still different in the pipeline then from locally, it can be two things in my experience, either the versions of the tools don't align or it's not correctly picking up the configuration of pyproject/.Flake8. I don't mind taking another look when I'm back or if you give me a particular example I can also see if I can help you debug.
It would be awesome if you could send me a screenshot and a github pipeline URL :)

@ewels
Copy link
Owner

ewels commented Mar 12, 2022

Ah thanks for the tips! I'll take a look after the weekend. Thanks for the quick reply, enjoy your holiday!

Phil

@Jorricks
Copy link
Contributor Author

Ah thanks for the tips! I'll take a look after the weekend. Thanks for the quick reply, enjoy your holiday!

Phil

Thanks! Have a good weekend 🤟

ewels added a commit that referenced this pull request Mar 15, 2022
@ewels
Copy link
Owner

ewels commented Mar 16, 2022

Underscores typo now fixed 👍🏻

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