-
Notifications
You must be signed in to change notification settings - Fork 0
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
Bump pre-commit versions + add isort #12
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good to me.
By default, isort will edit files in place. As a pre-commit hook, it will print a message, abort the commit, and invite you to look at what it has done to your files — which may be mixed up with your own unstaged changes. IMHO it would be better for it to do what at least several of the other hooks do: print detailed messages about its complaints and abort the commit, but not affect the files. So I would add: hooks:
- id: isort
name: isort (python)
+ args: [--check, --diff, --color]
+ additional_dependencies: [colorama] |
We also have a problem that we believe in more categories of imports than isort does (by default). For example, our production-pipelines code has: import hailtop.batch as hb
from hailtop.batch.job import Job
from cpg_utils import Path
from cpg_utils.config import get_config because hail is externally-supplied while cpg_utils is CPG-local, and we consider those to be separate categories. OTOH isort will move We may be able to add |
Black, prettier and our own custom pre-commit hooks (https://github.com/populationgenomics/cpg-infrastructure-private/blob/c97c31f9d1fe626e1831c9fbc066a529449837e2/sortyamlfiles.py#L113-L114) modifies files in place too, FWIW this is generally how I use pre-commit to fix auto fixable errors. If still not sure, maybe it's best to wait for the software team meeting to chat about it there. |
@jmarshall, what do you think of Forced Separate: [tool.isort]
py_version = 311
line_length = 88
sections = ['FUTURE', 'STDLIB', 'HAIL', 'CPG', 'THIRDPARTY', 'FIRSTPARTY', 'LOCALFOLDER']
known_hail = [
"hail",
"hailctl",
]
known_cpg = [
"analysis-runner",
"cpg_utils",
"cpg_infra",
"cpg_workflows",
"metamist",
] |
I think that's pretty good, and I'm pleased isort is this configurable. Running it on the production-pipelines repo suggests some tweaks to adjust it to our existing conventions a bit more and also shows that it will probably need a bit of per-repository tweaking:
Per-repository tweaking:
|
Thanks @jmarshall, those suggestions sound great - especially avoiding submodules! Do you mind adding a commit to this branch with your suggestions, maybe a line in the TOML that suggests you might want to tweak these on a per-repo basis? |
Add custom sections for hail and CPG-local imports. Same line length as for other linters, and add a template for listing submodules etc that should not be linted or edited.
Happy new time to bump versions of our pre-commits - it's truly the most magical time of the year.
This time, a new friend
isort
. It's mostly enabled in vscode now, already in ourpyproject.toml
, so time to make things official.