[Tutor] Need some help with setuptools for my project.

Anubhav Yadav anubhav1691 at gmail.com
Mon Apr 6 12:46:29 CEST 2015


Hi,

I am new to python and still trying to get my concepts clear with respect
to standard practices in python. I wrote a script which fetches the latest
cricket scores from the internet and sends desktop notifications using
pynotify. The project, initially supported both python2 as well as python3,
but I realized it is very difficult to keep up with the errors. So I
migrated the project to python2.

Now I wanted to make my script robust such that it could be installed
easily by the users. I broke up my script in logical modules and added them
all under root directory with the name of the project.

Here is how the source tree looks now:

|-- LICENSE
|-- README.md
|-- requirements.txt
|-- scorer
|   |-- app.py
|   |-- fetch_scores.py
|   |-- __init__.py
|   |-- __main__.py
|   |-- notification.py
|   |-- system.py
|   `-- ui.py
`-- setup.py

Where scorer is the name of the project. Here are the contents of the
requirements.txt file:

scorer
requests==2.6.0
beautifulsoup4==4.3.2

And here is my setup.py

from setuptools import setup

def readme():
    with open('README.md') as f:
        return f.read()

setup(
    name = 'scorer',
    version = 0.1,
    description = 'A simple script to show desktop notifications for
cricket scores',
    long_description = readme(),
    url = 'https://github.com/neo1691/scorer.py',
    author = 'Anubhav Yadav',
    author_email = 'anubhav1691 at gmail.com',
    license = 'GPLv2',
    packages = ['scorer'],
    install_requires=[
          'requests',
          'beautifulsoup4',
      ],
    zip_safe = False
        )

When I run ``python setup.py build``, It gives me the following output:

running build
running build_py
creating build
creating build/lib.linux-x86_64-2.7
creating build/lib.linux-x86_64-2.7/scorer
copying scorer/ui.py -> build/lib.linux-x86_64-2.7/scorer
copying scorer/__init__.py -> build/lib.linux-x86_64-2.7/scorer
copying scorer/system.py -> build/lib.linux-x86_64-2.7/scorer
copying scorer/fetch_scores.py -> build/lib.linux-x86_64-2.7/scorer
copying scorer/__main__.py -> build/lib.linux-x86_64-2.7/scorer
copying scorer/app.py -> build/lib.linux-x86_64-2.7/scorer
copying scorer/notification.py -> build/lib.linux-x86_64-2.7/scorer

It creates a build directory with the above files, and I have no idea what
to do with them. How to use it? Or how to test my app without installing
it.

If I then run ``sudo python setup.py install``, it gives me a lot of output
but one of the lines is:
Installed /usr/lib/python2.7/site-packages/scorer-0.1-py2.7.egg

A few more directories are created in my project directory, build, dist,
scorer.egg-info etc. Yet I still have no idea how to run my app.

I can run my app from the root of the project directory using ``python -m
scorer`` since I have called my main() function using the __main__.py file.

Can someone help me figure out how can I package my project according to
setuptools format? Also can someone tell me how to un-install the project
from systemwide after running ``sudo python setup.py install``?

Any help would be greatly appreciated. I apologize if my question does not
belongs to this mailing list. My project is hosted on github[1].

Thank you.

[1] https://github.com/neo1691/scorer.py

-- 
Regards,
Anubhav Yadav
KPIT Technologies,
Pune.


More information about the Tutor mailing list