All of lore.kernel.org
 help / color / mirror / Atom feed
* [Buildroot] [PATCH next 1/1] package/python-hwdata: new package
@ 2023-03-11 18:41 Julien Olivain
  2023-03-12  9:23 ` Thomas Petazzoni via buildroot
  0 siblings, 1 reply; 3+ messages in thread
From: Julien Olivain @ 2023-03-11 18:41 UTC (permalink / raw)
  To: buildroot; +Cc: Julien Olivain, Asaf Kahlon

Provides python interface to database stored in hwdata
package. It allows you to get human readable description of
USB and PCI devices.

https://github.com/xsuchy/python-hwdata

Signed-off-by: Julien Olivain <ju.o@free.fr>
---
Patch tested on branch next at commit b793f3a with commands:

    make check-package
    ...
    0 warnings generated

    python3 -m flake8 \
        support/testing/tests/package/sample_python_hwdata.py \
        support/testing/tests/package/test_python_hwdata.py
    [no-output]

    support/testing/run-tests \
        -d dl -o output_folder \
        tests.package.test_python_hwdata
    ...
    OK
---
 DEVELOPERS                                    |  3 ++
 package/Config.in                             |  1 +
 package/python-hwdata/Config.in               | 12 ++++++
 package/python-hwdata/python-hwdata.hash      |  3 ++
 package/python-hwdata/python-hwdata.mk        | 14 +++++++
 .../tests/package/sample_python_hwdata.py     | 40 +++++++++++++++++++
 .../tests/package/test_python_hwdata.py       | 12 ++++++
 7 files changed, 85 insertions(+)
 create mode 100644 package/python-hwdata/Config.in
 create mode 100644 package/python-hwdata/python-hwdata.hash
 create mode 100644 package/python-hwdata/python-hwdata.mk
 create mode 100644 support/testing/tests/package/sample_python_hwdata.py
 create mode 100644 support/testing/tests/package/test_python_hwdata.py

diff --git a/DEVELOPERS b/DEVELOPERS
index d052e59122..c7ca204c05 100644
--- a/DEVELOPERS
+++ b/DEVELOPERS
@@ -1701,6 +1701,7 @@ F:	package/ptm2human/
 F:	package/python-distro/
 F:	package/python-gnupg/
 F:	package/python-hkdf/
+F:	package/python-hwdata/
 F:	package/python-magic-wormhole/
 F:	package/python-magic-wormhole-mailbox-server/
 F:	package/python-magic-wormhole-transit-relay/
@@ -1713,6 +1714,7 @@ F:	package/z3/
 F:	package/zynaddsubfx/
 F:	support/testing/tests/package/sample_python_distro.py
 F:	support/testing/tests/package/sample_python_gnupg.py
+F:	support/testing/tests/package/sample_python_hwdata.py
 F:	support/testing/tests/package/sample_python_pyalsa.py
 F:	support/testing/tests/package/sample_python_spake2.py
 F:	support/testing/tests/package/test_gnupg2.py
@@ -1727,6 +1729,7 @@ F:	support/testing/tests/package/test_perftest.py
 F:	support/testing/tests/package/test_python_distro.py
 F:	support/testing/tests/package/test_python_gnupg.py
 F:	support/testing/tests/package/test_python_hkdf.py
+F:	support/testing/tests/package/test_python_hwdata.py
 F:	support/testing/tests/package/test_python_magic_wormhole.py
 F:	support/testing/tests/package/test_python_pyalsa.py
 F:	support/testing/tests/package/test_python_spake2.py
diff --git a/package/Config.in b/package/Config.in
index 7c32305129..d5b17b9716 100644
--- a/package/Config.in
+++ b/package/Config.in
@@ -1083,6 +1083,7 @@ menu "External python modules"
 	source "package/python-httplib2/Config.in"
 	source "package/python-huepy/Config.in"
 	source "package/python-humanize/Config.in"
+	source "package/python-hwdata/Config.in"
 	source "package/python-hyperframe/Config.in"
 	source "package/python-hyperlink/Config.in"
 	source "package/python-ibmiotf/Config.in"
diff --git a/package/python-hwdata/Config.in b/package/python-hwdata/Config.in
new file mode 100644
index 0000000000..923d0a7d8a
--- /dev/null
+++ b/package/python-hwdata/Config.in
@@ -0,0 +1,12 @@
+config BR2_PACKAGE_PYTHON_HWDATA
+	bool "python-hwdata"
+	select BR2_PACKAGE_HWDATA # runtime
+	select BR2_PACKAGE_HWDATA_PCI_IDS
+	select BR2_PACKAGE_HWDATA_PNP_IDS
+	select BR2_PACKAGE_HWDATA_USB_IDS
+	help
+	  Provides python interface to database stored in hwdata
+	  package. It allows you to get human readable description of
+	  USB and PCI devices.
+
+	  https://github.com/xsuchy/python-hwdata
diff --git a/package/python-hwdata/python-hwdata.hash b/package/python-hwdata/python-hwdata.hash
new file mode 100644
index 0000000000..90d546dafc
--- /dev/null
+++ b/package/python-hwdata/python-hwdata.hash
@@ -0,0 +1,3 @@
+# md5, sha256 from https://pypi.org/pypi/hwdata/json
+md5  dccf3b28d06fb9c6f56875e148356c24  hwdata-2.3.7.tar.gz
+sha256  9e5c96be38d9218ffde40834d4ca03344b8dfaed29c8c5afe0030125ea03db03  hwdata-2.3.7.tar.gz
diff --git a/package/python-hwdata/python-hwdata.mk b/package/python-hwdata/python-hwdata.mk
new file mode 100644
index 0000000000..acc0378d38
--- /dev/null
+++ b/package/python-hwdata/python-hwdata.mk
@@ -0,0 +1,14 @@
+################################################################################
+#
+# python-hwdata
+#
+################################################################################
+
+PYTHON_HWDATA_VERSION = 2.3.7
+PYTHON_HWDATA_SOURCE = hwdata-$(PYTHON_HWDATA_VERSION).tar.gz
+PYTHON_HWDATA_SITE = https://files.pythonhosted.org/packages/15/26/f5bc1b42129fbcbd1c99c29714af1685fc89e2cf37680a9930d4fcac1808
+PYTHON_HWDATA_SETUP_TYPE = distutils
+PYTHON_HWDATA_LICENSE = GPL-2.0+
+PYTHON_HWDATA_LICENSE_FILES = LICENSE
+
+$(eval $(python-package))
diff --git a/support/testing/tests/package/sample_python_hwdata.py b/support/testing/tests/package/sample_python_hwdata.py
new file mode 100644
index 0000000000..9209f07925
--- /dev/null
+++ b/support/testing/tests/package/sample_python_hwdata.py
@@ -0,0 +1,40 @@
+#! /usr/bin/env python3
+
+from hwdata import PCI, USB, PNP
+
+# Test PCI IDs
+pci_vendor_id = '1af4'
+pci_device_id = '1003'
+
+pci = PCI()
+
+pci_vendor = pci.get_vendor(pci_vendor_id)
+print("PCI Vendor: %s" % pci_vendor)
+assert(pci_vendor == "Red Hat, Inc.")
+
+pci_device = pci.get_device(pci_vendor_id, pci_device_id)
+print("PCI Device: %s" % pci_device)
+assert(pci_device == "Virtio console")
+
+# Test USB IDs
+usb_vendor_id = '1d6b'
+usb_device_id = '0001'
+
+usb = USB()
+
+usb_vendor = usb.get_vendor(usb_vendor_id)
+print("USB Vendor: %s" % usb_vendor)
+assert(usb_vendor == "Linux Foundation")
+
+usb_device = usb.get_device(usb_vendor_id, usb_device_id)
+print("USB Device: %s" % usb_device)
+assert(usb_device == "1.1 root hub")
+
+# Test PNP IDs
+pnp_id = 'RHT'
+
+pnp = PNP()
+
+pnp_vendor = pnp.get_vendor(pnp_id)
+print("PNP Vendor: %s" % pnp_vendor)
+assert(pnp_vendor == "Red Hat, Inc.")
diff --git a/support/testing/tests/package/test_python_hwdata.py b/support/testing/tests/package/test_python_hwdata.py
new file mode 100644
index 0000000000..7028d1dd59
--- /dev/null
+++ b/support/testing/tests/package/test_python_hwdata.py
@@ -0,0 +1,12 @@
+from tests.package.test_python import TestPythonPackageBase
+
+
+class TestPythonHwdata(TestPythonPackageBase):
+    __test__ = True
+    config = TestPythonPackageBase.config + \
+        """
+        BR2_PACKAGE_PYTHON3=y
+        BR2_PACKAGE_PYTHON_HWDATA=y
+        """
+    sample_scripts = ["tests/package/sample_python_hwdata.py"]
+    timeout = 10
-- 
2.39.2

_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [Buildroot] [PATCH next 1/1] package/python-hwdata: new package
  2023-03-11 18:41 [Buildroot] [PATCH next 1/1] package/python-hwdata: new package Julien Olivain
@ 2023-03-12  9:23 ` Thomas Petazzoni via buildroot
  2023-03-12  9:43   ` Julien Olivain
  0 siblings, 1 reply; 3+ messages in thread
From: Thomas Petazzoni via buildroot @ 2023-03-12  9:23 UTC (permalink / raw)
  To: Julien Olivain; +Cc: Asaf Kahlon, buildroot

Hello Julien,

Thanks for this work!

On Sat, 11 Mar 2023 19:41:48 +0100
Julien Olivain <ju.o@free.fr> wrote:

> +PYTHON_HWDATA_VERSION = 2.3.7
> +PYTHON_HWDATA_SOURCE = hwdata-$(PYTHON_HWDATA_VERSION).tar.gz
> +PYTHON_HWDATA_SITE = https://files.pythonhosted.org/packages/15/26/f5bc1b42129fbcbd1c99c29714af1685fc89e2cf37680a9930d4fcac1808
> +PYTHON_HWDATA_SETUP_TYPE = distutils
> +PYTHON_HWDATA_LICENSE = GPL-2.0+
> +PYTHON_HWDATA_LICENSE_FILES = LICENSE

This doesn't work because there is no LICENSE file in the PyPi tarball
(and also the hash file does not have the hash of that file):

>>> python-hwdata 2.3.7 Collecting legal info
ERROR: No hash found for LICENSE
cp: cannot stat '/home/thomas/projets/buildroot/output/build/python-hwdata-2.3.7/LICENSE': No such file or directory
make: *** [package/python-hwdata/python-hwdata.mk:16: python-hwdata-legal-info] Error 1

One thing you could do to address this is:

PYTHON_HWDATA_EXTRA_DOWNLOADS = https://raw.githubusercontent.com/xsuchy/python-hwdata/python-hwdata-2.3.7-1/LICENSE

and then add a post-extract hook that copies $(PYTHON_HWDATA_DLDIR) to
$(@D), and then use LICENSE as the license file.

This will of course require an update in the hash file.

Do you think you could look into this? The rest of the patch looks
good, of course.

Best regards,

Thomas
-- 
Thomas Petazzoni, co-owner and CEO, Bootlin
Embedded Linux and Kernel engineering and training
https://bootlin.com
_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Buildroot] [PATCH next 1/1] package/python-hwdata: new package
  2023-03-12  9:23 ` Thomas Petazzoni via buildroot
