Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python library release best practices

Tags:

python

release

I've written Python bindings using ctypes for the units library. The bindings themselves are only ~100 lines of Python. The library has an unnecessary (for the purposes of the Python bindings) dependency on tcl, and the configure script fails if tcl is absent. However, the library builds fine with gcc -Wl,-soname,units.so -o units.so -fPIC -shared units.c.

I would now like to release these bindings. There are three ways I could do this.

  1. Release the bindings on their own, with a basic setup.py and provide build, download and install instructions for the C library in the documentation.
  2. Release the bindings, along with the original library source and provide a setup.py that handles the compilation and installation of the C library. This is obviously more work for me.
  3. Just release the .py file, and let the users worry about installation and dependencies.

If I choose option 2, where should I put the library? Should I put it in the same directory as the .py file, allowing me to assume lib_name = CDLL('./units.extension'), or should I put it in a directory that tends to be in the linker's path (like /lib)? In addition, how is this normally handled for Windows machines which a) might not have a C compiler and b) have no standard place to put shared libraries?

Which of these options is the preferred one and what should I do about the Windows case?

like image 244
Chinmay Kanchi Avatar asked Mar 08 '11 20:03

Chinmay Kanchi


1 Answers

It appears that the units library hasn't been modified in over 5 years, so option 2 may be the best one. It's also unlikely that one of the major distributions will package it (I can't find it in Ubuntu Lucid or Macports for example).

For example, copy units.c and units.h into your project and create a setup.py to compile and deploy it along with your bindings:

from setuptools import setup, Extension

sources = ['src/units.c']
ext_opts = {'extra_compile_args': ['-Wl,-soname,units.so', '-Isrc']}

setup(
    name='units',
    ext_modules = [Extension('units', sources, **ext_opts)]
    )
like image 112
samplebias Avatar answered Sep 20 '22 01:09

samplebias