News for hackers. Stuff that matters.
Re:Astral by Night_Thastus on Tuesday April 18, 2023 @02:41PM (#35618113)
Pretty bold to try to replace Flake8 and Black with one tool. I hope they succeed. Would be great to have a tool that does both and is substantially faster.
Re:Astral by senko on Tuesday April 18, 2023 @02:43PM (#35618152)
Indeed.

I do hope they'll expose Ruff as a Python module / API in the future. I'm currently using Black to format Python code that's in-memory (never gets written out to disk).

With Black (as an imported Py module), it's just a matter of passing in a string and getting one back. With Ruff as it is now, I'd have to write that out to disk, spawn Ruff process, then read the formatted file back in. Do that for many files and the speed advantages disappear, and actually it's slower.

Re:Astral by BiteCode_dev on Tuesday April 18, 2023 @02:54PM (#35618309)
You can mount the file system in memory for that, but I see your point.
Re:Astral by zamnos on Tuesday April 18, 2023 @09:03PM (#35622839)
Why doesn't ruff reading/writing from stdin/out, combined with passing the data in with python subprocess.run and os.pipe work here?

    cat bad.py | ruff check --fix --stdin-filename stdin.py - > good.py
Substituting bad.py and good.py for in-memory os.pipe objects for your data. This still involves spawning a subprocess, which can add up, but you're not having to read/write to disk at least.
Re:Astral by senko on Wednesday April 19, 2023 @02:54AM (#35625099)
It does work. The tradeoff is:

* run ruff command many times (with different input file each time) * write all the files to "disk" (tempfs actually so it doesn't involve disk access) and run ruff once

Currently with black I avoid that by importing it as a module once so I get the benefits of both (and is simple to boot).

In other comments here I've read that a person heavily involved in Python-Rust interop is also part of the team, so there's hope they'll expose ruff as a module too and magically whisk my dilemma away :-)