Skip to content

Commit

Permalink
package_checks: output dep lists with proper offset
Browse files Browse the repository at this point in the history
**Summary**

Change loader/dumper to ruamel to enable putting out dependency lists with proper offset.
This way the output can directly be copied and pasted into the recipe.

Resolves #3924

Signed-off-by: Thomas Staudinger <[email protected]>
  • Loading branch information
Staudey committed Sep 26, 2024
1 parent 0e04a2d commit 186822d
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions common/CI/package_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
from dataclasses import dataclass
from datetime import datetime, timezone
from enum import Enum
from ruamel.yaml import YAML

Check failure on line 13 in common/CI/package_checks.py

View workflow job for this annotation

GitHub Actions / Python Linting

Cannot find implementation or library stub for module named "ruamel.yaml" [import-not-found]
from ruamel.yaml.compat import StringIO

Check failure on line 14 in common/CI/package_checks.py

View workflow job for this annotation

GitHub Actions / Python Linting

Cannot find implementation or library stub for module named "ruamel.yaml.compat" [import-not-found]

Check failure on line 14 in common/CI/package_checks.py

View workflow job for this annotation

GitHub Actions / Python Linting

See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
from typing import Any, Callable, Dict, List, Optional, TextIO, Tuple, Union
from urllib import request
from xml.etree import ElementTree

import yaml

"""Package is either a Package YML file or Pspec XML file."""
Package = Union['PackageYML', 'PspecXML']

Expand All @@ -29,7 +29,9 @@ class PackageYML:
"""Represents a Package YML file."""

def __init__(self, stream: Any):
self._data = dict(yaml.safe_load(stream))
yaml = YAML(typ='safe', pure=True)
yaml.default_flow_style = False
self._data = dict(yaml.load(stream))

@property
def name(self) -> str:
Expand Down Expand Up @@ -92,7 +94,8 @@ class Config:

@staticmethod
def load(stream: Any) -> 'Config':
return Config(**yaml.safe_load(stream))
yaml = YAML(typ='safe', pure=True)
return Config(**yaml.load(stream))

def __post_init__(self) -> None:
self.freeze = FreezeConfig(**self.freeze) # type: ignore
Expand Down Expand Up @@ -395,7 +398,9 @@ def run(self) -> List[Result]:

def _includes_homepage(self, file: str) -> bool:
with self._open(file) as f:
return 'homepage' in yaml.safe_load(f)
yaml = YAML(typ='safe', pure=True)
yaml.default_flow_style = False
return 'homepage' in yaml.load(f)


class PackageBumped(PullRequestCheck):
Expand Down Expand Up @@ -453,8 +458,18 @@ def _check_deps(self, deps: str, file: str) -> Optional[Result]:
exp = self._sorted(cur)

if cur != exp:
class Dumper(YAML):

Check failure on line 461 in common/CI/package_checks.py

View workflow job for this annotation

GitHub Actions / Python Linting

Class cannot subclass "YAML" (has type "Any") [misc]
def dump(self, data, stream=None, **kw):

Check failure on line 462 in common/CI/package_checks.py

View workflow job for this annotation

GitHub Actions / Python Linting

Function is missing a type annotation [no-untyped-def]
stream = StringIO()
YAML.dump(self, data, stream, **kw)
return stream.getvalue()

yaml = Dumper(typ='safe', pure=True)
yaml.default_flow_style = False
yaml.indent(offset=4, sequence=4)
yaml.prefix_colon = ' '
return Result(file=file, level=self._level, line=self.file_line(file, '^' + deps + r'\s*:'),
message=f'{deps} are not in order, expected: \n' + yaml.safe_dump(exp))
message=f'{deps} are not in order, expected: \n' + yaml.dump(exp))

Check failure on line 472 in common/CI/package_checks.py

View workflow job for this annotation

GitHub Actions / Python Linting

Call to untyped function "dump" in typed context [no-untyped-call]

return None

Expand Down

0 comments on commit 186822d

Please sign in to comment.