Python Package: Difference between revisions
From charlesreid1
No edit summary |
No edit summary |
||
| Line 1: | Line 1: | ||
A skeleton Python package takes the following structure: | |||
<pre> | <pre> | ||
myproject/ | myproject/ | ||
| Line 19: | Line 21: | ||
==Setup.py== | ==Setup.py== | ||
Here's what the package setup file looks like: | |||
<pre> | <pre> | ||
| Line 43: | Line 47: | ||
==Test_code.py== | ==Test_code.py== | ||
It is important to test your code. Here's a skeleton nose test suite: | |||
<pre> | <pre> | ||
Revision as of 01:05, 19 March 2015
A skeleton Python package takes the following structure:
myproject/
setup.py
myproject/
__init__.py
code.py
submodule/
somecode.py
morecode.py
tests/
test_code.py
test_somecode.py
test_morecode.py
Setup.py
Here's what the package setup file looks like:
try:
from setuptools import setup
except ImportError:
from distutils.core import setup
config = {
'description': 'My Project',
'author': 'My Name',
'url': 'URL to get it at.',
'download_url': 'Where to download it.',
'author_email': 'My email.',
'version': '0.1',
'install_requires': ['nose'],
'packages': ['NAME'],
'scripts': [],
'name': 'projectname'
}
setup(**config)
Test_code.py
It is important to test your code. Here's a skeleton nose test suite:
from nose.tools import *
import NAME
def setup():
print "setup"
def teardown():
print "tear down"
def test_basic():
print "i run good"