-
-
Notifications
You must be signed in to change notification settings - Fork 371
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
pythonlib: add linting with ruff #4072
Conversation
5302482
to
1acf3d3
Compare
@jodersky Sir are you working on this or I can take over this to finish line |
I'll finish it, but thanks for proposing your help!
…On Thu, Dec 26, 2024, 14:04 Himanshu Mahajan ***@***.***> wrote:
@jodersky <https://github.com/jodersky> Sir are you working on this or I
can take over this to finish line
—
Reply to this email directly, view it on GitHub
<#4072 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAHV3JB2HVSIVGGCLZWSGFL2HP5G5AVCNFSM6AAAAABS74KNMKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDKNRSGY4DGMJWHA>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
3ed34ba
to
03ed33f
Compare
89178c1
to
d4cf900
Compare
@lihaoyi, I think I'm happy with the linting and formatting part, would you mind giving it a first review? I'll finish up the coverage before final review however. One question I had was about adding something like a |
Thanks will take a look
The goal of the global |
private def configArgs: Task[Seq[os.Shellable]] = Task.Anon { | ||
val cfg = ruffConfigFile() | ||
if (os.exists(cfg.path)) Seq[os.Shellable]("--config", cfg) else Seq.empty[os.Shellable] | ||
} |
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.
os.Shellable
is basically an implicit constructor for conveniently passing Seq[String]
s, so we can probably just use T[Seq[String]]
here instead
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.
The reason why I didn't go with a plain string seq, was to prevent caching: essentially, I want factor out the argument string --config, <path>
, but also want to invalidate the result if the contents of the config file change. I didn't think this through indeed and somehow thought that shellable will handle this (but of course that's wrong).
Ideally this would be a helper function, not a task. However, I'm not sure how I can call others tasks in helper functions.
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.
You can have helper functions that return anonymous tasks, or anoynymous tasks which return a function type
If you want to make a task that invalidates whenever the file changes, you want a Task.Input
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.
You can have helper functions that return anonymous tasks, or anoynymous tasks which return a function type
This sounds like what I'm looking for, thanks!
If you want to make a task that invalidates whenever the file changes, you want a Task.Input
But this wouldn't work if I want the dependents of the task to be invalidated, right?
def foo = Task.Input { "a" }
def bar = Task { foo() }
If I run bar()
, then change "a" to "b", then re-run bar()
, it would not actually be executed. Only foo
would be reevaluated since it's an input, but since its output hasn't changed, bar would not be rerun afterwards.
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.
If you use a Task.Source pointing at the config file, then the contents of the config file changing will cause the returned PathRef to have a different hash, and any task immediately downstream of the config file will be forced to re-evaluate.
Transitive downstream tasks then may or may not invalidate depending on whether the return value of the intermediate tasks changed, which is probably what you want most of the time
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.
Right, what was confusing me was that if I factored out the the command line construction (which contains only the file path, NOT the pathref) as an intermediary to the actual file contents, then it would effectively absorb any changes in the cache chain.
However, after some more reading through the task source code and testing, I think that a Task.Anon is actually sufficient here; there's no need for fancy function-returning tasks.
What I missed was that the results of Anon tasks are never cached, so if an upstream change causes an Anon task to be re-run, its dependents will also be re-run.
Thanks for your explanations!
I think this looks good for me. Apart from coverage, last thing to do would be to add the global |
5b20cf3
to
5f16b40
Compare
1c95d8a
to
182d672
Compare
f5a7b01
to
0f3d477
Compare
As I mentioned directly to you, I've moved coverage to a separate PR |
Add a
RuffModule
, which serves as a code formatter and linter.Note: Ruff can also serve as a drop-in replacement for Black, so we'll use that for formatting too.
Part of #3928