Skip to contentSkip to conversation

support/testing: python-requests: new runtime test

PATCH Applied Marcus Hoffmann via buildroot 3 participants 6 messages Feb 2 – Feb 13

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 support/testing: python-requests: new runtime test

Use an armv7 kernel because that comes with networking support.

---
 DEVELOPERS                                    |  2 ++
 .../tests/package/sample_python_requests.py   |  4 ++++
 .../tests/package/test_python_requests.py     | 21 +++++++++++++++++++
 3 files changed, 27 insertions(+)
 create mode 100644 support/testing/tests/package/sample_python_requests.py
 create mode 100644 support/testing/tests/package/test_python_requests.py
DEVELOPERS +2 -0
index aff26f8012..6dc83d3a38 100644
@@ -2284,6 +2284,7 @@ F:	support/testing/tests/package/test_python_django.py
 F:	support/testing/tests/package/test_python_fastapi.py
 F:	support/testing/tests/package/test_python_pydantic.py
 F:	support/testing/tests/package/test_python_pydantic_settings.py
+F:	support/testing/tests/package/test_python_requests.py
 F:	support/testing/tests/package/test_python_ruamel_yaml.py
 F:	support/testing/tests/package/test_python_sdbus_modemmanager.py
 F:	support/testing/tests/package/test_python_tzlocal.py
@@ -2297,6 +2298,7 @@ F:	support/testing/tests/package/sample_python_django.py
 F:	support/testing/tests/package/sample_python_fastapi.py
 F:	support/testing/tests/package/sample_python_pydantic.py
 F:	support/testing/tests/package/sample_python_pydantic_settings.py
+F:	support/testing/tests/package/sample_python_requests.py
 F:	support/testing/tests/package/sample_python_ruamel_yaml.py
 F:	support/testing/tests/package/sample_python_sdbus_modemmanager.py
 
support/testing/tests/package/sample_python_requests.py new file +4 -0
new file mode 100644
index 0000000000..e8d2b64076
@@ -0,0 +1,4 @@
+import requests
+
+r = requests.get("https://buildroot.org")
+assert r.status_code == 200
support/testing/tests/package/test_python_requests.py new file +21 -0
new file mode 100644
index 0000000000..48f910139b
@@ -0,0 +1,21 @@
+import os
+from tests.package.test_python import TestPythonPackageBase
+
+
+class TestPythonPy3Requests(TestPythonPackageBase):
+    __test__ = True
+    config = TestPythonPackageBase.config + \
+        """
+        BR2_SYSTEM_DHCP="eth0"
+        BR2_PACKAGE_PYTHON3=y
+        BR2_PACKAGE_PYTHON_REQUESTS=y
+        """
+    sample_scripts = ["tests/package/sample_python_requests.py"]
+    timeout=15
+
+    def login(self):
+        cpio_file = os.path.join(self.builddir, "images", "rootfs.cpio")
+        self.emulator.boot(arch="armv7",
+                           kernel="builtin",
+                           options=["-initrd", cpio_file])
+        self.emulator.login()
Signature · 6 lines
2.52.0

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
#1 lore raw

PATCH 2/2 package/python-requests: depend on system certificates instead of python-certifi

Add patch from archlinux distribution[1] that references system certificate store instead of using the python certifi package.

As a user of the requests package, I'd expect this to use the system certificate store and not pull in another certificate store that must be kept up-to-date separately (and is currently outdated in buildroot).

The file that is patched explicitly mentions that as an option for distributions. This approach is taken by Fedora[2] and Archlinux but not by other distributions (alpine, openembedded, debian, nix, guix).

[1] https://gitlab.archlinux.org/archlinux/packaging/packages/python-requests/-/blob/main/certs.patch?ref_type=heads
[2] https://koji.fedoraproject.org/koji/fileinfo?rpmID=43302745&filename=system-certs.patch

---
 .../0001-use-systemd-cert-bundle.patch          | 17 +++++++++++++++++
 package/python-requests/Config.in               |  2 +-
 .../tests/package/test_python_requests.py       | 14 ++++++++------
 3 files changed, 26 insertions(+), 7 deletions(-)
 create mode 100644 package/python-requests/0001-use-systemd-cert-bundle.patch