@ 2023-03-12  9:43   ` Julien Olivain
  0 siblings, 0 replies; 3+ messages in thread
From: Julien Olivain @ 2023-03-12  9:43 UTC (permalink / raw)
  To: Thomas Petazzoni; +Cc: Asaf Kahlon, buildroot

Hi Thomas,

On 12/03/2023 10:23, Thomas Petazzoni wrote:
> Hello Julien,
> 
> Thanks for this work!
> 
> On Sat, 11 Mar 2023 19:41:48 +0100
> Julien Olivain <ju.o@free.fr> wrote:
> 
>> +PYTHON_HWDATA_VERSION = 2.3.7
>> +PYTHON_HWDATA_SOURCE = hwdata-$(PYTHON_HWDATA_VERSION).tar.gz
>> +PYTHON_HWDATA_SITE = 
>> https://files.pythonhosted.org/packages/15/26/f5bc1b42129fbcbd1c99c29714af1685fc89e2cf37680a9930d4fcac1808
>> +PYTHON_HWDATA_SETUP_TYPE = distutils
>> +PYTHON_HWDATA_LICENSE = GPL-2.0+
>> +PYTHON_HWDATA_LICENSE_FILES = LICENSE
> 
> This doesn't work because there is no LICENSE file in the PyPi tarball
> (and also the hash file does not have the hash of that file):

I also realized that, but I sent the wrong patch version.  Sorry about 
that.
My fixed version was just included a "no license file" comment. I'll 
send
a fixed v2.

>>>> python-hwdata 2.3.7 Collecting legal info
> ERROR: No hash found for LICENSE
> cp: cannot stat
> '/home/thomas/projets/buildroot/output/build/python-hwdata-2.3.7/LICENSE':
> No such file or directory
> make: *** [package/python-hwdata/python-hwdata.mk:16:
> python-hwdata-legal-info] Error 1
> 
> One thing you could do to address this is:
> 
> PYTHON_HWDATA_EXTRA_DOWNLOADS =
> https://raw.githubusercontent.com/xsuchy/python-hwdata/python-hwdata-2.3.7-1/LICENSE
> 
> and then add a post-extract hook that copies $(PYTHON_HWDATA_DLDIR) to
> $(@D), and then use LICENSE as the license file.
> 
> This will of course require an update in the hash file.
> 
> Do you think you could look into this? The rest of the patch looks
> good, of course.

Sure! I'll rework the patch to include your suggestion.  I never thought 
about
this workaround for this situation.

Best regards,

Julien.
_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-03-12  9:43 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-03-11 18:41 [Buildroot] [PATCH next 1/1] package/python-hwdata: new package Julien Olivain
2023-03-12  9:23 ` Thomas Petazzoni via buildroot
2023-03-12  9:43   ` Julien Olivain

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.