-
-
Notifications
You must be signed in to change notification settings - Fork 36
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
Python 3.13. Remove ruff flakiness #614
Conversation
Remove ruff flakiness Better showing of deltas when codegen fails
Python 3.8 reached end-of-live on 8 October, 2024. I can pull the plug on 3.8 at the same time I add 3.13, if you want. |
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.
I suspect this has to do with ruff caching. When I looked up the cli arg to disable caching, I noticed that ruff can also run via stdin/stdout, avoiding the need for a temporary file. Here's a minimal working example:
import subprocess
import sys
FormatError = Exception
cmd = [
sys.executable,
"-m",
"ruff",
"format",
"--line-length",
str(88),
"--no-cache",
"--stdin-filename",
"tmp.py"
]
input = """
foo = 3 + 1 8
"""
p = subprocess.run(cmd, input=input.encode(), stdout=subprocess.PIPE, stderr=subprocess.PIPE)
if p.returncode:
stdout = p.stdout.decode(errors="ignore")
stderr = p.stderr.decode(errors="ignore")
raise FormatError(
f"Could not format source ({p.returncode}).\n\nstdout: "
+ stdout
+ "\n\nstderr: "
+ stderr
)
else:
result = p.stdout.decode(errors="ignore")
print(result)
I also separeted stdout and stderr, as it can be problematic, as seen in pygfx/pygfx#862
Let's do that too :) |
Replaced ruff temporary file with stdin/stdout
Removed 3.8. I suppose we can now use | and |= on dictionaries, and str.removeprefix. |
I was wrong. It requires an administrator to remove the 3.8 requirement. The branch protection rule requiring that the test py38 pass can only be removed by an administrator, and only an administrator can add the requirement for py313. [As a contributor, I can't even see these settings.] I've undone my 3.8 -> 3.9 changes. If someone else wants to make them, just update ci.yml, pyproject.toml, and the comment in start.rst Other changes have been made. ruff now uses stdin/stdout and seems to be doing the right thing. |
This is ready for review and merging. It tests both Python 3.8 and 3.13. It also includes the fixes to get ruff to work through stdin. |
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!
Added test for Python 3.13. (Is it time to remove support for 3.8??)
Codegen was giving me occasional bizarre results because of ruff. Fixed by using a different file each time for "ruff" rather than reusing the same file over and over.
Finding and fixing the bug above required me to print out codegen deltas in a more easily understandable way. I'm keeping those changes.