Skip to content

Commit

Permalink
Removed 3.8
Browse files Browse the repository at this point in the history
Replaced ruff temporary file with stdin/stdout
  • Loading branch information
fyellin committed Oct 11, 2024
1 parent 465b90e commit c54cf5d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 24 deletions.
3 changes: 0 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,6 @@ jobs:
fail-fast: false
matrix:
include:
- name: Test Linux py38
os: ubuntu-latest
pyversion: '3.8'
- name: Test Linux py39
os: ubuntu-latest
pyversion: '3.9'
Expand Down
47 changes: 26 additions & 21 deletions codegen/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,27 +110,32 @@ def format_code(src, singleline=False):
"""Format the given src string. If singleline is True, all function
signatures become single-line, so they can be parsed and updated.
"""

# Use Ruff to format the line. Ruff does not yet have a Python API, so we use its CLI.
with tempfile.NamedTemporaryFile(suffix=".py", delete_on_close=False) as fp:
fp.write(src.encode())
fp.close()

line_length = 320 if singleline else 88
cmd = [
sys.executable,
"-m",
"ruff",
"format",
"--line-length",
str(line_length),
fp.name,
]
p = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
if p.returncode:
raise FormatError(p.stdout.decode(errors="ignore"))
with open(fp.name, "rb") as fp:
result = fp.read().decode()
line_length = 320 if singleline else 88
cmd = [
sys.executable,
"-m",
"ruff",
"format",
"--line-length",
str(line_length),
"--no-cache",
"--stdin-filename",
"tmp.py",
]

p = subprocess.run(cmd, input=src.encode(), capture_output=True)

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")

# Make defs single-line. You'd think that setting the line length
# to a very high number would do the trick, but it does not.
Expand Down

0 comments on commit c54cf5d

Please sign in to comment.