YosysHQ / apicula

Project Apicula 🐝: bitstream documentation for Gowin FPGAs
MIT License
446 stars 64 forks source link

Please use a crc library that provides a pure Python implementation #217

Closed whitequark closed 6 months ago

whitequark commented 7 months ago

Right now, Apycula cannot be used with Pyodide:

>>> await micropip.install('Apycula==0.10.0')
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/lib/python3.11/site-packages/micropip/_commands/install.py", line 142, in install
    await transaction.gather_requirements(requirements)
  File "/lib/python3.11/site-packages/micropip/transaction.py", line 204, in gather_requirements
    await asyncio.gather(*requirement_promises)
  File "/lib/python3.11/site-packages/micropip/transaction.py", line 211, in add_requirement
    return await self.add_requirement_inner(Requirement(req))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/lib/python3.11/site-packages/micropip/transaction.py", line 300, in add_requirement_inner
    await self._add_requirement_from_package_index(req)
  File "/lib/python3.11/site-packages/micropip/transaction.py", line 347, in _add_requirement_from_package_index
    await self.add_wheel(wheel, req.extras, specifier=str(req.specifier))
  File "/lib/python3.11/site-packages/micropip/transaction.py", line 385, in add_wheel
    await self.gather_requirements(wheel.requires(extras))
  File "/lib/python3.11/site-packages/micropip/transaction.py", line 204, in gather_requirements
    await asyncio.gather(*requirement_promises)
  File "/lib/python3.11/site-packages/micropip/transaction.py", line 208, in add_requirement
    return await self.add_requirement_inner(req)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/lib/python3.11/site-packages/micropip/transaction.py", line 300, in add_requirement_inner
    await self._add_requirement_from_package_index(req)
  File "/lib/python3.11/site-packages/micropip/transaction.py", line 339, in _add_requirement_from_package_index
    wheel = find_wheel(metadata, req)
            ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/lib/python3.11/site-packages/micropip/transaction.py", line 431, in find_wheel
    raise ValueError(
ValueError: Can't find a pure Python 3 wheel for 'crcmod'.
See: https://pyodide.org/en/stable/usage/faq.html#why-can-t-micropip-find-a-pure-python-wheel-for-a-package
You can use `await micropip.install(..., keep_going=True)` to get a list of all packages with missing wheels.

This is the only problematic dependency AFAICT (numpy is supported).

pepijndevos commented 7 months ago

Any suggestions for such a library?

whitequark commented 7 months ago

https://pypi.org/project/crc/

pepijndevos commented 6 months ago

It's only used here so the change should be simple.

https://github.com/YosysHQ/apicula/blob/fedab4cf9871184c41e10ee6cdc6b306e3eb6a21/apycula/bslib.py#L5

I'm guessing we'll need these parameters, that's the main tricky part https://reveng.sourceforge.io/crc-catalogue/all.htm#crc.cat.crc-16-arc

Actually, these are the current parameters: https://crcmod.sourceforge.net/crcmod.predefined.html#predefined-crc-algorithms

whitequark commented 6 months ago
>>> import crcmod.predefined
>>> crc16 = crcmod.predefined.mkPredefinedCrcFun('crc-16')
>>> crc16(b"abcd")
14743
>>> calc = crc.Calculator(crc.Configuration(width=16, polynomial=0x8005, reverse_input=True, reverse_output=True))
>>> calc.checksum(b"abcd")
14743
whitequark commented 6 months ago

Thanks!