Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

move yaml lib into artcommon lib #1162

Merged
merged 3 commits into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions artcommon/artcommonlib/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@ def remove_suffix(s: str, suffix: str) -> str:
return s[:]


def yaml_handler():
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function needs more describable name, like new_roundtrip_yaml_processor

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function needs more describable name, like new_roundtrip_yaml_processor

yaml = YAML(typ="rt")
yaml.default_flow_style = False
yaml.preserve_quotes = True
yaml.width = 4096
yaml.indent(mapping=2,sequence=4,offset=2)
return yaml


def convert_remote_git_to_https(source_url: str):
"""
Accepts a source git URL in ssh or https format and return it in a normalized
Expand Down
8 changes: 2 additions & 6 deletions pyartcd/pyartcd/pipelines/build_microshift.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@

from artcommonlib.arch_util import brew_arch_for_go_arch
from artcommonlib.assembly import AssemblyTypes
from artcommonlib.util import get_ocp_version_from_group
from artcommonlib.util import get_ocp_version_from_group, yaml_handler
from artcommonlib import exectools
from doozerlib.util import isolate_nightly_name_components
from ghapi.all import GhApi
from ruamel.yaml import YAML
from semver import VersionInfo
from tenacity import retry, stop_after_attempt, wait_fixed

Expand All @@ -30,10 +29,7 @@
default_release_suffix,
get_microshift_builds)

yaml = YAML(typ="rt")
yaml.default_flow_style = False
yaml.preserve_quotes = True
yaml.width = 4096
yaml = yaml_handler()


class BuildMicroShiftPipeline:
Expand Down
8 changes: 2 additions & 6 deletions pyartcd/pyartcd/pipelines/build_microshift_bootc.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@
import asyncio
import traceback
from typing import Optional
from ruamel.yaml import YAML

from artcommonlib.assembly import AssemblyTypes
from artcommonlib.util import get_ocp_version_from_group, isolate_major_minor_in_group
from artcommonlib.util import get_ocp_version_from_group, isolate_major_minor_in_group, yaml_handler
from artcommonlib.konflux.konflux_build_record import KonfluxBuildOutcome, Engine, ArtifactType, KonfluxBuildRecord
from artcommonlib.konflux.konflux_db import KonfluxDb
from artcommonlib.arch_util import brew_arch_for_go_arch
Expand All @@ -27,10 +26,7 @@
from pyartcd.plashets import build_plashets, plashet_config_for_major_minor
from doozerlib.constants import ART_DEFAULT_IMAGE_REPO

yaml = YAML(typ="rt")
yaml.default_flow_style = False
yaml.preserve_quotes = True
yaml.width = 4096
yaml = yaml_handler()


class BuildMicroShiftBootcPipeline:
Expand Down
8 changes: 2 additions & 6 deletions pyartcd/pyartcd/pipelines/gen_assembly.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@
import aiohttp
import click
from ghapi.all import GhApi
from ruamel.yaml import YAML

from artcommonlib.util import split_git_url, merge_objects, get_inflight, isolate_major_minor_in_group
from artcommonlib.util import split_git_url, merge_objects, get_inflight, isolate_major_minor_in_group, yaml_handler
from artcommonlib import exectools
from doozerlib.cli.get_nightlies import rc_api_url
from pyartcd import constants, jenkins
Expand All @@ -21,10 +20,7 @@
from pyartcd.jenkins import start_build_sync
from pyartcd.runtime import Runtime

yaml = YAML(typ="rt")
yaml.default_flow_style = False
yaml.preserve_quotes = True
yaml.width = 4096
yaml = yaml_handler()


class GenAssemblyPipeline:
Expand Down
17 changes: 2 additions & 15 deletions pyartcd/pyartcd/pipelines/prepare_release.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,12 @@
from subprocess import PIPE
from typing import Dict, List, Optional, Sequence, Tuple
from jira.resources import Issue
from ruamel.yaml import YAML
from tenacity import retry, stop_after_attempt, wait_fixed
from datetime import datetime, timedelta, timezone

from artcommonlib.assembly import AssemblyTypes, assembly_group_config
from artcommonlib.model import Model
from artcommonlib.util import get_assembly_release_date
from artcommonlib.util import get_assembly_release_date, yaml_handler
from elliottlib.errata import set_blocking_advisory, get_blocking_advisories, push_cdn_stage, is_advisory_editable
from elliottlib.errata_async import AsyncErrataAPI
from elliottlib.errata import set_blocking_advisory, get_blocking_advisories
Expand All @@ -38,7 +37,7 @@


_LOGGER = logging.getLogger(__name__)

yaml = yaml_handler()

class PrepareReleasePipeline:
def __init__(
Expand Down Expand Up @@ -387,10 +386,6 @@ async def load_releases_config(self) -> Optional[None]:
return None
async with aiofiles.open(path, "r") as f:
content = await f.read()
yaml = YAML(typ="safe")
yaml.default_flow_style = False
yaml.preserve_quotes = True
yaml.width = 4096
return yaml.load(content)

@cached_property
Expand Down Expand Up @@ -504,10 +499,6 @@ async def load_group_config(self) -> Dict:
await self.clone_build_data(repo)
async with aiofiles.open(repo / "group.yml", "r") as f:
content = await f.read()
yaml = YAML(typ="safe")
yaml.default_flow_style = False
yaml.preserve_quotes = True
yaml.width = 4096
return yaml.load(content)

def check_blockers(self):
Expand Down Expand Up @@ -607,10 +598,6 @@ async def update_build_data(self, advisories: Dict[str, int], jira_issue_key: Op
f.write(group_config)
else:
# update releases.yml (if we are operating on a non-stream assembly)
yaml = YAML(typ="rt")
yaml.default_flow_style = False
yaml.preserve_quotes = True
yaml.width = 4096
async with aiofiles.open(repo / "releases.yml", "r") as f:
old = await f.read()
releases_config = yaml.load(old)
Expand Down
8 changes: 2 additions & 6 deletions pyartcd/pyartcd/pipelines/review_cvp.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,13 @@
import click
from ghapi.all import GhApi
from artcommonlib import exectools
from artcommonlib.util import yaml_handler
from pyartcd import jenkins, constants
from pyartcd.cli import cli, click_coroutine, pass_runtime
from pyartcd.git import GitRepository
from pyartcd.runtime import Runtime
from ruamel.yaml import YAML

yaml = YAML(typ="rt")
yaml.default_flow_style = False
yaml.preserve_quotes = True
yaml.width = 4096

yaml = yaml_handler()

class ReviewCVPPipeline:
def __init__(self, runtime: Runtime, group: str, assembly: str) -> None:
Expand Down
7 changes: 2 additions & 5 deletions pyartcd/pyartcd/pipelines/update_golang.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from artcommonlib.release_util import split_el_suffix_in_release
from artcommonlib.rpm_utils import parse_nvr
from artcommonlib import exectools
from artcommonlib.util import yaml_handler
from pyartcd import jenkins
from pyartcd.constants import GITHUB_OWNER
from pyartcd.cli import cli, click_coroutine, pass_runtime
Expand All @@ -24,11 +25,7 @@
from elliottlib import util as elliottutil

_LOGGER = logging.getLogger(__name__)

yaml = YAML(typ="rt")
yaml.default_flow_style = False
yaml.preserve_quotes = True
yaml.width = 4096
yaml = yaml_handler()


def is_latest_build(ocp_version: str, el_v: int, nvr: str, koji_session) -> bool:
Expand Down
Loading