mirror of
https://github.com/getsolus/packages.git
synced 2025-04-29 22:30:49 +03:00
package_checks: output dep lists with proper offset (#3928)
**Summary** Change loader/dumper to ruamel to enable putting out dependency lists with proper offset and colon spacing. This way the output can directly be copied and pasted into the recipe. Note: I couldn't find a way to do this with pyyaml; Dumper implementation [adopted from ruamel docs](https://yaml.readthedocs.io/en/latest/example/#output-of-dump-as-a-string). I also couldn't get `top_level_colon_align` to work for some reason, so in cases of very short subpackage names with dependencies the colon might be placed too far to the left (not 100% sure if there is such a case in the repo; the "^g++" case happens to perfectly align) Resolves https://github.com/getsolus/packages/issues/3924 **Test Plan** Old output `budgie-desktop-branding`: ``` - breeze-cursor-theme - budgie-backgrounds - budgie-desktop - font-hack-ttf - livecd: - budgie-desktop-branding - test - materia-gtk-theme - materia-gtk-theme-dark - noto-sans-ttf - noto-serif-ttf - papirus-icon-theme - qtstyleplugins - solus-artwork - test ``` New output `budgie-desktop-branding`: ``` - breeze-cursor-theme - budgie-backgrounds - budgie-desktop - font-hack-ttf - livecd : - budgie-desktop-branding - test - materia-gtk-theme - materia-gtk-theme-dark - noto-sans-ttf - noto-serif-ttf - papirus-icon-theme - qtstyleplugins - solus-artwork - test ``` Old output `gcc` rundeps: ``` - ^g++: gcc - ^gfortran: - gcc - libgfortran - ^libgcc-32bit: libgcc - ^libgfortran-32bit: libgfortran - ^libgomp-32bit: - libgcc-32bit - libgomp - ^libstdc++-32bit: libstdc++ - mpc - mpfr - test ``` New output `gcc` rundeps: ``` - ^g++ : gcc - ^gfortran : - gcc - libgfortran - ^libgcc-32bit : libgcc - ^libgfortran-32bit : libgfortran - ^libgomp-32bit : - libgcc-32bit - libgomp - ^libstdc++-32bit : libstdc++ - mpc - mpfr - test ``` **Checklist** - [x] Package was built and tested against unstable
This commit is contained in:
commit
34d5cba3d5
3 changed files with 26 additions and 8 deletions
5
.github/workflows/package_lint.yml
vendored
5
.github/workflows/package_lint.yml
vendored
|
@ -15,4 +15,7 @@ jobs:
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
- run: common/CI/package_checks.py --base=origin/${{ github.event.pull_request.base.ref }}
|
- run: |
|
||||||
|
sudo apt-get update
|
||||||
|
sudo apt-get install python3-ruamel.yaml
|
||||||
|
common/CI/package_checks.py --base=origin/${{ github.event.pull_request.base.ref }}
|
||||||
|
|
2
.github/workflows/script_lint.yml
vendored
2
.github/workflows/script_lint.yml
vendored
|
@ -33,7 +33,7 @@ jobs:
|
||||||
with:
|
with:
|
||||||
path: common/CI common/Hooks common/Scripts/worklog.py
|
path: common/CI common/Hooks common/Scripts/worklog.py
|
||||||
python_version: "3.10"
|
python_version: "3.10"
|
||||||
requirements: types-PyYAML
|
requirements: ruamel.yaml types-PyYAML
|
||||||
ShellCheck:
|
ShellCheck:
|
||||||
name: ShellCheck
|
name: ShellCheck
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
|
@ -11,12 +11,12 @@ import sys
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from datetime import datetime, timezone
|
from datetime import datetime, timezone
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
|
from ruamel.yaml import YAML
|
||||||
|
from ruamel.yaml.compat import StringIO
|
||||||
from typing import Any, Callable, Dict, List, Optional, TextIO, Tuple, Union
|
from typing import Any, Callable, Dict, List, Optional, TextIO, Tuple, Union
|
||||||
from urllib import request
|
from urllib import request
|
||||||
from xml.etree import ElementTree
|
from xml.etree import ElementTree
|
||||||
|
|
||||||
import yaml
|
|
||||||
|
|
||||||
"""Package is either a Package YML file or Pspec XML file."""
|
"""Package is either a Package YML file or Pspec XML file."""
|
||||||
Package = Union['PackageYML', 'PspecXML']
|
Package = Union['PackageYML', 'PspecXML']
|
||||||
|
|
||||||
|
@ -30,7 +30,9 @@ class PackageYML:
|
||||||
"""Represents a Package YML file."""
|
"""Represents a Package YML file."""
|
||||||
|
|
||||||
def __init__(self, stream: Any):
|
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
|
@property
|
||||||
def name(self) -> str:
|
def name(self) -> str:
|
||||||
|
@ -105,7 +107,8 @@ class Config:
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def load(stream: Any) -> 'Config':
|
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:
|
def __post_init__(self) -> None:
|
||||||
self.freeze = FreezeConfig(**self.freeze) # type: ignore
|
self.freeze = FreezeConfig(**self.freeze) # type: ignore
|
||||||
|
@ -409,7 +412,9 @@ class Homepage(PullRequestCheck):
|
||||||
|
|
||||||
def _includes_homepage(self, file: str) -> bool:
|
def _includes_homepage(self, file: str) -> bool:
|
||||||
with self._open(file) as f:
|
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):
|
class PackageBumped(PullRequestCheck):
|
||||||
|
@ -467,8 +472,18 @@ class PackageDependenciesOrder(PullRequestCheck):
|
||||||
exp = self._sorted(cur)
|
exp = self._sorted(cur)
|
||||||
|
|
||||||
if cur != exp:
|
if cur != exp:
|
||||||
|
class Dumper(YAML):
|
||||||
|
def dump(self, data: Any, stream: Optional[StringIO] = None, **kw: int) -> Any:
|
||||||
|
self.default_flow_style = False
|
||||||
|
self.indent(offset=4, sequence=4)
|
||||||
|
self.prefix_colon = ' ' # type: ignore[assignment]
|
||||||
|
stream = StringIO()
|
||||||
|
YAML.dump(self, data, stream, **kw)
|
||||||
|
return stream.getvalue()
|
||||||
|
|
||||||
|
yaml = Dumper(typ='safe', pure=True)
|
||||||
return Result(file=file, level=self._level, line=self.file_line(file, '^' + deps + r'\s*:'),
|
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))
|
||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue