First python project

22
My First Python Project Neetu Jain Software Engineer Softlayer, IBM [email protected] , [email protected]

description

Peak in to see how it looks like to get started in python

Transcript of First python project

Page 1: First python project

My First Python Project

Neetu Jain

Software Engineer

Softlayer, IBM

[email protected], [email protected]

Page 2: First python project

What’s Ahead?What to expect when diving into python:

Bird’s eye view of “getting started into python”

How to start your first python project:

some kind of a skeleton , resources, pointers

Help you realise that some comics hit close to home:

Thanks to xkcd.com

*** if you already know python, you might not get much out of this talk :)***

Page 3: First python project

First Stop:Install

Python Version:

Python 2.x or Python 3.x

Python IDE:

Pycharm, pythonwin, sublime ...e.t.c

version control:

git, svn...e.t.c

Page 4: First python project

Readability(whitespace) Matters!

Page 5: First python project

Zen Of PythonPEP8

pip install --upgrade pep8

pep8 --show-source --show-pep8 test.py4685 E501 line too long (80 > 79 characters)

1718 E302 expected 2 blank lines, found 1

pep8 --statistics -qq Project/

Pylint

pip install pylint

pylint --reports=n test.pyC0111: 4,0:sth1: Missing docstring

W0104: 5,4:sth1: Statement seems to have no effect

Page 6: First python project

No More Compiler Breaks!

Page 7: First python project

Nostalgia!

Page 8: First python project

Bye Bye Static Typing

Page 9: First python project

Built-in Data Structures

● Sets

● List

● Tuple

● Dictionary

Page 10: First python project

No Pointers->No Segfaults

*forget memory management and issues that arise from it*

Page 11: First python project

Recycling Wins Reinventing

Not likely in Python

Page 12: First python project

Power of PyPi

$pip install newpackage

$import newpackage

$newpackage.callitsfunction()

Page 13: First python project

Testing Tools Ensure Automation

**https://wiki.python.org/moin/PythonTestingToolsTaxonomy**

Page 14: First python project

Tests:made easy

$python unittest_simple.py

$ python unittest_simple.py -v

test (__main__.SimplisticTest) ... ok

------------------------------------

Ran 1 test in 0.000s

OK/FAIL/ERROR

unittest_simple.py

import unittest

class FixturesTest(unittest.TestCase):

def test(self):

print 'in test()'

self.failIf(True, 'failure message goes here')

if __name__ == '__main__':

unittest.main()

Page 15: First python project

Python: you can do a lot!

Database: sqlliteDeployment mgmt :fabric

Process mgmt: supervisor

Messaging: pika(amqp)Web framework:flask

Page 16: First python project
Page 17: First python project

Virtual environment$ [sudo] pip install virtualenv

$ cd ~/code/myproject/

$ virtualenv env

New python executable in env/bin/python

Installing setuptools............done.

Installing pip...............done.

$ ls env

bin include lib

$ which python

/usr/bin/python

$ source env/bin/activate

$ which python

/Users/name/code/myproject/env/bin/python

Page 18: First python project

Directory structure some_root_dir/

|-- LICENSE

|-- README

|-- setup.py

|-- example_project/

| |-- __init__.py

| |-- useful_1.py

| |-- drivers/

| | |--useful_2.py

|-- tests/

| |-- __init__.py

| |-- runall.py

| |-- test0.py

|-- docs/

| |--conf.py

| |--generated

Page 19: First python project

Setup.pyfrom setuptools import setup, find_packages

setup(

name='buzz',

version='0.1',

description=Project name ',

long_description=open('README.md', 'r').read(),

classifiers=[

'Development Status :: 1 - Beta',

'Programming Language :: Python :: 2.7',

],

author_email='[email protected]',

url='http://sldn.softlayer.com',

license='MIT',

packages=find_packages(),

include_package_data=True,

install_requires=[

‘package-name’,

‘docutils>=0.3’,

],

entry_points={

'console_scripts': [

'face_of_project = module:your_function,

]

},

#just download not install

setup_requires=[],

)

Page 20: First python project

vagrant VM manager

$ vagrant box add lucid32 http://files.vagrantup.com/lucid32.box

$ mkdir my_vagrant_test

$ cd my_vagrant_test

$ vagrant init lucid32

$ vim Vagrantfile

$ vagrant up

$ vagrant ssh

$ vagrant status

$ vagrant reload

$ vagrant destroy

Page 21: First python project

Supervisor: A Process Control Systemvagrant@buzz:~$ supervisord -c /vagrant/scripts/supervisord.conf

vagrant@buzz:~$ sudo supervisorctl -c /vagrant/scripts/supervisord.conf

apnsfb RUNNING pid 5671, uptime 0:02:17

buzz RUNNING pid 5673, uptime 0:02:17

flask RUNNING pid 5672, uptime 0:02:17

vagrant@buzz:~$ cat /tmp/supervisord.log

2014-09-12 18:31:22,001 CRIT Supervisor running as root (no user in config

file)

2014-09-12 18:31:22,017 INFO RPC interface 'supervisor' initialized

Page 22: First python project

My First Python Project

Neetu Jain

Software Engineer

Softlayer, IBM

[email protected], [email protected]