3

I'm working on creating a Python package that is somewhat modular in nature and I was wondering what's the best way to go about handling multiple installation configurations?

Take the following setup.py for the package of a simple document parser:

setup(
    name = 'my_document_parser',
    ...
    entry_points = {
        'my_document_parser.parsers': [
            'markdown = my_document_parser.parsers.misaka:Parser [misaka]',
            'textile = my_document_parser.parsers.textile:Parser [textile]'
        ]
    },
    install_requires = [
        'some_required_package'
    ],
    extras_require = {
        'misaka' = ['misaka'],
        'textile' = ['textile']
    },
    ...
)

I'd like to make something like the following available:

  • A default install
    • python setup.py install or pip install my_document_parser
    • installs my_document_parser, some_required_package, misaka
  • A bare install
    • something like python setup.py install --bare
    • installs my_document_parser, some_required_package
  • A way to enable other dependencies
    • something like python setup.py install --bare --with-textile
    • installs my_document_parser, some_required_package, textile

This is my first time messing around with Python packages from a developer standpoint, so I'm open to anything anyone has to offer if I'm going about things the wrong way or such.

Thanks.

anomareh
  • 5,294
  • 4
  • 25
  • 22

1 Answers1

0

The default installation will install everything in your install_requires and packages sections. Packages under extras_require will never be installed by your setup.py script; only if you create some logic for this kind of installation.

By default, setuptools and distutils have no way to explictly say "install using these sections of my setup call". You would need to implement by yourself.

pip always installs packages using no parameter to setup.py but --single-version-externally-managed, to tell setuptools to never create a .egg file.


Conclusion: if you want people to install your package by using pip, forget --bare and --with-textile. The best you can do is a full installation including misaka and textile as dependencies.

Maybe you should read The Hitchhiker's Guide To Packaging, specifically Creating a Package section and setuptool's specification -- it is a pretty good one, it covers everything setuptools can do.

Hugo Lopes Tavares
  • 28,528
  • 5
  • 47
  • 45
  • Thanks for taking the time to answer, but for the most part you just told me everything I already knew and have already read all the links you posted. My example commands were just that, an example of what I'd like to achieve, not what I expected to accomplish with distribute or pip specifically. My question as in the title and first paragraph is: __What's the best way to go about making multiple installation configurations available for a Python package?__ – anomareh Nov 29 '11 at 02:24
  • No problem, I appreciate the response. – anomareh Nov 30 '11 at 05:22