Skip to content

Commit 3cb759d

Browse files
committed
feat: release_service_utils as python package
scripts/python/* is now shipped as python package which can be imported as release_service_utils Assisted-By: claude Signed-off-by: Jindrich Luza <jluza@redhat.com>
1 parent 5282931 commit 3cb759d

22 files changed

Lines changed: 115 additions & 44 deletions

pyproject.toml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,21 @@ dependencies = [
2323
"confluent-kafka",
2424
]
2525

26+
[build-system]
27+
requires = ["setuptools>=61.0.0", "wheel"]
28+
build-backend = "setuptools.build_meta"
29+
30+
[tool.setuptools]
31+
packages = [
32+
"release_service_utils",
33+
"release_service_utils.helpers",
34+
"release_service_utils.tasks",
35+
"release_service_utils.tasks.internal",
36+
]
37+
38+
[tool.setuptools.package-dir]
39+
"release_service_utils" = "scripts/python"
40+
2641
[tool.black]
2742
line-length = 95
2843

scripts/python/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""Release Service Utils Python Package."""

scripts/python/helpers/__init__.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,12 @@
11
"""Reusable Python helpers for release task scripts."""
2+
3+
__all__ = [
4+
"authentication",
5+
"file",
6+
"http_client",
7+
"image_ref",
8+
"logger",
9+
"osidb",
10+
"retry",
11+
"tekton",
12+
]

scripts/python/helpers/authentication.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from collections.abc import Sequence
1414
from pathlib import Path
1515

16-
import retry
16+
from release_service_utils.helpers import retry
1717

1818

1919
def read_mounted_text(mount: Path, filename: str) -> str:

scripts/python/helpers/osidb.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import json
1717
from typing import Any
1818

19-
import http_client
19+
from release_service_utils.helpers import http_client
2020
from requests_kerberos import HTTPKerberosAuth, OPTIONAL
2121

2222

scripts/python/helpers/tests/__init__.py

Whitespace-only changes.

scripts/python/helpers/test_authentication.py renamed to scripts/python/helpers/tests/test_authentication.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
import pytest
1111

12-
import authentication
12+
from release_service_utils.helpers import authentication
1313

1414

1515
def test_read_mounted_text_strips_whitespace(tmp_path: Path) -> None:
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44

55
from pathlib import Path
66

7-
import file
87
import pytest
98

9+
from release_service_utils.helpers import file
10+
1011

1112
def test_path_from_env_variable_uses_set_value(
1213
tmp_path: Path, monkeypatch: pytest.MonkeyPatch

scripts/python/helpers/test_http_client.py renamed to scripts/python/helpers/tests/test_http_client.py

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import requests
99
from requests.adapters import HTTPAdapter
1010

11-
import http_client
11+
from release_service_utils.helpers import http_client
1212

1313

1414
def test_retries_policy_defaults() -> None:
@@ -43,7 +43,9 @@ def test_get_text_uses_session_and_headers() -> None:
4343
r.text = "body"
4444
r.raise_for_status = mock.MagicMock()
4545
session.get.return_value = r
46-
with mock.patch("http_client.get_session", return_value=session):
46+
with mock.patch(
47+
"release_service_utils.helpers.http_client.get_session", return_value=session
48+
):
4749
out = http_client.get_text("https://e/x", headers={"A": "b", "C": "d"})
4850

4951
assert out == "body"
@@ -63,7 +65,9 @@ def test_get_text_auth_passed() -> None:
6365
r.text = "t"
6466
session.get.return_value = r
6567
ra = object()
66-
with mock.patch("http_client.get_session", return_value=session):
68+
with mock.patch(
69+
"release_service_utils.helpers.http_client.get_session", return_value=session
70+
):
6771
assert http_client.get_text("https://u", auth=ra) == "t"
6872
assert session.get.call_args[1]["auth"] is ra
6973

@@ -75,7 +79,9 @@ def test_get_text_http_error() -> None:
7579
r.status_code = 500
7680
r.raise_for_status.side_effect = requests.HTTPError("nope", response=mock.MagicMock())
7781
session.get.return_value = r
78-
with mock.patch("http_client.get_session", return_value=session):
82+
with mock.patch(
83+
"release_service_utils.helpers.http_client.get_session", return_value=session
84+
):
7985
with pytest.raises(requests.HTTPError):
8086
http_client.get_text("https://u/")
8187

@@ -99,9 +105,11 @@ def test_get_text_retries_429_then_succeeds() -> None:
99105
session.get.side_effect = [r1, r2, r3]
100106

101107
with (
102-
mock.patch("http_client.get_session", return_value=session),
103-
mock.patch("http_client.random.randint", return_value=0),
104-
mock.patch("http_client.time.sleep") as sleep_mock,
108+
mock.patch(
109+
"release_service_utils.helpers.http_client.get_session", return_value=session
110+
),
111+
mock.patch("release_service_utils.helpers.http_client.random.randint", return_value=0),
112+
mock.patch("release_service_utils.helpers.http_client.time.sleep") as sleep_mock,
105113
):
106114
assert http_client.get_text("https://u") == "ok"
107115

@@ -125,9 +133,11 @@ def test_get_text_retries_404_when_enabled(monkeypatch: pytest.MonkeyPatch) -> N
125133
session.get.side_effect = [r1, r2]
126134

127135
with (
128-
mock.patch("http_client.get_session", return_value=session),
129-
mock.patch("http_client.random.randint", return_value=0),
130-
mock.patch("http_client.time.sleep") as sleep_mock,
136+
mock.patch(
137+
"release_service_utils.helpers.http_client.get_session", return_value=session
138+
),
139+
mock.patch("release_service_utils.helpers.http_client.random.randint", return_value=0),
140+
mock.patch("release_service_utils.helpers.http_client.time.sleep") as sleep_mock,
131141
):
132142
assert http_client.get_text("https://u") == "ok"
133143

scripts/python/helpers/test_image_ref.py renamed to scripts/python/helpers/tests/test_image_ref.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
from __future__ import annotations
44

5-
import image_ref
5+
from release_service_utils.helpers import image_ref
6+
67
import pytest
78

89

0 commit comments

Comments
 (0)