Files
ortools-clone/ortools/python/README.md

104 lines
2.9 KiB
Markdown
Raw Permalink Normal View History

2020-10-05 21:18:52 +02:00
# Introduction
This is the documentation page for the Python 3.9+ wrapper of OR-Tools.
2020-10-05 21:18:52 +02:00
2020-11-18 18:18:43 +01:00
This project aim to explain how you build a Python native wheel package using
[`setup.py`](https://packaging.python.org/tutorials/packaging-projects/).
2020-10-05 21:18:52 +02:00
## Table of Content
2020-11-18 18:18:43 +01:00
2020-10-05 21:18:52 +02:00
* [Requirement](#requirement)
* [Directory Layout](#directory-layout)
* [Build Process](#build-process)
* [Local Package](#local-package)
2020-11-18 18:18:43 +01:00
* [Building a native Package](#building-local-native-package)
2020-10-05 21:18:52 +02:00
* [Appendices](#appendices)
2020-11-26 16:19:31 +01:00
* [Resources](#resources)
2020-10-05 21:18:52 +02:00
* [Misc](#misc)
2020-11-18 18:18:43 +01:00
## Requirement
2025-07-09 14:23:53 +02:00
You'll need "Python >= 3.9" and few python modules ("wheel" and "absl-py").
2020-10-05 21:18:52 +02:00
2020-11-18 18:18:43 +01:00
## Directory Layout
* [setup.py.in](setup.py.in) `Setup.py` template to build the python native
project.
## Build Process
2020-10-05 21:18:52 +02:00
To Create a native dependent package which will contains two parts:
2022-03-02 22:08:52 +01:00
2020-11-18 18:18:43 +01:00
* A bunch of native libraries for the supported platform targeted.
* The Python code depending on it.
2021-09-20 15:24:04 +02:00
note: Since [Pypi.org](https://pypi.org/) support multiple packages, we will
simply upload one package per supported platform.
2020-10-05 21:18:52 +02:00
2020-11-18 18:18:43 +01:00
### Local Package
2020-10-05 21:18:52 +02:00
2020-11-18 18:18:43 +01:00
The pipeline for `linux-x86-64` should be as follow: \
note: The pipeline will be similar for other architectures, don't hesitate to
2022-03-02 22:08:52 +01:00
look at the CI log! ![Local Pipeline](docs/local_pipeline.svg)
![Legend](docs/legend.svg)
2020-10-05 21:18:52 +02:00
2020-11-18 18:18:43 +01:00
#### Building local native Package
Thus we have the C++ shared library `libortools.so` and the SWIG generated
Python wrappers e.g. `pywrapsat.py` in the same package.
2020-10-05 21:18:52 +02:00
Here some dev-note concerning this `setup.py`.
2022-03-02 22:08:52 +01:00
2020-11-18 18:18:43 +01:00
* This package is a native package containing native libraries.
2020-10-05 21:18:52 +02:00
Then you can generate the package and install it locally using:
2022-03-02 22:08:52 +01:00
2020-10-05 21:18:52 +02:00
```bash
python3 setup.py bdist_wheel
python3 -m pip install --user --find-links=dist ortools
```
2020-11-18 18:18:43 +01:00
If everything good the package (located in `<buildir>/python/dist`) should have
this layout:
2022-03-02 22:08:52 +01:00
2020-10-05 21:18:52 +02:00
```
2021-08-30 10:10:21 +02:00
{...}/dist/ortools-X.Y.9999-cp3Z-cp3Z-<platform>.whl:
2020-10-05 21:18:52 +02:00
\- ortools
\- __init__.py
\- .libs
\- libortools.so
\- constraint_solver
\- __init__.py
\- pywrapcp.py
\- _pywrapcp.so
\- ...
\- __init__.py
\- pywrap....py
\- _pywrap....so
2020-11-18 18:18:43 +01:00
...
2020-10-05 21:18:52 +02:00
```
2021-08-30 10:10:21 +02:00
note: `<platform>` could be `manylinux2014_x86_64`, `macosx_10_9_x86_64` or `win-amd64`.
2020-10-05 21:18:52 +02:00
2020-11-18 18:18:43 +01:00
tips: since wheel package are just zip archive you can use `unzip -l <package>.whl`
to study their layout.
## Appendices
2020-10-05 21:18:52 +02:00
Few links on the subject...
2020-11-26 16:19:31 +01:00
### Resources
2020-11-18 18:18:43 +01:00
* [Packaging Python Project](https://packaging.python.org/tutorials/packaging-projects/)
* [PEP 513 -- A Platform Tag for Portable Linux Built Distributions](https://www.python.org/dev/peps/pep-0513/)
* [PEP 571 -- The manylinux2010 Platform Tag](https://www.python.org/dev/peps/pep-0571/)
2021-08-30 10:10:21 +02:00
* [PEP 600 Future 'manylinux' Platform Tags](https://www.python.org/dev/peps/pep-0600/)
2020-10-05 21:18:52 +02:00
2020-11-18 18:18:43 +01:00
## Misc
2020-10-05 21:18:52 +02:00
Image has been generated using [plantuml](http://plantuml.com/):
2022-03-02 22:08:52 +01:00
2020-10-05 21:18:52 +02:00
```bash
2022-03-02 22:08:52 +01:00
plantuml -Tsvg docs/{file}.dot
2020-10-05 21:18:52 +02:00
```
So you can find the dot source files in [docs](docs).