Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Packages in setup.py file

Tags:

python

Im following a tutorial on Python packages and trying to understand what the "packages" line here does..

install_requires will install all the software that are given in the list...So, what does packages do?

from distutils.core import setup

setup(
    name='TowelStuff',
    version='0.1.0',
    author='J. Random Hacker',
    author_email='[email protected]',
    packages=['towelstuff', 'towelstuff.test'],
    scripts=['bin/stowe-towels.py','bin/wash-towels.py'],
    url='http://pypi.python.org/pypi/TowelStuff/',
    license='LICENSE.txt',
    description='Useful towel-related stuff.',
    long_description=open('README.txt').read(),
    install_requires=[
        "Django >= 1.1.1",
        "caldav == 0.1.4",
    ],
)
like image 919
user1050619 Avatar asked Sep 03 '25 04:09

user1050619


1 Answers

You can have a look at this section of the disutils documentation, which gives a full explanation: http://docs.python.org/2/distutils/setupscript.html#listing-whole-packages

But in short, 'packages' refers to your code, not outside dependencies. If your setup.py file lives in the top level directory of your project, and your 'packages' argument lists towelstuff and towelstuff.test, here's how the directory structure should look:

setup.py
towelstuff
    __init__.py
    ...some other files in towelstuff...
towelstuff.test
    __init__.py
    ...some other files in towelstuff.test...
...some other scripts in the project directory...

Basically, a Python package is just a directory that contains an '__init__.py' file. When you write the setup.py file as you have, you're promising setup.py that there are two packages (towelstuff and towelstuff.test) that live in the same directory as the setup.py script.

In future, when you use your setup.py to bundle your application, those two packages will be included in the distribution.

like image 132
Stephan Avatar answered Sep 04 '25 17:09

Stephan