Skip to content

Darker diffs should be apply-able, or command should autofix #105762

Open
@keith

Description

@keith

I got this great python formatter comment on my PR:

#105759 (comment)

copied content in case it gets deleted:

⚠️ Python code formatter, darker found issues in your code. ⚠️

You can test this locally with the following command:
darker --check --diff -r 09a275e8a4c2cea22bb67c7247fc892d5e73eb42...09671451af93ebe468971bc3e3b9882d09b7f354 llvm/utils/lit/lit/TestRunner.py
View the diff from darker here.
--- TestRunner.py	2024-08-23 00:57:43.000000 +0000
+++ TestRunner.py	2024-08-23 01:04:52.524386 +0000
@@ -1222,12 +1222,14 @@
                     commands[i] += f" && {{ {command}; }}"
         if test.config.pipefail:
             f.write(b"set -o pipefail;" if mode == "wb" else "set -o pipefail;")
         f.write(b"set -x;" if mode == "wb" else "set -x;")
 
-        env_str = "\n".join("export {}={};".format(k, shlex.quote(v))
-                            for k, v in test.config.environment.items())
+        env_str = "\n".join(
+            "export {}={};".format(k, shlex.quote(v))
+            for k, v in test.config.environment.items()
+        )
         f.write(bytes(env_str, "utf-8") if mode == "wb" else env_str)
 
         if sys.version_info > (3, 0) and mode == "wb":
             f.write(bytes("{ " + "; } &&\n{ ".join(commands) + "; }", "utf-8"))
         else:

But neither this command or diff are exactly what I was hoping for. I was hoping that either the darker command could be updated to just apply the diff, which it doesn't seem like it can:

darker 09a275e8a4c2cea22bb67c7247fc892d5e73eb42...09671451af93ebe468971bc3e3b9882d09b7f354 llvm/utils/lit/lit/TestRunner.py
argument PATH: Error: Path(s) '09a275e8a4c2cea22bb67c7247fc892d5e73eb42...09671451af93ebe468971bc3e3b9882d09b7f354' do not exist in the working tree

Or I'd be able to copy and paste the diff contents and run git apply which I cannot because the path is not TestRunner.py, so git is expecting it to be llvm/utils/lit/lit/TestRunner.py. If I manually update the paths in the diff to be:

--- a/llvm/utils/lit/lit/TestRunner.py
+++ b/llvm/utils/lit/lit/TestRunner.py

Then applying it works, but I think it would be nice if either of these options worked without this extra step.

I might be missing another command line flag here too, in which case I think it would be nice to add the automatic fix instructions to the comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    infrastructureBugs about LLVM infrastructure

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions