Building an open source
Python application
the right way
Hi.
I’m Kiran.
Hacker
Programmer
Open Source enthusiast
Computer Science fanboy
Currently, having an affair with

Python
Why follow

Guidelines
Conventions
Best Practices
Your code is

Open Source !
What does that mean

You ask ?
Code available to
People will

everyone

start using it

People will(might)

try to help
So, what do I do ?
Make it easier for
people to use 

your application
How ?
Let’s start with
basic project structure
Let’s make it simpler
Application
Tests
Documentation
Dependency Management
Setup
Publish
Task Execution
Extras
Application
Write good
code.
http://www.python.org/dev/peps/pep-0008/
Don’t bloat your code with

classes
Use them when required
Use

modules
to architect your application
Tests
“Code not tested is broken by
design”
- Jacob Kaplan Moss
Lots of ways to

Test

your application
unit tests

Start with simple
py.test
unittest
Nose

Most
commonly
used
Documentation
For small projects

Code is the documentation
http://www.python.org/dev/peps/pep-0257/
Sadly
This is not

scalable
Use

Sphinx

http://sphinx-doc.org/
HTML
EPUB
Automatic
Syntax
Highlighting

PDF
Plain Text

Theming
Support
Man
Pages

LaTex

Internationalisation
Dependency
Management
Project Dependencies

requirements.txt
then

pip install -r requirements.txt
Setup
Pro Tip:
Use

Virtualenv
to setup your environment
Why ?
Test with different Python versions
Install dependencies inside environment
No unnecessary namespace pollution
Diffe...
Publish
Every project’s

setup.py
contains the necessary information
required for it’s installation
Packages and uploads your application to

Python Package Index
a.k.a

PyPI
setup(
name='project name',
version=myapp.__version__,
description='project description here',
license=open("LICENSE").rea...
Register at PyPI

python setup.py register
Package and Upload application

python setup.py sdist upload
Install application on any platform

pip install myapp
Task Execution
Use a

Makefile
to automate multiple tasks
and commands

http://mrbook.org/tutorials/make/
Extras
(a.k.a enhancements)
AUTHORS
CHANGELOG
CONTRIBUTING
License

is
very important
for open source projects

http://www.tldrlegal.com/
Recap
R

C
E

P
A

Application
Tests
Documentation

Dependency Management
Setup
Publish
Task Execution
Extras
Questions ?
Thank you !
@kirang89
http://kirang.in
Building an open source python application the right way
Building an open source python application the right way
Building an open source python application the right way
Building an open source python application the right way
Upcoming SlideShare
Loading in...5
×

Building an open source python application the right way

358
-1

Published on

Best practices to be followed while building an open source Python application.

Published in: Technology

Building an open source python application the right way

  1. 1. Building an open source Python application the right way
  2. 2. Hi.
  3. 3. I’m Kiran. Hacker Programmer Open Source enthusiast Computer Science fanboy
  4. 4. Currently, having an affair with Python
  5. 5. Why follow Guidelines Conventions Best Practices
  6. 6. Your code is Open Source !
  7. 7. What does that mean You ask ?
  8. 8. Code available to People will everyone start using it People will(might) try to help
  9. 9. So, what do I do ?
  10. 10. Make it easier for people to use 
 your application
  11. 11. How ?
  12. 12. Let’s start with basic project structure
  13. 13. Let’s make it simpler
  14. 14. Application Tests Documentation Dependency Management Setup Publish Task Execution Extras
  15. 15. Application
  16. 16. Write good code. http://www.python.org/dev/peps/pep-0008/
  17. 17. Don’t bloat your code with classes Use them when required
  18. 18. Use modules to architect your application
  19. 19. Tests
  20. 20. “Code not tested is broken by design” - Jacob Kaplan Moss
  21. 21. Lots of ways to Test your application
  22. 22. unit tests Start with simple
  23. 23. py.test unittest Nose Most commonly used
  24. 24. Documentation
  25. 25. For small projects Code is the documentation http://www.python.org/dev/peps/pep-0257/
  26. 26. Sadly This is not scalable
  27. 27. Use Sphinx http://sphinx-doc.org/
  28. 28. HTML EPUB Automatic Syntax Highlighting PDF Plain Text Theming Support Man Pages LaTex Internationalisation
  29. 29. Dependency Management
  30. 30. Project Dependencies requirements.txt
  31. 31. then pip install -r requirements.txt
  32. 32. Setup
  33. 33. Pro Tip: Use Virtualenv to setup your environment
  34. 34. Why ? Test with different Python versions Install dependencies inside environment No unnecessary namespace pollution Different environments and settings per project
  35. 35. Publish
  36. 36. Every project’s setup.py contains the necessary information required for it’s installation
  37. 37. Packages and uploads your application to Python Package Index a.k.a PyPI
  38. 38. 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', )
  39. 39. Register at PyPI python setup.py register Package and Upload application python setup.py sdist upload
  40. 40. Install application on any platform pip install myapp
  41. 41. Task Execution
  42. 42. Use a Makefile to automate multiple tasks and commands http://mrbook.org/tutorials/make/
  43. 43. Extras (a.k.a enhancements)
  44. 44. AUTHORS CHANGELOG CONTRIBUTING
  45. 45. License is very important for open source projects http://www.tldrlegal.com/
  46. 46. Recap
  47. 47. R C E P A Application Tests Documentation Dependency Management Setup Publish Task Execution Extras
  48. 48. Questions ?
  49. 49. Thank you ! @kirang89 http://kirang.in

×