From 906c9d8b70dc734f6ea3450b4f0f7eec718baeda Mon Sep 17 00:00:00 2001 From: Gus Kenion Date: Thu, 26 Jun 2025 11:24:05 +0200 Subject: [PATCH 1/4] Fix 'osc-develproject' behavior for opensuse:Factory packages hosted in gitea --- osc/core.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/osc/core.py b/osc/core.py index fc1ca79f..684d9c88 100644 --- a/osc/core.py +++ b/osc/core.py @@ -16,6 +16,7 @@ import locale import os import platform import re +import requests import shlex import shutil import subprocess @@ -100,6 +101,8 @@ DISTURL_RE = re.compile(r"^(?P.*)://(?P.*?)/(?P.*?)/(?Phttps?://.*?)/build/(?P.*?)/(?P.*?)/(?P.*?)/(?P.*?)/_log$") BUFSIZE = 1024 * 1024 +DEVEL_PACKAGES_URL = "https://src.opensuse.org/openSUSE/Factory/raw/branch/main/pkgs/_meta/devel_packages" + new_project_templ = """\ @@ -1397,6 +1400,20 @@ def show_devel_project(apiurl, prj, pac): package_obj = obs_api.Package.from_api(apiurl, prj, pac) if package_obj.devel is None: + if prj == 'openSUSE:Factory' or prj == 'openSUSE.org:opensuse:Factory': + # If OBS api doesn't return a devel project, query the gitea devel_packages file + try: + response = requests.get(DEVEL_PACKAGES_URL) + except: + return None, None + if response.status_code == 200 and response.text: + # locate pac in the devel_packages file + for line in response.text.splitlines(): + parts = line.split() + if parts[0] == pac: + # found the package, return devel project and package + if len(parts) > 1: + return parts[1], parts[0] return None, None # mute a false-positive: Instance of 'dict' has no 'project' member (no-member) From 6d4d23a134a4720cfd625ad5fc2d59444b985987 Mon Sep 17 00:00:00 2001 From: Gus Kenion Date: Fri, 27 Jun 2025 11:22:15 +0200 Subject: [PATCH 2/4] Include requests library in osc.spec file for rpmbuild test. Fix openSUSE string case and code style fix in core.py. --- contrib/osc.spec | 2 ++ osc/core.py | 10 +++++----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/contrib/osc.spec b/contrib/osc.spec index 6c065706..8f607bef 100644 --- a/contrib/osc.spec +++ b/contrib/osc.spec @@ -83,6 +83,7 @@ BuildRequires: %{use_python_pkg}-devel >= 3.6 BuildRequires: %{use_python_pkg}-rpm BuildRequires: %{use_python_pkg}-setuptools BuildRequires: %{use_python_pkg}-urllib3 +BuildRequires: %{use_python_pkg}-requests BuildRequires: %{yaml_pkg} BuildRequires: diffstat %if %{with fdupes} @@ -94,6 +95,7 @@ BuildRequires: git-core Requires: %{use_python_pkg}-cryptography Requires: %{use_python_pkg}-rpm Requires: %{use_python_pkg}-urllib3 +BuildRequires: %{use_python_pkg}-requests Requires: %{yaml_pkg} # needed for git-obs completion diff --git a/osc/core.py b/osc/core.py index 684d9c88..a60c9ccc 100644 --- a/osc/core.py +++ b/osc/core.py @@ -1400,7 +1400,7 @@ def show_devel_project(apiurl, prj, pac): package_obj = obs_api.Package.from_api(apiurl, prj, pac) if package_obj.devel is None: - if prj == 'openSUSE:Factory' or prj == 'openSUSE.org:opensuse:Factory': + if prj == 'openSUSE:Factory' or prj == 'openSUSE.org:openSUSE:Factory': # If OBS api doesn't return a devel project, query the gitea devel_packages file try: response = requests.get(DEVEL_PACKAGES_URL) @@ -1409,11 +1409,11 @@ def show_devel_project(apiurl, prj, pac): if response.status_code == 200 and response.text: # locate pac in the devel_packages file for line in response.text.splitlines(): - parts = line.split() - if parts[0] == pac: + devel_pkg, _, devel_prj = line.partition(' ') + if devel_pkg == pac: # found the package, return devel project and package - if len(parts) > 1: - return parts[1], parts[0] + if devel_pkg and devel_prj: + return devel_prj, devel_pkg return None, None # mute a false-positive: Instance of 'dict' has no 'project' member (no-member) From 86963efea5f08e8cb78e2e7be7c0d68770169fc2 Mon Sep 17 00:00:00 2001 From: Gus Kenion Date: Fri, 27 Jun 2025 13:11:39 +0200 Subject: [PATCH 3/4] Switch http requests to use http_request() --- contrib/osc.spec | 2 -- osc/core.py | 13 +++++++------ setup.cfg | 1 - 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/contrib/osc.spec b/contrib/osc.spec index 8f607bef..6c065706 100644 --- a/contrib/osc.spec +++ b/contrib/osc.spec @@ -83,7 +83,6 @@ BuildRequires: %{use_python_pkg}-devel >= 3.6 BuildRequires: %{use_python_pkg}-rpm BuildRequires: %{use_python_pkg}-setuptools BuildRequires: %{use_python_pkg}-urllib3 -BuildRequires: %{use_python_pkg}-requests BuildRequires: %{yaml_pkg} BuildRequires: diffstat %if %{with fdupes} @@ -95,7 +94,6 @@ BuildRequires: git-core Requires: %{use_python_pkg}-cryptography Requires: %{use_python_pkg}-rpm Requires: %{use_python_pkg}-urllib3 -BuildRequires: %{use_python_pkg}-requests Requires: %{yaml_pkg} # needed for git-obs completion diff --git a/osc/core.py b/osc/core.py index a60c9ccc..0bcb10b7 100644 --- a/osc/core.py +++ b/osc/core.py @@ -16,7 +16,6 @@ import locale import os import platform import re -import requests import shlex import shutil import subprocess @@ -1400,16 +1399,18 @@ def show_devel_project(apiurl, prj, pac): package_obj = obs_api.Package.from_api(apiurl, prj, pac) if package_obj.devel is None: - if prj == 'openSUSE:Factory' or prj == 'openSUSE.org:openSUSE:Factory': + if prj == "openSUSE:Factory" or prj == "openSUSE.org:openSUSE:Factory": # If OBS api doesn't return a devel project, query the gitea devel_packages file try: - response = requests.get(DEVEL_PACKAGES_URL) + response = http_request("GET", DEVEL_PACKAGES_URL) + response.auto_close = False except: return None, None - if response.status_code == 200 and response.text: + if response.status == 200: # locate pac in the devel_packages file - for line in response.text.splitlines(): - devel_pkg, _, devel_prj = line.partition(' ') + for line in io.TextIOWrapper(response): + devel_pkg, _, devel_prj = line.partition(" ") + devel_prj = devel_prj.strip() if devel_pkg == pac: # found the package, return devel project and package if devel_pkg and devel_prj: diff --git a/setup.cfg b/setup.cfg index 5c14b817..a8549fb1 100644 --- a/setup.cfg +++ b/setup.cfg @@ -47,7 +47,6 @@ install_requires = # rpm is not available on pip, install a matching package manually prior installing osc rpm ruamel.yaml - urllib3 [options.extras_require] lint = From 86bea1279b6a4e6fac924a40e98c675ec90c3c3c Mon Sep 17 00:00:00 2001 From: Gus Kenion Date: Fri, 27 Jun 2025 13:24:55 +0200 Subject: [PATCH 4/4] Restore urllib3 to setup.cfg --- setup.cfg | 1 + 1 file changed, 1 insertion(+) diff --git a/setup.cfg b/setup.cfg index a8549fb1..5c14b817 100644 --- a/setup.cfg +++ b/setup.cfg @@ -47,6 +47,7 @@ install_requires = # rpm is not available on pip, install a matching package manually prior installing osc rpm ruamel.yaml + urllib3 [options.extras_require] lint =