Skip to main content

distcontrib

Python package distcontrib contributes utility functions to Distutils, extending its functionalities, like integration with Cython build and a launcher for doctest.

The primary reason for the existence of distcontrib is making life a lot easier when you write setup.py for your projects. You can create a template setup.py file and simply copy it to all new or existing projects you have, without any modification, in most situations. Under the covers, distcontrib finds several bits and pieces about your project and automagically configures itself so that you don’t have to adjust your setup.py file every time you create a new project.

See also: distcontrib-migrate

Usage

This is an example of how your setup.py would look like:

#!/usr/bin/env python

from setuptools import find_packages
from distutils.core import setup
from Cython.Distutils import build_ext as cython_build
import distcontrib as du

 ##
# This block contains settings you will eventually need to change
###

import myapp as myapp   #--- adjust to your package name

PACKAGE      = myapp.pkg_name
VERSION      = myapp.pkg_version
DESCRIPTION  = myapp.pkg_description
LICENSE      = myapp.pkg_license
URL          = myapp.pkg_url
AUTHOR       = myapp.pkg_author
AUTHOR_EMAIL = myapp.pkg_email
KEYWORDS     = myapp.pkg_keywords
REQUIREMENTS = myapp.pkg_requirements
LONG_DESCRIPTION = du.tools.read('README')
CLASSIFIERS      = [ 'License :: ' + LICENSE,
                     'Operating System :: OS Independent',
                     'Programming Language :: Python',
                     'Programming Language :: Cython',
                     'Development Status :: 3 - Alpha',
                     'Intended Audience :: Developers',
                     'Environment :: Console' ]

 ##
# From this point on, it's unlikely you will be changing anything.
###

PACKAGES      = find_packages(exclude=["*.tests", "*.tests.*", "tests.*", "tests"])
PACKAGES_DATA = du.tools.findall_package_data(PACKAGES)
EXT_MODULES   = du.tools.find_ext_modules(PACKAGES)

setup(
    name=PACKAGE,
    version=VERSION,
    description=DESCRIPTION,
    url=URL,
    author=AUTHOR,
    author_email=AUTHOR_EMAIL,
    long_description=LONG_DESCRIPTION,
    license=LICENSE,
    keywords=KEYWORDS,
    classifiers=CLASSIFIERS,
    packages=PACKAGES,
    package_data=PACKAGES_DATA,
    cmdclass={ 'build_ext' : cython_build,
               'doctest'   : du.doctest,
               'zap'       : du.zap, },
    ext_modules=EXT_MODULES,
    install_requires=REQUIREMENTS
)

Then create under your myapp/__init__.py file something like this:

#!/usr/bin/env python

pkg_name         = __name__ if __package__ is None else __package__
pkg_description  = 'This application does everything you can imagine'
pkg_version      = '0.1.0'
pkg_license      = 'OSI Approved :: BSD License'
pkg_url          = 'http://' + pkg_name + '.readthedocs.org/'
pkg_author       = 'Richard Gomes http://rgomes-info.blogspot.com'
pkg_email        = 'rgomes.info@gmail.com'
pkg_keywords     = [ 'artificial','intelligence','magic','sorcery','voodoo' ]
pkg_requirements = [ 'lxml', 'sqlalchemy' ]

Then you can do enter from command line:

$ python setup.py zap        # clean on steroids
$ python setup.py doctest    # run your doctests
$ python setup.py build_ext  # build with Cython

Command zap cleans a lot more stuff than command clean does, being ideal as a step before committing changes to the source control or creating a backup copy of your working folder.

Command doctest runs all doctests, from all your packages. If you find that thre are doctests not being run, please make sure you have created __init__.py files in all packages.

Special cases

In certain circumstances, you may have to guarantee that your setup.py installs a minumun set of essential requirements which, if not installed, may prevent your setup.py from running properly. By borrowing function install_requirements from package distcontrib.bootstrap and calling it on the top of your setup.py, you can install these essential requirements, as shown below:

#!/usr/bin/env python

ESSENTIAL = [ 'distribute', 'version', 'Cython', 'distcontrib', 'distcontrib-migrate' ]

# This function was copied verbatim from distcontrib.bootstrap
# In certain situations, you are not sure if distcontrib is installed, then
# makes sense to have this function straight on the top of your setup.py
def install_requirements(requirements, verbose=True):
    import os, pip
    pip_args = list()
    if verbose:
        print('Installing requirements: ' + str(requirements))
        pip_args.append( '--verbose' )
    proxy = os.environ['http_proxy']
    if proxy:
        pip_args.append('--proxy')
        pip_args.append(proxy)
        if verbose:
            print('http_proxy=' + proxy)
    pip_args.append('install')
    for req in requirements:
        pip_args.append( req )
    pip.main(initial_args = pip_args)


try:
    from setuptools import find_packages
    from distutils.core import setup
    from Cython.Distutils import build_ext as cython_build
    import distcontrib as du
    import distcontrib_migrate as dm
except:
    #-- import distcontrib.bootstrap
    #-- distcontrib.bootstrap.install_requirements( ESSENTIAL )
    install_requirements( ESSENTIAL )

    # do it again
    from setuptools import find_packages
    from distutils.core import setup
    from Cython.Distutils import build_ext as cython_build
    import distcontrib as du
    import distcontrib_migrate as dm

... the rest of your setup.py comes here

Support

Metadata

Release files for distcontrib 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for distcontrib 0.1.0
File Size Uploaded Provenance
distcontrib-0.1.0.tar.gz 7.7 kB Without provenance Details

Release files / distcontrib-0.1.0.tar.gz

Download URL distcontrib-0.1.0.tar.gz
Size 7.7 kB
Tags Source
SHA-256 checksum
How to use checksums
2fafe2a59a1f27a814d87a3a61203311ac806b5624b1f88dddf83a587d2e469f
BLAKE2b-256 checksum
How to use checksums
b63ae663c8cf81158121fb9339a13fdcc3ea515cc746cc05cdfcfb866923fd4c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for distcontrib 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

1 release file No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page