package/python-requests/0001-use-systemd-cert-bundle.patch new file +17 -0
new file mode 100644
index 0000000000..3c123e52b1
@@ -0,0 +1,17 @@
+---
+Signed-off-by: Marcus Hoffmann <[email protected]>
+Upstream: N/A, supposed to be patched downstream
+diff --git a/src/requests/certs.py b/src/requests/certs.py
+index be422c3e..9bfe1c80 100644
+--- a/src/requests/certs.py
++++ b/src/requests/certs.py
+@@ -11,7 +11,8 @@ If you are packaging Requests, e.g., for a Linux distribution or a managed
+ environment, you can change the definition of where() to return a separately
+ packaged CA bundle.
+ """
+-from certifi import where
++def where():
++    return "/etc/ssl/certs/ca-certificates.crt"
+ 
+ if __name__ == "__main__":
+     print(where())
package/python-requests/Config.in +1 -1
index 929b99657c..e2e329749e 100644
@@ -1,6 +1,6 @@
 config BR2_PACKAGE_PYTHON_REQUESTS
 	bool "python-requests"
-	select BR2_PACKAGE_PYTHON_CERTIFI # runtime
+	select BR2_PACKAGE_CA_CERTIFICATES # runtime
 	select BR2_PACKAGE_PYTHON_CHARSET_NORMALIZER # runtime
 	select BR2_PACKAGE_PYTHON_IDNA # runtime
 	select BR2_PACKAGE_PYTHON_URLLIB3 # runtime
support/testing/tests/package/test_python_requests.py +8 -6
index 48f910139b..33392839b0 100644
@@ -4,18 +4,20 @@ from tests.package.test_python import TestPythonPackageBase
 
 class TestPythonPy3Requests(TestPythonPackageBase):
     __test__ = True
-    config = TestPythonPackageBase.config + \
-        """
+    config = (
+        TestPythonPackageBase.config
+        + """
         BR2_SYSTEM_DHCP="eth0"
         BR2_PACKAGE_PYTHON3=y
         BR2_PACKAGE_PYTHON_REQUESTS=y
         """
+    )
     sample_scripts = ["tests/package/sample_python_requests.py"]
-    timeout=15
+    timeout = 15
 
     def login(self):
         cpio_file = os.path.join(self.builddir, "images", "rootfs.cpio")
-        self.emulator.boot(arch="armv7",
-                           kernel="builtin",
-                           options=["-initrd", cpio_file])
+        self.emulator.boot(
+            arch="armv7", kernel="builtin", options=["-initrd", cpio_file]
+        )
         self.emulator.login()
Signature · 6 lines
2.52.0

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
#2 lore raw

Re: [Buildroot] [PATCH 2/2] package/python-requests: depend on system certificates instead of python-certifi

Quoted 7 lines · Marcus Hoffmann

Add patch from archlinux distribution[1] that references system certificate store instead of using the python certifi package.

As a user of the requests package, I'd expect this to use the system certificate store and not pull in another certificate store that must be kept up-to-date separately (and is currently outdated in buildroot).

I generally do try to keep the python certifi package up to date as I think quite a few different python packages use it for certificates.

Quoted 4 lines

The file that is patched explicitly mentions that as an option for distributions. This approach is taken by Fedora[2] and Archlinux but not by other distributions (alpine, openembedded, debian, nix, guix).

I'm a bit skeptical this is a good idea, mostly because other python packages using certifi would then behave differently from requests.

It's kind of subjective however so I'm not sure what's actually best.

Quoted 79 lines

[1] https://gitlab.archlinux.org/archlinux/packaging/packages/python-requests/-/blob/main/certs.patch?ref_type=heads
[2] https://koji.fedoraproject.org/koji/fileinfo?rpmID=43302745&filename=system-certs.patch

---
 .../0001-use-systemd-cert-bundle.patch          | 17 +++++++++++++++++
 package/python-requests/Config.in               |  2 +-
 .../tests/package/test_python_requests.py       | 14 ++++++++------
 3 files changed, 26 insertions(+), 7 deletions(-)
 create mode 100644 package/python-requests/0001-use-systemd-cert-bundle.patch
