how to deliver a python project

20
matt_davidson@python_talks ~/ $ delivering a python project

Upload: mattjdavidson

Post on 07-Aug-2015

53 views

Category:

Software


3 download

TRANSCRIPT

Page 1: How to deliver a Python project

matt_davidson@python_talks ~/ $ delivering a python project

Page 2: How to deliver a Python project

|-- my_first_module.py|-- test_my_first_module.py

your current code

Page 3: How to deliver a Python project

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

Page 4: How to deliver a Python project

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

Page 5: How to deliver a Python project

docopt==0.6.2requests==2.7.0

requirements.txt

Page 6: How to deliver a Python project

""" my_first_package is a dummy package used for presentations"""

__version__ = '0.0.1'

__init__.py

Page 7: How to deliver a Python project

|- 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

Page 8: How to deliver a Python project

• Create projects using templates• Windows, Mac, Linux• Python, Javascript, Ruby etc.

https://github.com/audreyr/cookiecutter

Page 9: How to deliver a Python project

code documentation• Readability > Verbosity• Generate from docstrings• Use a tool!

Page 10: How to deliver a Python project

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

Page 11: How to deliver a Python project

doc generators• http://sphinx-doc.org/• http://fitzgen.github.io/pycco/• http://www.mkdocs.org/

Page 12: How to deliver a Python project

dependencies• Manage throughout development

lifecycle• Dependency’s dependenciesmatt@workstation ~/code $ pip freeze > requirements.txt

Page 13: How to deliver a Python project

pip• PyPA recommended install tool• Easy to use with PyPI (mirrors),

wheels• Easy requirements gathering• 2.7.9+ 3.4+ included

Page 14: How to deliver a Python project

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.

Page 15: How to deliver a Python project

wheel PEP 427• A zip archive• Requires setup.py and PEP 376 files• Wheel > egg (dependencies)

Page 16: How to deliver a Python project

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.

Page 17: How to deliver a Python project

tying it all together• Organise your code• Run your tests• Generate your documents• Build your wheels• Distribute your wheels• Share your code

Page 18: How to deliver a Python project

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.

Page 19: How to deliver a Python project

future talks suggestions• Development Tools and Virtualenvs• Unit Testing and Docker• Python 2 vs Python 3 & “future”

proofing• Intermediate Python• Pythonic Code