how to deliver a python project
TRANSCRIPT
matt_davidson@python_talks ~/ $ delivering a python project
|-- my_first_module.py|-- test_my_first_module.py
your current code
setup( name='my_first_package', version=my_first_package.__version__, author='Matt Davidson', tests_require=['pytest'], install_requires=['requests==2.7.0', 'docopt==0.6.2' ], cmdclass={'test': PyTest}, author_email='[email protected]', description='A dummy package used for presentations', long_description=long_description, packages=['my_first_package'], include_package_data=True, platforms='any',
setup.py
my_first_package=======Documentation-------------Available in docs directory of the project, hopefully hosted somewhere else too!
### Installation
`pip install my_first_package`
## Contact Me
Questions or comments about `my first package`? Hit me up at[[email protected]](mailto:[email protected]).
README.md
docopt==0.6.2requests==2.7.0
requirements.txt
""" my_first_package is a dummy package used for presentations"""
__version__ = '0.0.1'
__init__.py
|- README.md|- requirements.txt|- setup.py|- docs| |-- my_first_module.rst|- my_first_package| |-- __init__.py| |-- my_first_module.py|- tests| |-- test_my_first_module.py
your code now
• Create projects using templates• Windows, Mac, Linux• Python, Javascript, Ruby etc.
https://github.com/audreyr/cookiecutter
code documentation• Readability > Verbosity• Generate from docstrings• Use a tool!
def complex(real=0.0, imag=0.0): """Form a complex number.
If necessary you can include a much longer multi line explanation here if the single line explanation is not sufficient.
Keyword arguments: real -- the real part (default 0.0) imag -- the imaginary part (default 0.0) """ if imag == 0.0 and real == 0.0: return complex_zero ...
docstrings PEP 0257
doc generators• http://sphinx-doc.org/• http://fitzgen.github.io/pycco/• http://www.mkdocs.org/
dependencies• Manage throughout development
lifecycle• Dependency’s dependenciesmatt@workstation ~/code $ pip freeze > requirements.txt
pip• PyPA recommended install tool• Easy to use with PyPI (mirrors),
wheels• Easy requirements gathering• 2.7.9+ 3.4+ included
matt@workstation ~/code $ pip install my_first_package
matt@workstation ~/code $ pip install /path/to/dir
matt@workstation ~/code $ pip install -e /path/to/dir
matt@workstation ~/code $ pip install -r requirements.txt
matt@workstation ~/code $ pip uninstall ...
matt@workstation ~/code $ pip install --no-index --find-links /path/to/dependencies my_first_package
pip cont.
wheel PEP 427• A zip archive• Requires setup.py and PEP 376 files• Wheel > egg (dependencies)
matt@workstation ~/code $ python setup.py bdist_wheel
matt@workstation ~/code $ pip install wheel
matt@workstation ~/code $ pip --wheel-dir /path/to/dir my_first_package
matt@workstation ~/code $ pip install --no-index --find-links /path/to/dir my_first_package
wheel cont.
tying it all together• Organise your code• Run your tests• Generate your documents• Build your wheels• Distribute your wheels• Share your code
matt@workstation ~/code $ python setup.py test
matt@workstation ~/code $ sphinx/pycco ...
matt@workstation ~/code $ pip wheel --wheel-dir /path/to/dir my_first_package
matt@workstation ~/code $ git bundle create repo.bundle --all
matt@workstation ~/code $ pip install --no-index --find-links /path/to/dir my_first_package
tying it all together cont.
future talks suggestions• Development Tools and Virtualenvs• Unit Testing and Docker• Python 2 vs Python 3 & “future”
proofing• Intermediate Python• Pythonic Code
references• https://www.python.org/dev/peps• http://www.jeffknupp.com/blog/• http://docs.python-guide.org
/en/latest/