33import abc
44import asyncio
55import datetime
6- import enum
76import os
87import textwrap
98from collections .abc import Callable
2928from bci_build .registry import ApplicationCollectionRegistry
3029from bci_build .registry import Registry
3130from bci_build .registry import publish_registry
32- from bci_build .service import Service
31+ from bci_build .replacement import Replacement
3332from bci_build .templates import DOCKERFILE_TEMPLATE
3433from bci_build .templates import INFOHEADER_TEMPLATE
3534from bci_build .templates import KIWI_TEMPLATE
@@ -74,15 +73,6 @@ def __str__(self) -> str:
7473 return self .name
7574
7675
77- @enum .unique
78- class ParseVersion (enum .StrEnum ):
79- MAJOR = enum .auto ()
80- MINOR = enum .auto ()
81- PATCH = enum .auto ()
82- PATCH_UPDATE = enum .auto ()
83- OFFSET = enum .auto ()
84-
85-
8676@dataclass
8777class StableUser :
8878 """Data class that stores information about stable user and group
@@ -99,54 +89,6 @@ class StableUser:
9989 group_id : int
10090
10191
102- @dataclass
103- class Replacement :
104- """Represents a replacement via the `obs-service-replace_using_package_version
105- <https://github.com/openSUSE/obs-service-replace_using_package_version>`_.
106-
107- """
108-
109- #: regex to be replaced in :py:attr:`~bci_build.package.Replacement.file_name`, :file:`Dockerfile` or :file:`$pkg_name.kiwi`
110- regex_in_build_description : str
111-
112- #: package name to be queried for the version
113- package_name : str
114-
115- #: override file name, if unset use :file:`Dockerfile` or :file:`$pkg_name.kiwi`
116- file_name : str | None = None
117-
118- #: specify how the version should be formatted, see
119- #: `<https://github.com/openSUSE/obs-service-replace_using_package_version#usage>`_
120- #: for further details
121- parse_version : None | ParseVersion = None
122-
123- def __post_init__ (self ) -> None :
124- """Barf if someone tries to replace variables in README, as those
125- changes will be only performed in the buildroot, but not in the actual
126- source package.
127-
128- """
129- if "%%" not in self .regex_in_build_description :
130- raise ValueError ("regex_in_build_description must be in the form %%foo%%" )
131- if self .file_name and "readme" in self .file_name .lower ():
132- raise ValueError (f"Cannot replace variables in { self .file_name } !" )
133-
134- def to_service (self , default_file_name : str ) -> Service :
135- """Convert this replacement into a
136- :py:class:`~bci__build.service.Service`.
137-
138- """
139- return Service (
140- name = "replace_using_package_version" ,
141- param = [
142- ("file" , self .file_name or default_file_name ),
143- ("regex" , self .regex_in_build_description ),
144- ("package" , self .package_name ),
145- ]
146- + ([("parse-version" , self .parse_version )] if self .parse_version else []),
147- )
148-
149-
15092def _build_tag_prefix (os_version : OsVersion ) -> str :
15193 if os_version == OsVersion .TUMBLEWEED :
15294 return "opensuse/bci"
0 commit comments