package/python-requests/0001-use-systemd-cert-bundle.patch new file +17 -0
new file mode 100644
index 0000000000..3c123e52b1
@@ -0,0 +1,17 @@
+---
+Signed-off-by: Marcus Hoffmann <[email protected]>
+Upstream: N/A, supposed to be patched downstream
+diff --git a/src/requests/certs.py b/src/requests/certs.py
+index be422c3e..9bfe1c80 100644
+--- a/src/requests/certs.py
++++ b/src/requests/certs.py
+@@ -11,7 +11,8 @@ If you are packaging Requests, e.g., for a Linux distribution or a managed
+ environment, you can change the definition of where() to return a separately
+ packaged CA bundle.
+ """
+-from certifi import where
++def where():
++    return "/etc/ssl/certs/ca-certificates.crt"
+
+ if __name__ == "__main__":
+     print(where())
package/python-requests/Config.in +1 -1
index 929b99657c..e2e329749e 100644
@@ -1,6 +1,6 @@
 config BR2_PACKAGE_PYTHON_REQUESTS
        bool "python-requests"
-       select BR2_PACKAGE_PYTHON_CERTIFI # runtime
+       select BR2_PACKAGE_CA_CERTIFICATES # runtime
        select BR2_PACKAGE_PYTHON_CHARSET_NORMALIZER # runtime
        select BR2_PACKAGE_PYTHON_IDNA # runtime
        select BR2_PACKAGE_PYTHON_URLLIB3 # runtime
support/testing/tests/package/test_python_requests.py +8 -7
index 48f910139b..33392839b0 100644
@@ -4,18 +4,20 @@ from tests.package.test_python import TestPythonPackageBase
 
 class TestPythonPy3Requests(TestPythonPackageBase):
     __test__ = True
-    config = TestPythonPackageBase.config + \
-        """
+    config = (
+        TestPythonPackageBase.config
+        + """
         BR2_SYSTEM_DHCP="eth0"
         BR2_PACKAGE_PYTHON3=y
         BR2_PACKAGE_PYTHON_REQUESTS=y
         """
+    )
     sample_scripts = ["tests/package/sample_python_requests.py"]
-    timeout=15
+    timeout = 15
 
     def login(self):
         cpio_file = os.path.join(self.builddir, "images", "rootfs.cpio")
-        self.emulator.boot(arch="armv7",
-                           kernel="builtin",
-                           options=["-initrd", cpio_file])
+        self.emulator.boot(
+            arch="armv7", kernel="builtin", options=["-initrd", cpio_file]
+        )
         self.emulator.login()
--
Quoted 2 lines

2.52.0

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot

#3 lore raw

Re: [Buildroot] [PATCH 2/2] package/python-requests: depend on system certificates instead of python-certifi

Hi James,

Quoted 11 lines · James Hilliard
Quoted 7 lines · Marcus Hoffmann

Add patch from archlinux distribution[1] that references system certificate store instead of using the python certifi package.

As a user of the requests package, I'd expect this to use the system certificate store and not pull in another certificate store that must be kept up-to-date separately (and is currently outdated in buildroot).

I generally do try to keep the python certifi package up to date as I think quite a few different python packages use it for certificates.

That's fair and is has been fairly up to date recently, I actually had this patch lying around for a while. (And I checked before sending as well, but missed the recent bump somehow, sorry!)

Quoted 10 lines
Quoted 5 lines

The file that is patched explicitly mentions that as an option for distributions. This approach is taken by Fedora[2] and Archlinux but not by other distributions (alpine, openembedded, debian, nix, guix).

I'm a bit skeptical this is a good idea, mostly because other python packages using certifi would then behave differently from requests.

It's kind of subjective however so I'm not sure what's actually best.

I mostly looked into this because I always found it strange that requests would depend an a separate copy of the certificate store, when one is already installed in the system and used by all the other system level things, like libcurl, etc. Also aiohttp defaults to the system CA store.

I'd prefer switching requests to also use the system ca store and also not pull in certifi, but it's somewhat a mess in the ecosystem either way.

[...]

Marcus
_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot

#4 lore raw
In reply to Marcus Hoffmann via buildroot
Quoted 38 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Marcus" == Marcus Hoffmann via buildroot <[email protected]> writes:

Use an armv7 kernel because that comes with networking support.

---
 DEVELOPERS                                    |  2 ++
 .../tests/package/sample_python_requests.py   |  4 ++++
 .../tests/package/test_python_requests.py     | 21 +++++++++++++++++++
 3 files changed, 27 insertions(+)
 create mode 100644 support/testing/tests/package/sample_python_requests.py
 create mode 100644 support/testing/tests/package/test_python_requests.py
DEVELOPERS +2 -0
index aff26f8012..6dc83d3a38 100644
@@ -2284,6 +2284,7 @@ F:	support/testing/tests/package/test_python_django.py
 F:	support/testing/tests/package/test_python_fastapi.py
 F:	support/testing/tests/package/test_python_pydantic.py
 F:	support/testing/tests/package/test_python_pydantic_settings.py
+F:	support/testing/tests/package/test_python_requests.py
 F:	support/testing/tests/package/test_python_ruamel_yaml.py
 F:	support/testing/tests/package/test_python_sdbus_modemmanager.py
 F:	support/testing/tests/package/test_python_tzlocal.py
@@ -2297,6 +2298,7 @@ F:	support/testing/tests/package/sample_python_django.py
 F:	support/testing/tests/package/sample_python_fastapi.py
 F:	support/testing/tests/package/sample_python_pydantic.py
 F:	support/testing/tests/package/sample_python_pydantic_settings.py
+F:	support/testing/tests/package/sample_python_requests.py
 F:	support/testing/tests/package/sample_python_ruamel_yaml.py
 F:	support/testing/tests/package/sample_python_sdbus_modemmanager.py
 
