I'm working on a new Python authentication library for WSGI frameworks and want to use the python-openid and maybe some other third-party libs too. I see 2 options:
The question is:
What is the preferred conventional way of incorporating a third party library in Python open source projects?
In the production cycle, many developers find themselves using a third party library to grab some code for their project as opposed to creating their own library and being able to refer it. Libraries are part of every developers workflow, but writing your own can be tedious.
Python ships with a lovely standard library, which is a collection of packages and modules that are available on every machine that runs Python. However, you'll soon find that it doesn't contain everything you need.
Using a third party source for a project is a faster solution that writing your own code and using your own library. Some library have a huge user base, contributors and community around then which makes them well maintained.
From previous tutorials of this course, you must have gathered some idea about networking and stuff. Now it's time for us to get our hands dirty. But before that, do you know what are python libraries or python modules? Well, technically a module is simply a Python source file, which can expose classes, functions and global variables.
The preffered way is to use setuptools/distribute and define a setup.py for your project that downloads third-party libraries via PyPi.
Here's an extract from one of my projects. Note the use of setup/install/test/extras-require keyword arguments, which is what you're looking for
import distribute_setup
distribute_setup.use_setuptools()
import os
from setuptools import setup, find_packages
# Utility function to read the README file.
# Used for the long_description. It's nice, because now 1) we have a top level
# README file and 2) it's easier to type in the README file than to put a raw
# string in below ...
def read(fname):
return open(os.path.join(os.path.dirname(__file__), fname)).read()
setup(
name='buildboticon',
version='0.3.2',
author='Marcus Lindblom',
author_email='[email protected]',
description=('A buildbot monitoring utility'),
license='GPL 3.0',
keywords='buildbot systemtray pyqt',
url='http://bitbucket.org/marcusl/buildboticon',
download_url='http://packages.python.org/buildboticon',
package_dir={'':'src'},
packages=find_packages('src', exclude=['*.tests']),
long_description=read('README'),
entry_points={
'setuptools.installation': [
'eggsecutable = bbicon:main',
],
'gui_scripts': [
'buildboticon = bbicon:main',
]
},
setup_requires=[
'setuptools_hg',
],
tests_require=[
'unittest2 >= 0.5',
'mock >= 0.7.0b4',
],
install_requires=[
'pyyaml >= 0.3',
# 'pyqt >= 4.7' # PyQt doesn't have anything useful on PyPi :(
],
extras_require={
'speech': ['pyspeech >= 1.0'],
# 'phidgets': ['PhidgetsPython >= 2.1.7'],
},
Full file here: https://bitbucket.org/marcusl/buildboticon/src/5232de5ead73/python/setup.py
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With