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

Building an open source Python application, the right way

Kiran
October 26, 2013

Building an open source Python application, the right way

Overview of conventions/best practices to follow when writing an open source Python application

Kiran

October 26, 2013
Tweet

More Decks by Kiran

Other Decks in Technology

Transcript

  1. Building open source
    the
    Python application
    right way
    an

    View full-size slide

  2. I’m Kiran.
    Hacker
    Programmer
    Open Source enthusiast
    Computer Science fanboy

    View full-size slide

  3. Currently, having an affair with
    Python

    View full-size slide

  4. Why follow Conventions
    Guidelines
    Best Practices

    View full-size slide

  5. Your code is
    Open Source !

    View full-size slide

  6. What does that mean
    You ask ?

    View full-size slide

  7. Code available to
    People will
    try to help
    start using it
    everyone
    People will(might)

    View full-size slide

  8. So, what do I do ?

    View full-size slide

  9. Make it easier for
    people to use 

    your application

    View full-size slide

  10. Let’s start with
    basic project structure

    View full-size slide

  11. Let’s make it simpler

    View full-size slide

  12. Documentation
    Tests
    Application
    Dependency Management
    Setup
    Task Execution
    Extras
    Publish

    View full-size slide

  13. Write good
    code.
    http://www.python.org/dev/peps/pep-0008/

    View full-size slide

  14. Don’t bloat your code with
    Use them when required
    classes

    View full-size slide

  15. to architect your application
    modules
    Use

    View full-size slide

  16. “Code not tested is broken by
    design”
    - Jacob Kaplan Moss

    View full-size slide

  17. Lots of ways to
    your application
    Test

    View full-size slide

  18. Start with simple
    unit tests

    View full-size slide

  19. unittest
    Nose
    py.test
    Most
    commonly
    used

    View full-size slide

  20. Documentation

    View full-size slide

  21. For small projects
    Code is the documentation
    http://www.python.org/dev/peps/pep-0257/

    View full-size slide

  22. Sadly
    This is not
    scalable

    View full-size slide

  23. Use Sphinx
    http://sphinx-doc.org/

    View full-size slide

  24. HTML
    EPUB
    PDF Man
    Pages
    LaTex
    Automatic
    Syntax
    Highlighting
    Plain Text
    Theming
    Support
    Internationalisation

    View full-size slide

  25. Dependency
    Management

    View full-size slide

  26. Project Dependencies
    requirements.txt

    View full-size slide

  27. pip install -r requirements.txt
    then

    View full-size slide

  28. Pro Tip:
    Use
    Virtualenv
    to setup your environment

    View full-size slide

  29. Why ?
    Test with different Python versions
    No unnecessary namespace pollution
    Different environments and settings
    per project
    Install dependencies inside environment

    View full-size slide

  30. setup.py
    contains the necessary information
    required for it’s installation
    Every project’s

    View full-size slide

  31. Packages and uploads your application to
    Python Package Index
    a.k.a
    PyPI

    View full-size slide

  32. setup(
    name='project name',
    version=myapp.__version__,
    description='project description here',
    license=open("LICENSE").read(),
    author='author',
    author_email='email',
    url='project url',
    packages=['myapp'],
    include_package_data=True,
    classifiers=(
    'Development Status :: 5 - Production/Stable',
    'Intended Audience :: Developers',
    'Natural Language :: English',
    'License :: OSI Approved :: MIT License',
    'Programming Language :: Python',
    'Programming Language :: Python :: 2.6',
    'Programming Language :: Python :: 2.7',
    'Programming Language :: Python :: 3.3',
    ),
    test_suite='tests',
    )

    View full-size slide

  33. Register at PyPI
    python setup.py register
    Package and Upload application
    python setup.py sdist upload

    View full-size slide

  34. Install application on any platform
    pip install myapp

    View full-size slide

  35. Task Execution

    View full-size slide

  36. Makefile
    Use a
    to automate multiple tasks
    and commands
    http://mrbook.org/tutorials/make/

    View full-size slide

  37. Extras
    (a.k.a enhancements)

    View full-size slide

  38. AUTHORS
    CHANGELOG
    CONTRIBUTING

    View full-size slide

  39. is
    License very important
    for open source projects
    http://www.tldrlegal.com/

    View full-size slide

  40. RECAP
    Documentation
    Tests
    Application
    Dependency Management
    Setup
    Task Execution
    Extras
    Publish

    View full-size slide

  41. Thank you !
    @kirang89
    http://kirang.in

    View full-size slide