Package: prio
python-libprioThis module contains a Python wrapper around libprio.QuickstartInstall the required dependencies via the system package manager and install the
package from pip. The shared libraries for msgpack and NSS must be available for
the module to initialize properly.On an image derived from Ubuntu:dockerrun-itpython:3bash
aptupdate&&aptinstalllibmsgpackc2libnss3On Centos:dockerrun-itcentos:8bash
dnfupdate&&dnfinstallepel-release&&dnfinstallpython36msgpacknssOn macOS:brewinstallmsgpacknssTo test the package:pip3installprio
python3-c"from prio.libprio import *; Prio_init(); print(PrioPRGSeed_randomize())"Building from sourceEnsure all of the libprio build tools are available, such assconsandclangpython3-mvenvvenvsourcevenv/bin/activatemakeinstall# run testspipinstallpytestpython-mpytestTo run a coverage report:pipinstallpytest-cov
python-mpytest--cov-report=html--cov-report=term--cov=priotestsDistributingBinary eggs and wheels are built for Python 3.6, 3.7, and 3.8 for macOS 10.15
and Linux. From the project root, run the following command to distribute the
wheels for macOS.exportTWINE_REPOSITORY=testpypi# optional: for testingexportTWINE_USERNAME=__token__exportTWINE_PASSWORD=<API_KEY>
./scripts/python-dist.shRun the docker container for distributing the linux wheels.docker-composebuildlibprio-distexportTWINE_USERNAME=__token__exportTWINE_PASSWORD=<API_KEY>
docker-composerun-eTWINE_USERNAME-eTWINE_PASSWORDlibprio-distBuild ProcessThere are issues running an installation of the extension module inside of the
current directory (i.e.libprio/python). The directory is the first
item on thePYTHONPATH. The extension module cannot be referenced until it has
been completely packaged, due to the implicit import statement made by the swig
wrapper:from.import_libprioThe directory sturcture of module after runningpython setup.py buildshows the
intermediate shared object stored in a directory underneath build.# make%treepriobuild
prio
├──__init__.py
└──libprio.py
build
├──lib.macosx-10.15-x86_64-3.8
│└──prio
│├──__init__.py
│├──_libprio.cpython-38-darwin.so
│└──libprio.py
└──temp.macosx-10.15-x86_64-3.8└──libprio_wrap.oThe package references are valid once installed into the Python site packages.# python3 -m venv venv# source venv/bin/activate# make install%treevenv/lib/python3.8/site-packages/prio
venv/lib/python3.8/site-packages/prio
├──__init__.py
├──__pycache__
│├──__init__.cpython-38.pyc
│└──libprio.cpython-38.pyc
├──_libprio.cpython-38-darwin.so
└──libprio.py1directory,5filesSee thisStackOverflow postfor reference.Multiprocessing on LinuxThere are certain pathological behaviors that exibit themselves when run on a
specific operating system. Due to the way that NSS is initialized, naive
multiprocessing using the%initblock andatexitin the SWIG interface file
will fail on the multiprocessing test in Linux, but not on macOS. Management of
the Prio context must be done by the library user.===================================FAILURES===================================____________________test_multiprocessing_encoding_succeeds____________________
multiprocessing.pool.RemoteTraceback:"""Traceback (most recent call last):File "/usr/lib64/python3.6/multiprocessing/pool.py", line 119, in workerresult = (True, func(*args, **kwds))File "/usr/lib64/python3.6/multiprocessing/pool.py", line 47, in starmapstarreturn list(itertools.starmap(args[0], args[1]))File "/app/python/tests/test_libprio_multiprocessing.py", line 14, in _encodefor_server_a, for_server_b = PrioClient_encode(cfg, data_items)File "/usr/local/lib64/python3.6/site-packages/prio/libprio.py", line 380, in PrioClient_encodereturn _libprio.PrioClient_encode(cfg, data_in)RuntimeError: PrioClient_encode was not successful."""Theaboveexceptionwasthedirectcauseofthefollowingexception:deftest_multiprocessing_encoding_succeeds():_,pkA=Keypair_new()_,pkB=Keypair_new()internal_hex=PublicKey_export_hex(pkA)external_hex=PublicKey_export_hex(pkB)pool_size=2num_elements=10p=Pool(pool_size)>res=p.starmap(_encode,[(internal_hex,external_hex)]*num_elements)python/tests/test_libprio_multiprocessing.py:28:
________________________________________
/usr/lib64/python3.6/multiprocessing/pool.py:274:instarmapreturnself._map_async(func,iterable,starmapstar,chunksize).get()________________________________________self=<multiprocessing.pool.MapResultobjectat0x7f7a86db0048>,timeout=Nonedefget(self,timeout=None):self.wait(timeout)ifnotself.ready():raiseTimeoutErrorifself._success:returnself._valueelse:
>raiseself._value
ERuntimeError:PrioClient_encodewasnotsuccessful.

/usr/lib64/python3.6/multiprocessing/pool.py:644:RuntimeError===========================shorttestsummaryinfo============================FAILEDpython/tests/test_libprio_multiprocessing.py::test_multiprocessing_encoding_succeeds=========================1failed,20passedin0.49s=========================