Skip to content

Commit

Permalink
Don't textwrap toml scenarios
Browse files Browse the repository at this point in the history
Unlike json scenarios, toml and yaml scenarios have multi-line description fields, in which we can write proper markdown. Textwrap doesn't understand markdown and mangles it. To fix astral-sh/uv#5441 (comment), we stop textwrapping toml and yaml files.

I've tested this locally and the snapshots look better, due to astral-sh/uv#5475 is somewhat incomplete though: astral-sh/uv#5441.
  • Loading branch information
konstin committed Aug 6, 2024
1 parent 8fb45e9 commit a35500e
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/packse/scenario.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,11 @@ class Scenario(msgspec.Struct, forbid_unknown_fields=True):
The description of the scenario.
"""

_textwrap: bool = False
"""
Whether to wrap long lines in the scenario description (`.json` scenarios) or not (`.toml` or `.yaml` scenarios).
"""

def hash(self) -> str:
"""
Return a hash of the scenario contents
Expand All @@ -298,9 +303,17 @@ def dict(self) -> dict:
return json.loads(enc.encode(self))


def _load(target: Path, type: Type):
def _load[T: Scenario | list[Scenario]](target: Path, type: Type[T]) -> T:
if target.suffix == ".json":
return msgspec.json.decode(target.read_text(), type=type, dec_hook=dec_hook)
loaded = msgspec.json.decode(target.read_text(), type=type, dec_hook=dec_hook)
# json scenarios have unformatted single line descriptions that we need to wrap for rust docstrings, while
# toml and yaml descriptions are already formatted and should be converted verbatim (with the default: False).
if isinstance(loaded, Scenario):
loaded._textwrap = True
else:
for scenario in loaded:
scenario._textwrap = True
return loaded
elif target.suffix == ".toml":
return msgspec.toml.decode(target.read_text(), type=type, dec_hook=dec_hook)
elif target.suffix == ".yaml":
Expand Down

0 comments on commit a35500e

Please sign in to comment.