Skip to content

Commit

Permalink
fix: older pythons require resource package
Browse files Browse the repository at this point in the history
  • Loading branch information
henryiii committed Jan 28, 2024
1 parent 275de9a commit b5a7d07
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/black/schema.py
Expand Up @@ -8,12 +8,13 @@ def get_schema(tool_name: str = "black") -> Any:
"""Get the stored complete schema for black's settings."""
assert tool_name == "black", "Only black is supported."

loc = "resources/black.schema.json"
pkg = "black.resources"
fname = "black.schema.json"

if sys.version_info < (3, 9):
with importlib.resources.open_text("black", loc, encoding="utf-8") as f:
with importlib.resources.open_text(pkg, fname, encoding="utf-8") as f:
return json.load(f)

schema = importlib.resources.files("black").joinpath(loc) # type: ignore[unreachable]
schema = importlib.resources.files(pkg).joinpath(fname) # type: ignore[unreachable]
with schema.open(encoding="utf-8") as f:
return json.load(f)

0 comments on commit b5a7d07

Please sign in to comment.