[bug#78422,electronics-team,v3] gnu: Add python-apycula.

Message ID 95f594e9bb4e2a081499d9f17d70266afd6a14dd.1747664177.git.csantosb@inventati.org
State New
Headers
Series [bug#78422,electronics-team,v3] gnu: Add python-apycula. |

Commit Message

Cayetano Santos May 19, 2025, 2:16 p.m. UTC
  * gnu/packages/electronics.scm (python-apycula): New variable.

Change-Id: I8e65416c1a555be189e9b8433d1ec7165aee16e9
---
 gnu/packages/electronics.scm | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)


base-commit: 450a361532573a02389530a6a80b7821683ed41b
--
2.49.0
  

Comments

Gabriel Wicki May 19, 2025, 5:10 p.m. UTC | #1
LGTM
  
Maxim Cournoyer May 20, 2025, 11:18 p.m. UTC | #2
Hi,

Cayetano Santos <csantosb@inventati.org> writes:

> * gnu/packages/electronics.scm (python-apycula): New variable.
>
> Change-Id: I8e65416c1a555be189e9b8433d1ec7165aee16e9
> ---
>  gnu/packages/electronics.scm | 33 +++++++++++++++++++++++++++++++++
>  1 file changed, 33 insertions(+)
>
> diff --git a/gnu/packages/electronics.scm b/gnu/packages/electronics.scm
> index dc9de79ffa..2736df4b3c 100644
> --- a/gnu/packages/electronics.scm
> +++ b/gnu/packages/electronics.scm
> @@ -29,6 +29,7 @@ (define-module (gnu packages electronics)
>    #:use-module (guix build-system cmake)
>    #:use-module (guix build-system gnu)
>    #:use-module (guix build-system pyproject)
> +  #:use-module (guix build-system python)
>    #:use-module (guix download)
>    #:use-module (guix gexp)
>    #:use-module (guix git-download)
> @@ -560,6 +561,38 @@ (define-public pulseview
>      (description "PulseView is a Qt based logic analyzer, oscilloscope and MSO GUI
>  for sigrok.")
>      (license license:gpl3+)))
> +(define-public python-apycula
> +  (package
> +    (name "python-apycula")
> +    (version "0.19")
> +    ;; The pypi tar.gz file includes the necessary .pickle files, not available
> +    ;; in the home-page repository.

That sounds like potentially bundled pre-generated sources (I hope not
binaries?).  How are these generated?  Ideally we'd generate everything
needed from sources.
  
Maxim Cournoyer May 20, 2025, 11:23 p.m. UTC | #3
Hi,

Cayetano Santos <csantosb@inventati.org> writes:

> * gnu/packages/electronics.scm (python-apycula): New variable.
>
> Change-Id: I8e65416c1a555be189e9b8433d1ec7165aee16e9
> ---
>  gnu/packages/electronics.scm | 33 +++++++++++++++++++++++++++++++++
>  1 file changed, 33 insertions(+)
>
> diff --git a/gnu/packages/electronics.scm b/gnu/packages/electronics.scm
> index dc9de79ffa..2736df4b3c 100644
> --- a/gnu/packages/electronics.scm
> +++ b/gnu/packages/electronics.scm
> @@ -29,6 +29,7 @@ (define-module (gnu packages electronics)
>    #:use-module (guix build-system cmake)
>    #:use-module (guix build-system gnu)
>    #:use-module (guix build-system pyproject)
> +  #:use-module (guix build-system python)
>    #:use-module (guix download)
>    #:use-module (guix gexp)
>    #:use-module (guix git-download)
> @@ -560,6 +561,38 @@ (define-public pulseview
>      (description "PulseView is a Qt based logic analyzer, oscilloscope and MSO GUI
>  for sigrok.")
>      (license license:gpl3+)))
> +(define-public python-apycula
> +  (package
> +    (name "python-apycula")
> +    (version "0.19")
> +    ;; The pypi tar.gz file includes the necessary .pickle files, not available
> +    ;; in the home-page repository.

It looks like running just 'make' in the repository should suffice to
generate the .pickle files, which are apparently some database files
("chipdb") [0].

Could you give it a try, and perhaps fetch from git instead to avoid the
pregenerated sources (else clean it up in a snippet phase) ?

Thanks!

[0]  https://github.com/YosysHQ/apicula/blob/master/Makefile
  
Maxim Cournoyer May 20, 2025, 11:41 p.m. UTC | #4
Hi,

I tried locally, this is my local changes so far:

--8<---------------cut here---------------start------------->8---
(define-public apycula
  (package
    (name "apycula")
    (version "0.19")
    ;; The pypi tar.gz file includes the necessary .pickle files, not available
    ;; in the home-page repository.
    (source
     (origin
       (method git-fetch)
       (uri (git-reference
             (url "https://github.com/YosysHQ/apicula")
             (commit version)))
       (file-name (git-file-name name version))
       (sha256
        (base32
         "0i3p3x3hs7c2dw5g6wa5g9lh551f5drb0abp7p3gkcfq4hi7bwm0"))))
    (build-system pyproject-build-system)
    (arguments
     (list
      #:tests? #f                       ;requires Gowin EDA tools
      #:phases
      #~(modify-phases %standard-phases
          (add-after 'unpack 'generate-chipdb-files
            (lambda _
              (invoke "make" "GOWINHOME=/tmp")))
          (add-after 'unpack 'sanity-check-fix
            (lambda _
              ;; The module name changed (see:
              ;; https://github.com/YosysHQ/apicula/issues/337).
              (substitute* "setup.py"
                (("'gowin_bba")
                 "# 'gowin_bbva")))))))
    (native-inputs (list python-setuptools python-wheel
                         ;gowin-eda   ;; PACKAGE ME!
                         ))
    (inputs (list python-crc))
    (home-page "https://github.com/YosysHQ/apicula/")
    (synopsis "Gowin FPGA bitstream format")
    (description
     "The project Apycula provides tools to support development and
generating bitstreams with Gowin FPGAs.")
    (license license:expat)))
--8<---------------cut here---------------end--------------->8---

I'm fetching from git, and renamed the package to just 'apycula' since
it appears intended to be used as tools (commands), not as a library.
I've also reported the bug found upstream and linked it here.  Thus we
can also make propagated-inputs just inputs, since they are captured in
the command wrapper scripts.

The problem now is that to generate the chipdb files we need gowin-eda.
Since this would also enable running the test suite, I think gowin-eda
should be packaged first and added to the native inputs here:

--8<---------------cut here---------------start------------->8---
starting phase `generate-chipdb-files'
python3 -m apycula.tiled_fuzzer GW1N-1
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "/tmp/guix-build-apycula-0.19.drv-0/source/apycula/tiled_fuzzer.py", line 231, in <module>
    with open(f"{gowinhome}/IDE/share/device/{device}/{device}.fse", 'rb') as f:
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: '/tmp/IDE/share/device/GW1N-1/GW1N-1.fse'
make: *** [Makefile:12: GW1N-1_stage1.pickle] Error 1
error: in phase 'generate-chipdb-files': uncaught exception:
%exception #<&invoke-error program: "make" arguments: ("GOWINHOME=/tmp") exit-status: 2 term-signal: #f stop-signal: #f> 
phase `generate-chipdb-files' failed after 0.1 seconds
--8<---------------cut here---------------end--------------->8---

Cayetano, could you please try packaging gowin-eda and using it here, to
get past the above issue?  And see if we can enable the test suite too!

--
Thanks,
Maxim
  
Cayetano Santos May 21, 2025, 8:29 a.m. UTC | #5
>mer. 21 mai 2025 at 08:41, Maxim Cournoyer <maxim.cournoyer@gmail.com> wrote:

Hi Maxim,

> I'm fetching from git, and renamed the package to just 'apycula' since
> it appears intended to be used as tools (commands), not as a library.

Just for the record, this package would allow including support for
gowin in guix nextpnr package, see [0], implementing a whole guix
workflow for gowin fpgas.

> The problem now is that to generate the chipdb files we need gowin-eda.
> Since this would also enable running the test suite, I think gowin-eda
> should be packaged first and added to the native inputs here:

Sorry, my bad. I assumed pickle files were acceptable for guix, while
clearly they are not.

Now, gowin-eda [1] are proprietary tools, for as much as I know, so I’m
afraid this is a closed path for us, unless I figure out a clean way to
obtain the necessary files under a free license. I’ll take the time to investigate,

Thanks again for your help,

C.

[0] https://research.utwente.nl/files/249654527/DeVos2020complete.pdf
[1] https://www.gowinsemi.com/en/support/home/
  
Maxim Cournoyer May 21, 2025, 9:14 a.m. UTC | #6
Hello,

Cayetano Santos <csantosb@inventati.org> writes:

>>mer. 21 mai 2025 at 08:41, Maxim Cournoyer <maxim.cournoyer@gmail.com> wrote:
>
> Hi Maxim,
>
>> I'm fetching from git, and renamed the package to just 'apycula' since
>> it appears intended to be used as tools (commands), not as a library.
>
> Just for the record, this package would allow including support for
> gowin in guix nextpnr package, see [0], implementing a whole guix
> workflow for gowin fpgas.

Neat!

>> The problem now is that to generate the chipdb files we need gowin-eda.
>> Since this would also enable running the test suite, I think gowin-eda
>> should be packaged first and added to the native inputs here:
>
> Sorry, my bad. I assumed pickle files were acceptable for guix, while
> clearly they are not.

They may be!  Since they can be considered data files (thus
non-funtional), the license terms per the GNU FSDG are relaxed: the
license that applies to these may be non-free, and what matters is being
able to redistribute these freely, without any restriction [0].  See the
'Non-functional Data' paragraph at [0].

[0]  https://www.gnu.org/distros/free-system-distribution-guidelines.html
  
Cayetano Santos May 21, 2025, 9:48 a.m. UTC | #7
>mer. 21 mai 2025 at 18:14, Maxim Cournoyer <maxim.cournoyer@gmail.com> wrote:

>>> The problem now is that to generate the chipdb files we need gowin-eda.
>>> Since this would also enable running the test suite, I think gowin-eda
>>> should be packaged first and added to the native inputs here:
>>
>> Sorry, my bad. I assumed pickle files were acceptable for guix, while
>> clearly they are not.
>
> They may be!  Since they can be considered data files (thus
> non-funtional), the license terms per the GNU FSDG are relaxed: the
> license that applies to these may be non-free, and what matters is being
> able to redistribute these freely, without any restriction [0].  See the
> 'Non-functional Data' paragraph at [0].

This means a v4, including a ref to the issue you just open, might be accepted ?

Otherwise, we have the huge and public educational distribution of the
gowin ide [0] (the 784.12MB thing), but we’d rather avoid such an
horror; anyway it is unclear to me the license which applies here.

[0] https://www.gowinsemi.com.cn/faq.aspx
  

Patch

diff --git a/gnu/packages/electronics.scm b/gnu/packages/electronics.scm
index dc9de79ffa..2736df4b3c 100644
--- a/gnu/packages/electronics.scm
+++ b/gnu/packages/electronics.scm
@@ -29,6 +29,7 @@  (define-module (gnu packages electronics)
   #:use-module (guix build-system cmake)
   #:use-module (guix build-system gnu)
   #:use-module (guix build-system pyproject)
+  #:use-module (guix build-system python)
   #:use-module (guix download)
   #:use-module (guix gexp)
   #:use-module (guix git-download)
@@ -560,6 +561,38 @@  (define-public pulseview
     (description "PulseView is a Qt based logic analyzer, oscilloscope and MSO GUI
 for sigrok.")
     (license license:gpl3+)))
+(define-public python-apycula
+  (package
+    (name "python-apycula")
+    (version "0.19")
+    ;; The pypi tar.gz file includes the necessary .pickle files, not available
+    ;; in the home-page repository.
+    (source
+     (origin
+       (method url-fetch)
+       (uri (pypi-uri "Apycula" version))
+       (sha256
+        (base32 "034crnlrb3dlwwc75gpskyz47jvhcv0c3l74z5rpyz622ajv46d6"))))
+    (build-system pyproject-build-system)
+    (arguments
+     (list
+      #:tests? #f                       ;requires Gowin EDA tools
+      #:phases
+      #~(modify-phases %standard-phases
+          ;; Fix error related to import of 'apycula.gowin_bba'.
+          (add-after 'unpack 'sanity-check-fix
+            (lambda _
+              (substitute* "setup.py"
+                (("'gowin_bba")
+                 "# 'gowin_bbva")))))))
+    (propagated-inputs (list python-crc))
+    (native-inputs (list python-setuptools python-wheel))
+    (home-page "https://github.com/YosysHQ/apicula/")
+    (synopsis "Gowin FPGA bitstream format")
+    (description
+     "The project Apycula provides tools to support development and
+generating bitstreams with Gowin FPGAs.")
+    (license license:expat)))
 
 (define-public python-edalize
   (package