Skip to content

Commit

Permalink
add ruff_format_str
Browse files Browse the repository at this point in the history
  • Loading branch information
mattijn committed Oct 29, 2023
1 parent 92c6d3d commit 479e86e
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions tools/update_init_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@
"""
import inspect
import sys
import subprocess
from pathlib import Path
from os.path import abspath, dirname, join
from typing import TypeVar, Type, cast, List, Any, Optional, Iterable, Union

import black

if sys.version_info >= (3, 11):
from typing import Self
else:
Expand Down Expand Up @@ -58,13 +57,24 @@ def update__all__variable() -> None:
+ lines[last_definition_line + 1 :]
)
# Format file content with black
new_file_content = black.format_str("\n".join(new_lines), mode=black.Mode())
new_file_content = ruff_format_str("\n".join(new_lines))

# Write new version of altair/__init__.py
with open(init_path, "w") as f:
f.write(new_file_content)


def ruff_format_str(code: str) -> str:
r = subprocess.run(
# Name of the file does not seem to matter but ruff requires one
["ruff", "format", "--stdin-filename", "placeholder.py"],
input=code.encode(),
check=True,
capture_output=True,
)
return r.stdout.decode()


def _is_relevant_attribute(attr_name: str) -> bool:
attr = getattr(alt, attr_name)
if (
Expand Down

0 comments on commit 479e86e

Please sign in to comment.