=====Création d'un paquet===== * Génération du paquet Pour créer un paquet Python, il faut lancer la commande ''python -m pip wheel PATH'' avec PATH étant la racine du code source. L'utilisation de ''python setup.py'' est dépréciée. [[https://packaging.python.org/en/latest/discussions/setup-py-deprecated/|Is setup.py deprecated?]] {{ :lang:python:wheel:is_setup.py_deprecated_-_python_packaging_user_guide_10_8_2024_10_46_37_am_.html |Archive du 24/09/2024 le 08/10/2024}} * Option de compilation Si on veut passer des options à ''setup.py'', il faut passer par ''%%--config-settings=--global-option=BLABLA1 --config-settings=--global-option=BLABLA2=ON%%''. Les options ''%%--config-settings%%'' et ''%%global-option%%'' se combinent. Il faudra bien faire attention à supprimer les options personnalisées de la liste des arguments dans ''setup.py''. Par exemple : option_arg = next((arg for arg in sys.argv if arg.startswith("option=")), None) if option_arg != None: sys.argv.remove(option_arg) else: option_arg = "option=" =====cibuildwheel===== [[https://cibuildwheel.pypa.io/en/stable/|Site web]] [[https://cibuildwheel.pypa.io/en/stable/options/#build-skip|Options]] Il permet de compiler le projet pour n'importe quelle version de Python. Ce n'est intéressant que si le module python contient du code compilé et doit être compilé pour toutes les versions de Python compatibles. Uniquement testé sous Windows pour générer des versions pour Windows. Il va télécharger toutes les versions de Python nécessaires et exécuter ''wheel'' pour générer le paquet pour chaque version. python.exe -m pip install cibuildwheel python.exe -m cibuildwheel --output-dir wheelhouse --platform windows Il se configure avec le fichier ''pyproject.toml''. [tool.cibuildwheel] build-verbosity = 1 build-frontend = { name = "pip", args = ["--no-clean"] } test-command = "python -m unittest discover {project}/test/python" [tool.cibuildwheel.windows] build = [ "*-win_amd64" ] skip = [ "cp37-win_amd64" ] enable = ["pypy", "pypy-eol"] # Devrait être dans build-system.requires mais cela n'a pas fonctionné pour moi. https://cibuildwheel.pypa.io/en/stable/options/#before-build before-build = "pip install cmake==4.0.3" # N'est pas encore officiellement automatique. https://cibuildwheel.pypa.io/en/stable/options/#repair-wheel-command repair-wheel-command = "delvewheel repair -w {dest_dir} {wheel}" =====manylinux===== [[https://github.com/pypa/manylinux|Site web]] Fournit des images Docker avec toutes les versions de Python pour générer les wheel pour Linux avec la glibc et musl. Rien n'est automatisé. Les installations de Python sont dans ''/opt/python/*/bin/python'' au format ''cp38-cp38'' / ''cp314-cp314t'' / ''pp311-pypy311_pp73''. ''cibuildwheel'' supporte ''manylinux'' mais je ne l'ai pas testé. =====abi3audit===== [[https://github.com/pypa/abi3audit/|Site web]] Vérifie que le fichier wheel généré est compatible ''abi3'' stable. ''free-threading'' n'est pas ''abi3''. Un wheel indique via son nom la version minimale de Python et s'il est ''abi'' stable. Le fichier ''nh3-0.3.2-cp38-abi3-win_arm64.whl'' est ''abi3'' stable avec une version minimale de Python de 3.8. Exemple : abi3audit toto-1.3.1-cp38-abi3-win32.whl --verbose [11:38:42] 👎 toto-1.3.1-cp38-abi3-win32.whl: bindings.cp314t-win32.pyd has non-ABI3 symbols 👎 toto-1.3.1-cp38-abi3-win32.whl: bindings.cp314t-win32.pyd uses the Python 3.13 ABI, but is tagged for the Python 3.8 ABI ┌────────────────────────────┬──────────┐ │ Symbol │ Version │ ├────────────────────────────┼──────────┤ │ PyUnstable_Module_SetGIL │ not ABI3 │ │ _Py_DecRefShared │ not ABI3 │ │ PyMutex_Lock │ not ABI3 │ │ PyFrame_GetBack │ not ABI3 │ │ PyMethod_Type │ not ABI3 │ │ PyInstanceMethod_New │ not ABI3 │ │ _PyObject_GetDictPtr │ not ABI3 │ │ PyThreadState_GetUnchecked │ not ABI3 │ │ PyObject_ClearManagedDict │ not ABI3 │ │ _PyType_Lookup │ not ABI3 │ │ PyInstanceMethod_Type │ not ABI3 │ │ PyObject_LengthHint │ not ABI3 │ │ PyObject_VisitManagedDict │ not ABI3 │ │ PyMutex_Unlock │ not ABI3 │ │ _Py_MergeZeroLocalRefcount │ not ABI3 │ │ PyFrame_GetLineNumber │ 3.10 │ │ PyUnicode_AsUTF8AndSize │ 3.10 │ │ PyObject_CheckBuffer │ 3.11 │ │ PyObject_GenericGetDict │ 3.10 │ │ PyDict_GetItemStringRef │ 3.13 │ │ PyObject_GetBuffer │ 3.11 │ │ PyBuffer_Release │ 3.11 │ │ PyFrame_GetCode │ 3.10 │ │ PyCMethod_New │ 3.9 │ │ PyInterpreterState_Get │ 3.9 │ └────────────────────────────┴──────────┘ 💁 toto-1.3.1-cp38-abi3-win32.whl: 1 extensions scanned; 1 ABI version mismatches and 15 ABI violations found