aytey / cython-manylinux-setup

cython_main_setup

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

cython-manylinux-setup

This repository contains a very simple example that combines Cython with https://github.com/pypa/manylinux to create binary Python packages for Python 2.7 -> Python 3.9.

It is used to demonstrate how to work with Cython, setuptools and manylinux to generate binary packages targeting many Python versions.

Building

Requirements

The code in this repository will require you to have Docker installed, to allow you to work with the https://github.com/pypa/manylinux Docker images. This demo just uses:

Vector Informatik specific notes

If you are trying this demo under a corporate proxy where Docker cannot talk outside without additional configuration, please see the content of:

  • vector/internalise_manylinux.sh

which demonstrates working making an internal version of manylinux1_x86_64 configured to work with a corporate proxy.

Importantly: if you need to use vector/internalise_manylinux.sh then you must prefix the scripts/build.sh with DOCKER_IMAGE="vi/manylinux1".

pomona

The source code lives in the pomona folder and provides a very simple Python module (pomona.py) that simply meows.

The only interesting point is pomona/__main__.py that provides a simple main to work with the Pomona class.

setup.py

The setup.py included in this repository has two main features:

  • It automatically Cythonises and compiles pomona.pyx into pomona.cpython-<VER>-x86_64-linux-gnu.so
  • It provides the definition of a console_scripts that wraps the code in pomona/__main__.py to automatically generate an executable script called pomsy -- the implementation of pomsy is automatically crated by setup.py from the entry-point of pomona.__main__:main

scripts/build.sh

This script simplifies the .travis.yml from https://github.com/pypa/python-manylinux-demo -- rather than using Travis, it simply calls docker with the our given image name (manylinux1_x86_64).

scripts/build-wheels.sh

This is a direct copy of:

but where the package name has been changed from python-manylinux-demo to be pomona.

Using

Generated wheels

To generate the wheels, you should run:

Outside of Vector

# Outside of Vector
./scripts/build.sh

Inside of Vector

# Inside of Vector
./vector/internalise_manylinux.sh
DOCKER_IMAGE="vi/manylinux1" ./scripts/build.sh

Result

This will populate the folder wheelhouse with content such as:

pomona-0.0.0-cp27-cp27m-manylinux_2_5_x86_64.manylinux1_x86_64.whl
pomona-0.0.0-cp27-cp27mu-manylinux_2_5_x86_64.manylinux1_x86_64.whl
pomona-0.0.0-cp35-cp35m-manylinux_2_5_x86_64.manylinux1_x86_64.whl
pomona-0.0.0-cp36-cp36m-manylinux_2_5_x86_64.manylinux1_x86_64.whl
pomona-0.0.0-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.whl
pomona-0.0.0-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.whl
pomona-0.0.0-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.whl

because this folder was created by Docker, it is owned by root -- if you want to delete it, use sudo.

Installing

To quickly look at what one of these wheels does, you can do this:

python3 -m venv venv
source venv/bin/activate
pyver=$(python3 --version | cut -d ' ' -f 2 | cut -d '.' -f 1-2 | sed "s/\.//g")
pip install wheelhouse/pomona-0.0.0-cp${pyver}-cp${pyver}-manylinux_2_5_x86_64.manylinux1_x86_64.whl --force-reinstall

After this is done, you should see something like:

venv/lib/python3.8/site-packages/pomona/pomona.cpython-38-x86_64-linux-gnu.so

(adjusted for your Python version) and

venv/bin/pomsy

which is the setuptools-generated Python main, wrapping the content in pomona/__main__.py.

About

cython_main_setup

License:Creative Commons Zero v1.0 Universal


Languages

Language:Shell 56.7%Language:Python 30.2%Language:Dockerfile 7.8%Language:Cython 5.3%