-
Notifications
You must be signed in to change notification settings - Fork 33
Add linting and formatting to linkml-runtime #347
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
base: main
Are you sure you want to change the base?
Conversation
looks like we need to add a parameter to the upstream tests that lets us specify which branch to test against. |
Is this PR still a going concern or has it been abandoned? |
I just forgot about it, but it would be relatively straightforward to rebase it - it was always intended to be considered after #345 and that's in now so it could be done. |
I was going to put in a PR with some ruff formatting/linting, but since this one is already done, it'd be much better to use this instead. Could you update it so it can be re-reviewed if necessary and merged? (I am happy to review.) I think it'd make more sense to use ruff for code formatting -- the output is 99% identical to that of black and it'd be one less dependency. |
@sneakers-the-rat may I propose some changes to make this PR digestible for a reviewer? I would split it into smaller PRs, building each of the following points a PR build upon the previous ones: 1. Add linter configurationsPR including:
This should be a relatively easy review for someone with some 2. Lint and formatPR containing:
A reviewer can simply check if the 3. Enforce linting and formattingPR containing:
This is also easy to review and, if both previous PRs run well, should run really smoothly. From that point on, we start practicing "code lookism" (don't forget never to practice real lookism!). I'm taking the setup available in the https://github.com/linkml/linkml repo as a reference. If you disagree with it, please consider fixing it too. I'm happy to help you on all of it, if desired! |
See also the recently-implemented ruff formatting and linting in linkml-map. |
@ialarmedalien IMO the ruff rules that you use is the most interesting part. Apart from that I can see some relevant differences with the use of ruff in the
|
@Silvanoc I mostly took the path of least change (least resistance) with the linkml-map set up but would prefer to have a standardised formatting/linting set up in as many of the repos as possible (ideally via template, but it would probably have to be manually configured for now). My preference would be:
That makes it easy for devs and contributors to "do the right thing". Initial targets for this set up would be linkml-map, runtime, and the main linkml repo. |
… bunch of actually used imports
997c3e7
to
ed75b2d
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #347 +/- ##
==========================================
- Coverage 63.79% 63.74% -0.06%
==========================================
Files 63 63
Lines 8946 8939 -7
Branches 2587 2589 +2
==========================================
- Hits 5707 5698 -9
Misses 2633 2633
- Partials 606 608 +2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
rebased.
i appreciate the request, but it essentially amounts to completely redoing the PR, so i'm not going to do that. feel free to close this if it's unwanted. i've spent enough time on this doing it the first time and then rebasing it 7 months later. there is no way to make a "reformat the whole package" PR smaller. i don't see the purpose of splitting out adding the linter rules and applying them. it's pretty easy to ctrl+f for "pyproject.toml" in the diff view.
this is exactly how the PR is structured already, modulo rebasing. Side note on pre-commit actions: ime they are exclusionary - current test failures are mysterious to me. It looks like the current snapshots are incorrect, but not sure why this fixes them - notice how the URIs seem to be incorrectly generated with leading |
This PR fixes the upstream test issues but it's awaiting the release of linkml-runtime. Gotta love tightly-coupled packages! |
|
||
[tool.ruff.lint.per-file-ignores] | ||
"tests/**/*.py" = ["F401"] # unused imports | ||
"tests/**/**.py" = ["F841", "E501", "F842", "E741"] # I ain't fixing all that |
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.
😄
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.
Nobody needs nitpicking on tests 😄
Do we need black and ruff as code formatters? Due to the amount of work involved in generating this PR, I would be inclined to merge as-is and make a second PR that removes black and implements any formatting changes that introduces there. Apart from that, LGTM. Do we need another maintainer to take a look and approve? Thank you for all your work here! |
@sneakers-the-rat Sorry if I haven't shown enough sensitivity in my proposal. You invested significant time in this PR and I come proposing that you reformat the whole... As I explain further down, my proposal partially originates from a misunderstanding from my side. I was just making a proposal to make a review easier to accomplish. Let's switch roles. Imagine that I'm the author of this PR and you are considering reviewing it. So you would probably consider following:
Of course option 4 does not only imply proposing a full refactoring of this PR, and that's been my error. I should have asked first for the
That's what I was expecting from you, but to be honest I could not easily identify in your commits which contained only changes made by
pre-commit is optional for developers who want to use it (like me), so I don't see a problem providing it. You don't like it and prefer to let CI tell you that something is wrong? Fine for you. But I personally hate when I push and get to grab a coffee or switch task to check CI after some time and realize that the linter is telling me after 30s that I've spelled a word wrong. |
I would like to shortly illustrate what I had in mind. This branch of mine has all the configurations to apply the same linting and formatting (it's the A developer fetching the above mentioned branch can run the linter and formatter and should get exactly this commit. A reviewer could simply reproduce it and accept the bunch of changes resulting from it. The diff with the branch of this PR contains, in theory, only the changes that you've manually applied. That part should also be relatively easy to review. |
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.
Pending tests fixing
@sneakers-the-rat the issue with the tests is possibly related to linkml/linkml#2648. @dalito can you confirm it? If so, can it be easily fixed? |
The tests failures are exactly as expected until linkml/linkml#2648 is merged. @sneakers-the-rat could edit the first message of this PR to test against linkml/linkml#2648 to get all tests green (as I did here). If required, I can rebase that PR again. |
"Apply linting rules from upstream" "Reformat with black" "Apply ruff safe fixes" "Mid ruff linting" aka manually fixing linter errors (A few smaller, labeled manual changes) The one outlier step is repeating the above process for all the code that has changed since the rebase. The first commit has the commands needed to reproduce each of the programmatic stages of the PR - they are in the tox format action. The other changes that are not uncontroversially linter fixes are described in the OP. One can view the diff between any two commits on github using so im not disagreeing about how taking those steps would make the PR more reviewable, im just saying I already did them.
Just did that, I love that thing.
I am mostly trying to get parity between upstream and this package for now, but afterwards if we want to remove black from both, I take no position on that but could be done together. Last I checked there were some minor places they disagreed with one another? But could be wrong, and it also might not matter. Idk if we take it out and ruff formats the same way, then that seems like it would be fine?? |
I could not recognize it. So it's probably me, that got overwhelmed by the surface (huge amount of changes) without scratching the surface enough. Anyway, I really appreciate the huge effort and, as always, very valuable contribution 🚀 The only intention of my proposal was lowering the review effort to ensure that it finally gets reviewed and merged. |
upstream_repo: dalito/linkml
upstream_branch: issue2578-fix-uri-in-snapshot
edit: not anymore
Builds on: #345The non-modular PR is because the changes to update to 3.9 use the linting rules we're implementing here.
This sets us up with
linkml
UP
- pyupgrade with an override forX | Y
types until 3.9 gets droppedT100
- nopdb
imports or uses (i am guilty of this a lot)I punted on a handful of rules for the
tests
module because there are a lot of violations and it's just in tests, those are mostly assigned values that aren't used, which are fine in tests if a little implicit.Bigass diff, i'm aware, but that's why we add the linter rules, so future diffs are smaller :)
Review spots
To help out review, all the changes here are linter fixes with no functional change except:
linkml_runtime.utils.metamodelcore
- There were a handful of invalid error handling blocks that looked like this:And that isn't valid because
e
is undefined. It's also ambiguous whether or not those values should always pass, and we raise on any other error, or whether we raise those errors if in strict mode. I assumed the latter, so i changed that tolinkml_runtime.loaders.rdf_loader
- there's a reference topyld_jsonld_from_rdflib_graph
and i'm not sure what that is, can't find it anywhere. so i marked itnoqa
linkml_runtime.utils.permissiblevalueimpl:PvFormulaOptions
has a default value that usesEnumDefinition
. That would make a pretty nasty dependency loop if we fixed it, so i just commented it out. This prevented the module from being imported at all, so i suspect this is deprecated.tests.__init__.py
used aneval
call to get a log level, usingeval
that should basically never be done, so i switched it togetattr