support/testing/tests/package/sample_python_requests.py new file +0 -0
new file mode 100644
index 0000000000..e8d2b64076

support/testing/tests/package/sample_python_requests.py line 3

Quoted 3 lines
support/testing/tests/package/sample_python_requests.py new file +3 -0
@@ -0,0 +1,4 @@
+import requests
+
+r = requests.get("https://buildroot.org")

It is not so nice to rely on internet connectivity, so I changed it to run python3 -m http.server instead.

Quoted 11 lines
support/testing/tests/package/sample_python_requests.py new file +1 -0
+assert r.status_code == 200
support/testing/tests/package/test_python_requests.py new file +4 -0
new file mode 100644
index 0000000000..48f910139b
@@ -0,0 +1,21 @@
+import os
+from tests.package.test_python import TestPythonPackageBase
+
+

support/testing/tests/package/test_python_requests.py line 14

Quoted 10 lines
support/testing/tests/package/test_python_requests.py new file +10 -0
+class TestPythonPy3Requests(TestPythonPackageBase):
+    __test__ = True
+    config = TestPythonPackageBase.config + \
+        """
+        BR2_SYSTEM_DHCP="eth0"
+        BR2_PACKAGE_PYTHON3=y
+        BR2_PACKAGE_PYTHON_REQUESTS=y
+        """
+    sample_scripts = ["tests/package/sample_python_requests.py"]
+    timeout=15

flake8 wants spaces around '=', so I fixed that.

Committed with that fixed, thanks.

Signature · 5 lines
Bye, Peter Korsgaard
_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
#5 lore raw
In reply to Marcus Hoffmann via buildroot

In reply of:

Quoted 3 lines

Use an armv7 kernel because that comes with networking support.

Applied to 2025.02.x & 2025.11.x. Thanks

Quoted 72 lines
---
 DEVELOPERS                                    |  2 ++
 .../tests/package/sample_python_requests.py   |  4 ++++
 .../tests/package/test_python_requests.py     | 21 +++++++++++++++++++
 3 files changed, 27 insertions(+)
 create mode 100644 support/testing/tests/package/sample_python_requests.py
 create mode 100644 support/testing/tests/package/test_python_requests.py
DEVELOPERS +2 -0
index aff26f8012..6dc83d3a38 100644
@@ -2284,6 +2284,7 @@ F:	support/testing/tests/package/test_python_django.py
 F:	support/testing/tests/package/test_python_fastapi.py
 F:	support/testing/tests/package/test_python_pydantic.py
 F:	support/testing/tests/package/test_python_pydantic_settings.py
+F:	support/testing/tests/package/test_python_requests.py
 F:	support/testing/tests/package/test_python_ruamel_yaml.py
 F:	support/testing/tests/package/test_python_sdbus_modemmanager.py
 F:	support/testing/tests/package/test_python_tzlocal.py
@@ -2297,6 +2298,7 @@ F:	support/testing/tests/package/sample_python_django.py
 F:	support/testing/tests/package/sample_python_fastapi.py
 F:	support/testing/tests/package/sample_python_pydantic.py
 F:	support/testing/tests/package/sample_python_pydantic_settings.py
+F:	support/testing/tests/package/sample_python_requests.py
 F:	support/testing/tests/package/sample_python_ruamel_yaml.py
 F:	support/testing/tests/package/sample_python_sdbus_modemmanager.py
 
support/testing/tests/package/sample_python_requests.py new file +4 -0
new file mode 100644
index 0000000000..e8d2b64076
@@ -0,0 +1,4 @@
+import requests
+
+r = requests.get("https://buildroot.org")
+assert r.status_code == 200
support/testing/tests/package/test_python_requests.py new file +21 -0
new file mode 100644
index 0000000000..48f910139b
@@ -0,0 +1,21 @@
+import os
+from tests.package.test_python import TestPythonPackageBase
+
+
+class TestPythonPy3Requests(TestPythonPackageBase):
+    __test__ = True
+    config = TestPythonPackageBase.config + \
+        """
+        BR2_SYSTEM_DHCP="eth0"
+        BR2_PACKAGE_PYTHON3=y
+        BR2_PACKAGE_PYTHON_REQUESTS=y
+        """
+    sample_scripts = ["tests/package/sample_python_requests.py"]
+    timeout=15
+
+    def login(self):
+        cpio_file = os.path.join(self.builddir, "images", "rootfs.cpio")
+        self.emulator.boot(arch="armv7",
+                           kernel="builtin",
+                           options=["-initrd", cpio_file])
+        self.emulator.login()
Signature · 6 lines
2.52.0

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot