Upgrade to Pro — share decks privately, control downloads, hide ads and more …

PyOhio 2015 - Python Packaging from Init to Deploy

Dave Forgac
August 02, 2015

PyOhio 2015 - Python Packaging from Init to Deploy

Python packaging really isn't that bad (anymore.) In this talk you'll learn how you can take your beautiful new Python code and share it with the world in a way that everyone benefits. I will cover tools and techniques you can use to get the boring stuff out of the way so you can focus on your code and deploy quickly, frequently, and consistently.

Dave Forgac

August 02, 2015
Tweet

More Decks by Dave Forgac

Other Decks in Technology

Transcript

  1. How to package? There should be one — and preferably

    only one — obvious way to do it.
  2. Components . ├── data │ └── data_file ├── DESCRIPTION.rst ├──

    MANIFEST.in ├── README.rst ├── sample │ ├── __init__.py │ └── package_data.dat ├── setup.cfg ├── setup.py └── tests ├── __init__.py └── test_simple.py
  3. setup.py (1) from setuptools import setup, find_packages setup( name='pyohio2015', version='0.1.0',

    # PEP440 description='Example package for PyOhio talk.', long_description='Displayed on PyPI project page.', url='https://github.com/tylerdave/PyOhio-2015-Example', author='Dave Forgac', author_email='[email protected]', …
  4. setup.py (2) … license='MIT', classifiers=[ 'Development Status :: 3 -

    Alpha', 'Intended Audience :: Developers', 'License :: OSI Approved :: MIT License', 'Programming Language :: Python :: 2', 'Programming Language :: Python :: 2.7', 'Programming Language :: Python :: 3', 'Programming Language :: Python :: 3.3', 'Programming Language :: Python :: 3.4', ], …
  5. Other files (rst | md | txt) HISTORY or CHANGES

    or CHANGELOG CONTRIBUTING AUTHORS
  6. Run cookiecutter dave@xps:$ cookiecutter https://github.com/tylerdave/cookiec python-package.git … full_name (default is

    "Dave Forgac")? email (default is "[email protected]")? github_username (default is "tylerdave")? project_name (default is "Python Boilerplate")? PyOhio 2015 repo_name (default is "boilerplate")? pyohio2015 project_short_description (default is "Python Boilerplate co all the boilerplate you need to create a Python package.")? package for PyOhio talk. release_date (default is "2015-08-02")? year (default is "2015")? version (default is "0.1.0")?
  7. Add your code pyohio2015/cli.py: from __future__ import print_function def hello():

    """ Returns a Hello, World! """ return("Hello, PyOhio!") def say_hello(): """ Prints Hello, World message """ print(hello())
  8. Add tests tests/test_pyohio2015.py: import pyohio2015 class TestPyohio2015(unittest.TestCase): def setUp(self): self.hello_message

    = "Hello, PyOhio!" def test_prints_hello_pyohio(self): output = pyohio2015.hello() assert(output == self.hello_message)
  9. Run tests tox … OK ___________________________ summary ________________________ py26: InterpreterNotFound:

    python2.6 py27: commands succeeded py33: InterpreterNotFound: python3.3 py34: commands succeeded
  10. Git push To [email protected]:tylerdave/PyOhio-2015-Example.git * [new branch] master -> master

    Branch master set up to track remote branch master from origin.
  11. Commit, tag, & push git commit -m "awesome new functionality!"

    git push origin master git tag v0.2.0 git push origin --tags