What scripts would go into a bin folder of a Python package?
Asked Answered
C

2

22

I'm learning about Python Packages from Learn Python the Hard Way and one of the exercises it says:

Put a script in the bin directory that you can run

To me, it seems kind of vague. I'm not exactly sure what kind of scripts would go into the bin folder. The Hitchhiker's Guide to Packaging says

put into bin any scripts you’ve written that use your package and which you think would be useful for your users. If you don’t have any, then remove the bin directory.

But I'm still left wondering what kind of script would go in there. So, I know its may sound like a dumb question, but can someone give me an example of when, and why one would put "a script" in their package's bin folder?

Correia answered 29/5, 2012 at 2:58 Comment(0)
B
3

For example Django's project creating, Scrapy's project creating, django-admin.py and scrapy are both scripts in bin folder.

You could get even more examples by checking almost python-based tools.

Bozuwa answered 29/5, 2012 at 3:15 Comment(0)
B
22

I just recently got through Ex46 in LPTHW myself. Like you, I was confused by the scripts. In case the other answer was too advanced for you, I ended up just putting in a simple "hello world" script:

#!/usr/bin/env python

from test3 import printstring
printstring.printstring("test script working")
print "test over"

I named that file testscript3.py (*Note, I learned later that it would be more convenient to leave off the .py filename extension if it were a real script that I wanted to seem like a system command)

My file test3.py was like so:

def printstring(s='you did not provide string'):
    print s

Here's some newbie things that I learned while trying to get this process to work:

  • The #! symbol is sometimes pronounced shebang and the simple explanation is that the command on that line tells the shell to use python to run the script. If you leave off the ".py" filename extension, then the user of the script doesn't need to care what interpreter is needed to run the script. See wikipedia shebang article.

  • I ran the following command to package the distribution:

    python setup.py sdist

  • After doing that, I was able to install the package and script by running

    sudo pip install test3-0.1.tar.gz

  • One thing I worried about was permissions on the script file. However, I noticed that distutils took care of this when packaging (changed mode to 755 or whatever).

You can find my whole project for this example on github.

Beading answered 31/7, 2012 at 19:4 Comment(0)
B
3

For example Django's project creating, Scrapy's project creating, django-admin.py and scrapy are both scripts in bin folder.

You could get even more examples by checking almost python-based tools.

Bozuwa answered 29/5, 2012 at 3:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.