SlideShare a Scribd company logo
1 of 34
Download to read offline
Isolated Development
            in Python
1. pip installer
pip installer


 $ pip install <package>
pip installer


 $ pip install <package>


                Download package from pypi.python.org
pip installer


 $ pip install <package>


                Download package from pypi.python.org




 $ pip install <directory>
 $ pip install <tar.gz>
pip installer


 $ pip install <gitrepo>
pip installer


 $ pip install <gitrepo>




                           GREAT!!
pip installer


 $ pip install <gitrepo>




                           GREAT!!
 $ pip install git+git://github.com/ajdiaz/mole
 $ pip install git+ssh://github.com/ajdiaz/mole
 $ pip install git+git://github.com/ajdiaz/mole@840d25
 $ pip install git+git://github.com/ajdiaz/mole@devel-branch
 $ pip install git+git://....@devel-branch#egg=Mole
pip installer


 $ pip freeze
pip installer


 $ pip freeze
 Fabric==1.5.2
 GitPython==0.3.2.RC1
 Jinja2==2.6
 Pygments==1.6
 Sphinx==1.2b1          Create requirements.txt
 argparse==1.2.1
 async==0.6.1
 boto==2.7.0
 cuisine==0.5.1
 distribute==0.6.24
 docutils==0.10
 gitdb==0.5.4
 mico==0
 paramiko==1.9.0
 pycrypto==2.6
 smmap==0.8.2
 wsgiref==0.1.2
2. Virtualenv: a jail for python
Virtualenv: the python jail


 $ virtualenv --python=/usr/bin/python2.7 mynewenvironment
Virtualenv: the python jail


 $ virtualenv --python=/usr/bin/python2.7 mynewenvironment




                      OR EVEN BETTER
Virtualenv: the python jail


 $ virtualenv --python=/usr/bin/python2.7 mynewenvironment




                      OR EVEN BETTER




 $ mkvirtualenv --python=/usr/bin/python2.7 mynewenvironment
Virtualenv: the python jail


  $ virtualenv --python=/usr/bin/python2.7 mynewenvironment




                       OR EVEN BETTER




  $ mkvirtualenv --python=/usr/bin/python2.7 mynewenvironment




mkvirtualenvwrapper
Virtualenvwrapper


$ mkvirtualenv test
Virtualenvwrapper


$ mkvirtualenv test
New python executable in test/bin/python
Installing
distribute......................................................................................................................
.......................................................................done.
Installing pip...............done.
virtualenvwrapper.user_scripts creating /home/ajdiaz/env/test/bin/predeactivate
virtualenvwrapper.user_scripts creating /home/ajdiaz/env/test/bin/postdeactivate
virtualenvwrapper.user_scripts creating /home/ajdiaz/env/test/bin/preactivate
virtualenvwrapper.user_scripts creating /home/ajdiaz/env/test/bin/postactivate
virtualenvwrapper.user_scripts creating /home/ajdiaz/env/test/bin/get_env_details
(test) $
Virtualenvwrapper


$ mkvirtualenv test
New python executable in test/bin/python
Installing
distribute......................................................................................................................
.......................................................................done.
Installing pip...............done.
virtualenvwrapper.user_scripts creating /home/ajdiaz/env/test/bin/predeactivate
virtualenvwrapper.user_scripts creating /home/ajdiaz/env/test/bin/postdeactivate
virtualenvwrapper.user_scripts creating /home/ajdiaz/env/test/bin/preactivate
virtualenvwrapper.user_scripts creating /home/ajdiaz/env/test/bin/postactivate
virtualenvwrapper.user_scripts creating /home/ajdiaz/env/test/bin/get_env_details
(test) $ which python
/home/ajdiaz/env/test/bin/python
Virtualenvwrapper


$ mkvirtualenv test
New python executable in test/bin/python
Installing
distribute......................................................................................................................
.......................................................................done.
Installing pip...............done.
virtualenvwrapper.user_scripts creating /home/ajdiaz/env/test/bin/predeactivate
virtualenvwrapper.user_scripts creating /home/ajdiaz/env/test/bin/postdeactivate
virtualenvwrapper.user_scripts creating /home/ajdiaz/env/test/bin/preactivate
virtualenvwrapper.user_scripts creating /home/ajdiaz/env/test/bin/postactivate
virtualenvwrapper.user_scripts creating /home/ajdiaz/env/test/bin/get_env_details
(test) $ which python
/home/ajdiaz/env/test/bin/python
                                                                   yep, these are hooks!
Unit testing
Unit testing: nose


class A(object):
  def __init__(self):
    self.value = "Some Value"

  def return_true(self):
    return True                 save it in a.py
  def raise_exc(self, val):
    raise KeyError(val)
Unit testing: nose

from a import A
from nose.tools import assert_equal
from nose.tools import assert_not_equal
from nose.tools import assert_raises
from nose.tools import raises

class TestA(object):
  @classmethod
  def setup_class(klass):
    """This method is run once for each class before any tests are run"""

  @classmethod
  def teardown_class(klass):
    """This method is run once for each class _after_ all tests are run"""

  def setUp(self):
    """This method is run once before _each_ test method is executed"""

  def teardown(self):
    """This method is run once after _each_ test method is executed"""



            .... continue ....
Unit testing: nose

def test_init(self):
    a = A()
    assert_equal(a.value, "Some Value")
    assert_not_equal(a.value, "Incorrect Value")

 def test_return_true(self):
   a = A()
   assert_equal(a.return_true(), True)
   assert_not_equal(a.return_true(), False)

 def test_raise_exc(self):
   a = A()
   assert_raises(KeyError, a.raise_exc, "A value")

 @raises(KeyError)
 def test_raise_exc_with_decorator(self):
   a = A()
   a.raise_exc("A message")




                 save it in tests/testa.py
Unit testing: nose


$ nosetests -v tests/
Unit testing: nose


$ nosetests -v tests/


testa.TestA.test_init ... ok
testa.TestA.test_raise_exc ... ok
testa.TestA.test_raise_exc_with_decorator ... ok
testa.TestA.test_return_true ... ok

---------------------------------------------------------
Ran 4 tests in 0.002s

OK
Unit testing: Bonus: code coverage


$ pip install coverage

$ nosetests --with-coverage
....
Name Stmts Miss Cover Missing
-------------------------------------
a      8    0 100%
-------------------------------------
Ran 4 tests in 0.006s OK
Packaging Python Eggs
Python eggs: basic setup.py


    from setuptools import setup

setup(
  name = "example",
  version = "1.0",
  description = "An example package",
     author='Andres J. Diaz'
)
Python eggs: basic setup.py


from setuptools import setup, find_packages

setup(
  name = "example",
  version = "1.0",
  description = "An example package",
  author='Andres J. Diaz',
  packages=find_packages()
)
Python eggs: complex setup.py


import re

from setuptools import setup, find_packages
from os import path

def parse_requirements(file_name):
  requirements = []
  for line in open(file_name, 'r').read().split('n'):
     if re.match(r'(s*#)|(s*$)', line):
       continue
     if re.match(r's*-es+', line):
       requirements.append(re.sub(r's*-es+.*#egg=(.*)$', r'1', line))
     elif re.match(r's*-fs+', line):
       pass
     else:
       requirements.append(line)
  return requirements

        .... continue ....
Python eggs: complex setup.py


def parse_dependency_links(file_name):
  dependency_links = []
  for line in open(file_name, 'r').read().split('n'):
     if re.match(r's*-[ef]s+', line):
       dependency_links.append(re.sub(r's*-[ef]s+', '', line))
  return dependency_links


def get_file_contents(filename):
  fd = file(path.join(path.dirname(__file__), filename), "r")
  content = fd.read()
  fd.close()
  return content




        .... continue ....
Python eggs: complex setup.py


setup(
  name = "mico",
  version = "0.1",
  description = "A monkey driven cloud management",
  long_description=get_file_contents("README.rst"),
  author='Andres J. Diaz',
  author_email='ajdiaz@connectical.com',
  url='http://ajdiaz.github.com/mico',
  packages=find_packages(),
  install_requires = parse_requirements('requirements.txt'),
  dependency_links = parse_dependency_links('requirements.txt'),
  entry_points={
     'console_scripts': [
         'mico = mico.scripts.cmdline:main',
     ]
  },
  classifiers=[
       'Development Status :: 4 - Beta',
       'Intended Audience :: Developers',
       'License :: OSI Approved :: GNU General Public License (GPL)',
       'Operating System :: OS Independent',
       'Programming Language :: Python',
  ],
)
Python eggs: complex setup.py


setup(
  name = "mico",
  version = "0.1",
  description = "A monkey driven cloud management",
  long_description=get_file_contents("README.rst"),
  author='Andres J. Diaz',
  author_email='ajdiaz@connectical.com',
  url='http://ajdiaz.github.com/mico',
  packages=find_packages(),
  install_requires = parse_requirements('requirements.txt'),
  dependency_links = parse_dependency_links('requirements.txt'),
  entry_points={
     'console_scripts': [
         'mico = mico.scripts.cmdline:main',
     ]
  },
  classifiers=[
       'Development Status :: 4 - Beta',
       'Intended Audience :: Developers',
       'License :: OSI Approved :: GNU General Public License (GPL)',
       'Operating System :: OS Independent',
       'Programming Language :: Python',
  ],
)
Applauses & questions
     Not necessarily in that order.

More Related Content

What's hot

Django’s nasal passage
Django’s nasal passageDjango’s nasal passage
Django’s nasal passage
Erik Rose
 
Hacking Mac OSX Cocoa API from Perl
Hacking Mac OSX Cocoa API from PerlHacking Mac OSX Cocoa API from Perl
Hacking Mac OSX Cocoa API from Perl
typester
 

What's hot (20)

Workshop quality assurance for php projects - ZendCon 2013
Workshop quality assurance for php projects - ZendCon 2013Workshop quality assurance for php projects - ZendCon 2013
Workshop quality assurance for php projects - ZendCon 2013
 
Py.test
Py.testPy.test
Py.test
 
Puppet: What _not_ to do
Puppet: What _not_ to doPuppet: What _not_ to do
Puppet: What _not_ to do
 
Let's read code: python-requests library
Let's read code: python-requests libraryLet's read code: python-requests library
Let's read code: python-requests library
 
Five
FiveFive
Five
 
UA testing with Selenium and PHPUnit - PFCongres 2013
UA testing with Selenium and PHPUnit - PFCongres 2013UA testing with Selenium and PHPUnit - PFCongres 2013
UA testing with Selenium and PHPUnit - PFCongres 2013
 
Let's read code: the python-requests library
Let's read code: the python-requests libraryLet's read code: the python-requests library
Let's read code: the python-requests library
 
dotCloud and go
dotCloud and godotCloud and go
dotCloud and go
 
Django’s nasal passage
Django’s nasal passageDjango’s nasal passage
Django’s nasal passage
 
Python在豆瓣的应用
Python在豆瓣的应用Python在豆瓣的应用
Python在豆瓣的应用
 
Java设置环境变量
Java设置环境变量Java设置环境变量
Java设置环境变量
 
Voxxed Days Vilnius 2015 - Having fun with Javassist
Voxxed Days Vilnius 2015 - Having fun with JavassistVoxxed Days Vilnius 2015 - Having fun with Javassist
Voxxed Days Vilnius 2015 - Having fun with Javassist
 
Hacking Mac OSX Cocoa API from Perl
Hacking Mac OSX Cocoa API from PerlHacking Mac OSX Cocoa API from Perl
Hacking Mac OSX Cocoa API from Perl
 
Pytest: escreva menos, teste mais
Pytest: escreva menos, teste maisPytest: escreva menos, teste mais
Pytest: escreva menos, teste mais
 
#SPUG - Legacy applications
#SPUG - Legacy applications#SPUG - Legacy applications
#SPUG - Legacy applications
 
Puppet Continuous Integration with PE and GitLab
Puppet Continuous Integration with PE and GitLabPuppet Continuous Integration with PE and GitLab
Puppet Continuous Integration with PE and GitLab
 
Google I/O 2021 Recap
Google I/O 2021 RecapGoogle I/O 2021 Recap
Google I/O 2021 Recap
 
Memory Manglement in Raku
Memory Manglement in RakuMemory Manglement in Raku
Memory Manglement in Raku
 
Non stop random2b
Non stop random2bNon stop random2b
Non stop random2b
 
EuroPython 2015 - Decorators demystified
EuroPython 2015 - Decorators demystifiedEuroPython 2015 - Decorators demystified
EuroPython 2015 - Decorators demystified
 

Viewers also liked

Mico: A monkey in the cloud
Mico: A monkey in the cloudMico: A monkey in the cloud
Mico: A monkey in the cloud
Andrés J. Díaz
 

Viewers also liked (20)

Mico: A monkey in the cloud
Mico: A monkey in the cloudMico: A monkey in the cloud
Mico: A monkey in the cloud
 
Python speleology
Python speleologyPython speleology
Python speleology
 
We Buy Cheese in a Cheese Shop
We Buy Cheese in a Cheese ShopWe Buy Cheese in a Cheese Shop
We Buy Cheese in a Cheese Shop
 
Python, Development Environment for Windows
Python, Development Environment for WindowsPython, Development Environment for Windows
Python, Development Environment for Windows
 
Python Recipes for django girls seoul
Python Recipes for django girls seoulPython Recipes for django girls seoul
Python Recipes for django girls seoul
 
Overview of Testing Talks at Pycon
Overview of Testing Talks at PyconOverview of Testing Talks at Pycon
Overview of Testing Talks at Pycon
 
Authentication & Authorization in ASPdotNet MVC
Authentication & Authorization in ASPdotNet MVCAuthentication & Authorization in ASPdotNet MVC
Authentication & Authorization in ASPdotNet MVC
 
Rabbitmq & Postgresql
Rabbitmq & PostgresqlRabbitmq & Postgresql
Rabbitmq & Postgresql
 
PyClab.__init__(self)
PyClab.__init__(self)PyClab.__init__(self)
PyClab.__init__(self)
 
NoSql Day - Chiusura
NoSql Day - ChiusuraNoSql Day - Chiusura
NoSql Day - Chiusura
 
2 × 3 = 6
2 × 3 = 62 × 3 = 6
2 × 3 = 6
 
PythonBrasil[8] closing
PythonBrasil[8] closingPythonBrasil[8] closing
PythonBrasil[8] closing
 
Django - The Web framework for perfectionists with deadlines
Django - The Web framework for perfectionists with deadlinesDjango - The Web framework for perfectionists with deadlines
Django - The Web framework for perfectionists with deadlines
 
Load testing
Load testingLoad testing
Load testing
 
The Django Book, Chapter 16: django.contrib
The Django Book, Chapter 16: django.contribThe Django Book, Chapter 16: django.contrib
The Django Book, Chapter 16: django.contrib
 
Django - The Web framework for perfectionists with deadlines
Django - The Web framework  for perfectionists with deadlinesDjango - The Web framework  for perfectionists with deadlines
Django - The Web framework for perfectionists with deadlines
 
Django-Queryset
Django-QuerysetDjango-Queryset
Django-Queryset
 
Bottle - Python Web Microframework
Bottle - Python Web MicroframeworkBottle - Python Web Microframework
Bottle - Python Web Microframework
 
2007 - 应用系统脆弱性概论
2007 - 应用系统脆弱性概论 2007 - 应用系统脆弱性概论
2007 - 应用系统脆弱性概论
 
Digesting jQuery
Digesting jQueryDigesting jQuery
Digesting jQuery
 

Similar to Isolated development in python

From Dev to DevOps - Codemotion ES 2012
From Dev to DevOps - Codemotion ES 2012From Dev to DevOps - Codemotion ES 2012
From Dev to DevOps - Codemotion ES 2012
Carlos Sanchez
 
From Dev to DevOps - ApacheCON NA 2011
From Dev to DevOps - ApacheCON NA 2011From Dev to DevOps - ApacheCON NA 2011
From Dev to DevOps - ApacheCON NA 2011
Carlos Sanchez
 
From Dev to DevOps - FOSDEM 2012
From Dev to DevOps - FOSDEM 2012From Dev to DevOps - FOSDEM 2012
From Dev to DevOps - FOSDEM 2012
Carlos Sanchez
 
Continuous Delivery with Maven, Puppet and Tomcat - ApacheCon NA 2013
Continuous Delivery with Maven, Puppet and Tomcat - ApacheCon NA 2013Continuous Delivery with Maven, Puppet and Tomcat - ApacheCon NA 2013
Continuous Delivery with Maven, Puppet and Tomcat - ApacheCon NA 2013
Carlos Sanchez
 
Django deployment best practices
Django deployment best practicesDjango deployment best practices
Django deployment best practices
Erik LaBianca
 
Puppet for Java developers - JavaZone NO 2012
Puppet for Java developers - JavaZone NO 2012Puppet for Java developers - JavaZone NO 2012
Puppet for Java developers - JavaZone NO 2012
Carlos Sanchez
 
Hello click click boom
Hello click click boomHello click click boom
Hello click click boom
symbian_mgl
 
Making the most of your Test Suite
Making the most of your Test SuiteMaking the most of your Test Suite
Making the most of your Test Suite
ericholscher
 

Similar to Isolated development in python (20)

From Dev to DevOps - Codemotion ES 2012
From Dev to DevOps - Codemotion ES 2012From Dev to DevOps - Codemotion ES 2012
From Dev to DevOps - Codemotion ES 2012
 
Arbeiten mit distribute, pip und virtualenv
Arbeiten mit distribute, pip und virtualenvArbeiten mit distribute, pip und virtualenv
Arbeiten mit distribute, pip und virtualenv
 
MT_01_unittest_python.pdf
MT_01_unittest_python.pdfMT_01_unittest_python.pdf
MT_01_unittest_python.pdf
 
From Dev to DevOps - ApacheCON NA 2011
From Dev to DevOps - ApacheCON NA 2011From Dev to DevOps - ApacheCON NA 2011
From Dev to DevOps - ApacheCON NA 2011
 
Virtualenv
VirtualenvVirtualenv
Virtualenv
 
From Dev to DevOps - FOSDEM 2012
From Dev to DevOps - FOSDEM 2012From Dev to DevOps - FOSDEM 2012
From Dev to DevOps - FOSDEM 2012
 
Continuous Delivery with Maven, Puppet and Tomcat - ApacheCon NA 2013
Continuous Delivery with Maven, Puppet and Tomcat - ApacheCon NA 2013Continuous Delivery with Maven, Puppet and Tomcat - ApacheCon NA 2013
Continuous Delivery with Maven, Puppet and Tomcat - ApacheCon NA 2013
 
Django deployment best practices
Django deployment best practicesDjango deployment best practices
Django deployment best practices
 
Puppet for Java developers - JavaZone NO 2012
Puppet for Java developers - JavaZone NO 2012Puppet for Java developers - JavaZone NO 2012
Puppet for Java developers - JavaZone NO 2012
 
Effective testing with pytest
Effective testing with pytestEffective testing with pytest
Effective testing with pytest
 
Test-Driven Puppet Development - PuppetConf 2014
Test-Driven Puppet Development - PuppetConf 2014Test-Driven Puppet Development - PuppetConf 2014
Test-Driven Puppet Development - PuppetConf 2014
 
Hello click click boom
Hello click click boomHello click click boom
Hello click click boom
 
From Dev to DevOps
From Dev to DevOpsFrom Dev to DevOps
From Dev to DevOps
 
Тестирование и Django
Тестирование и DjangoТестирование и Django
Тестирование и Django
 
Custom deployments with sbt-native-packager
Custom deployments with sbt-native-packagerCustom deployments with sbt-native-packager
Custom deployments with sbt-native-packager
 
Arbeiten mit distribute, pip und virtualenv
Arbeiten mit distribute, pip und virtualenvArbeiten mit distribute, pip und virtualenv
Arbeiten mit distribute, pip und virtualenv
 
Python virtualenv & pip in 90 minutes
Python virtualenv & pip in 90 minutesPython virtualenv & pip in 90 minutes
Python virtualenv & pip in 90 minutes
 
Making the most of your Test Suite
Making the most of your Test SuiteMaking the most of your Test Suite
Making the most of your Test Suite
 
Christian Strappazzon - Presentazione Python Milano - Codemotion Milano 2017
Christian Strappazzon - Presentazione Python Milano - Codemotion Milano 2017Christian Strappazzon - Presentazione Python Milano - Codemotion Milano 2017
Christian Strappazzon - Presentazione Python Milano - Codemotion Milano 2017
 
Burn down the silos! Helping dev and ops gel on high availability websites
Burn down the silos! Helping dev and ops gel on high availability websitesBurn down the silos! Helping dev and ops gel on high availability websites
Burn down the silos! Helping dev and ops gel on high availability websites
 

Recently uploaded

Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Recently uploaded (20)

Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
API Governance and Monetization - The evolution of API governance
API Governance and Monetization -  The evolution of API governanceAPI Governance and Monetization -  The evolution of API governance
API Governance and Monetization - The evolution of API governance
 
WSO2 Micro Integrator for Enterprise Integration in a Decentralized, Microser...
WSO2 Micro Integrator for Enterprise Integration in a Decentralized, Microser...WSO2 Micro Integrator for Enterprise Integration in a Decentralized, Microser...
WSO2 Micro Integrator for Enterprise Integration in a Decentralized, Microser...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
JohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptxJohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptx
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....
TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....
TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....
 
Quantum Leap in Next-Generation Computing
Quantum Leap in Next-Generation ComputingQuantum Leap in Next-Generation Computing
Quantum Leap in Next-Generation Computing
 
Modernizing Legacy Systems Using Ballerina
Modernizing Legacy Systems Using BallerinaModernizing Legacy Systems Using Ballerina
Modernizing Legacy Systems Using Ballerina
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 

Isolated development in python

  • 3. pip installer $ pip install <package>
  • 4. pip installer $ pip install <package> Download package from pypi.python.org
  • 5. pip installer $ pip install <package> Download package from pypi.python.org $ pip install <directory> $ pip install <tar.gz>
  • 6. pip installer $ pip install <gitrepo>
  • 7. pip installer $ pip install <gitrepo> GREAT!!
  • 8. pip installer $ pip install <gitrepo> GREAT!! $ pip install git+git://github.com/ajdiaz/mole $ pip install git+ssh://github.com/ajdiaz/mole $ pip install git+git://github.com/ajdiaz/mole@840d25 $ pip install git+git://github.com/ajdiaz/mole@devel-branch $ pip install git+git://....@devel-branch#egg=Mole
  • 9. pip installer $ pip freeze
  • 10. pip installer $ pip freeze Fabric==1.5.2 GitPython==0.3.2.RC1 Jinja2==2.6 Pygments==1.6 Sphinx==1.2b1 Create requirements.txt argparse==1.2.1 async==0.6.1 boto==2.7.0 cuisine==0.5.1 distribute==0.6.24 docutils==0.10 gitdb==0.5.4 mico==0 paramiko==1.9.0 pycrypto==2.6 smmap==0.8.2 wsgiref==0.1.2
  • 11. 2. Virtualenv: a jail for python
  • 12. Virtualenv: the python jail $ virtualenv --python=/usr/bin/python2.7 mynewenvironment
  • 13. Virtualenv: the python jail $ virtualenv --python=/usr/bin/python2.7 mynewenvironment OR EVEN BETTER
  • 14. Virtualenv: the python jail $ virtualenv --python=/usr/bin/python2.7 mynewenvironment OR EVEN BETTER $ mkvirtualenv --python=/usr/bin/python2.7 mynewenvironment
  • 15. Virtualenv: the python jail $ virtualenv --python=/usr/bin/python2.7 mynewenvironment OR EVEN BETTER $ mkvirtualenv --python=/usr/bin/python2.7 mynewenvironment mkvirtualenvwrapper
  • 17. Virtualenvwrapper $ mkvirtualenv test New python executable in test/bin/python Installing distribute...................................................................................................................... .......................................................................done. Installing pip...............done. virtualenvwrapper.user_scripts creating /home/ajdiaz/env/test/bin/predeactivate virtualenvwrapper.user_scripts creating /home/ajdiaz/env/test/bin/postdeactivate virtualenvwrapper.user_scripts creating /home/ajdiaz/env/test/bin/preactivate virtualenvwrapper.user_scripts creating /home/ajdiaz/env/test/bin/postactivate virtualenvwrapper.user_scripts creating /home/ajdiaz/env/test/bin/get_env_details (test) $
  • 18. Virtualenvwrapper $ mkvirtualenv test New python executable in test/bin/python Installing distribute...................................................................................................................... .......................................................................done. Installing pip...............done. virtualenvwrapper.user_scripts creating /home/ajdiaz/env/test/bin/predeactivate virtualenvwrapper.user_scripts creating /home/ajdiaz/env/test/bin/postdeactivate virtualenvwrapper.user_scripts creating /home/ajdiaz/env/test/bin/preactivate virtualenvwrapper.user_scripts creating /home/ajdiaz/env/test/bin/postactivate virtualenvwrapper.user_scripts creating /home/ajdiaz/env/test/bin/get_env_details (test) $ which python /home/ajdiaz/env/test/bin/python
  • 19. Virtualenvwrapper $ mkvirtualenv test New python executable in test/bin/python Installing distribute...................................................................................................................... .......................................................................done. Installing pip...............done. virtualenvwrapper.user_scripts creating /home/ajdiaz/env/test/bin/predeactivate virtualenvwrapper.user_scripts creating /home/ajdiaz/env/test/bin/postdeactivate virtualenvwrapper.user_scripts creating /home/ajdiaz/env/test/bin/preactivate virtualenvwrapper.user_scripts creating /home/ajdiaz/env/test/bin/postactivate virtualenvwrapper.user_scripts creating /home/ajdiaz/env/test/bin/get_env_details (test) $ which python /home/ajdiaz/env/test/bin/python yep, these are hooks!
  • 21. Unit testing: nose class A(object): def __init__(self): self.value = "Some Value" def return_true(self): return True save it in a.py def raise_exc(self, val): raise KeyError(val)
  • 22. Unit testing: nose from a import A from nose.tools import assert_equal from nose.tools import assert_not_equal from nose.tools import assert_raises from nose.tools import raises class TestA(object): @classmethod def setup_class(klass): """This method is run once for each class before any tests are run""" @classmethod def teardown_class(klass): """This method is run once for each class _after_ all tests are run""" def setUp(self): """This method is run once before _each_ test method is executed""" def teardown(self): """This method is run once after _each_ test method is executed""" .... continue ....
  • 23. Unit testing: nose def test_init(self): a = A() assert_equal(a.value, "Some Value") assert_not_equal(a.value, "Incorrect Value") def test_return_true(self): a = A() assert_equal(a.return_true(), True) assert_not_equal(a.return_true(), False) def test_raise_exc(self): a = A() assert_raises(KeyError, a.raise_exc, "A value") @raises(KeyError) def test_raise_exc_with_decorator(self): a = A() a.raise_exc("A message") save it in tests/testa.py
  • 24. Unit testing: nose $ nosetests -v tests/
  • 25. Unit testing: nose $ nosetests -v tests/ testa.TestA.test_init ... ok testa.TestA.test_raise_exc ... ok testa.TestA.test_raise_exc_with_decorator ... ok testa.TestA.test_return_true ... ok --------------------------------------------------------- Ran 4 tests in 0.002s OK
  • 26. Unit testing: Bonus: code coverage $ pip install coverage $ nosetests --with-coverage .... Name Stmts Miss Cover Missing ------------------------------------- a 8 0 100% ------------------------------------- Ran 4 tests in 0.006s OK
  • 28. Python eggs: basic setup.py from setuptools import setup setup( name = "example", version = "1.0", description = "An example package", author='Andres J. Diaz' )
  • 29. Python eggs: basic setup.py from setuptools import setup, find_packages setup( name = "example", version = "1.0", description = "An example package", author='Andres J. Diaz', packages=find_packages() )
  • 30. Python eggs: complex setup.py import re from setuptools import setup, find_packages from os import path def parse_requirements(file_name): requirements = [] for line in open(file_name, 'r').read().split('n'): if re.match(r'(s*#)|(s*$)', line): continue if re.match(r's*-es+', line): requirements.append(re.sub(r's*-es+.*#egg=(.*)$', r'1', line)) elif re.match(r's*-fs+', line): pass else: requirements.append(line) return requirements .... continue ....
  • 31. Python eggs: complex setup.py def parse_dependency_links(file_name): dependency_links = [] for line in open(file_name, 'r').read().split('n'): if re.match(r's*-[ef]s+', line): dependency_links.append(re.sub(r's*-[ef]s+', '', line)) return dependency_links def get_file_contents(filename): fd = file(path.join(path.dirname(__file__), filename), "r") content = fd.read() fd.close() return content .... continue ....
  • 32. Python eggs: complex setup.py setup( name = "mico", version = "0.1", description = "A monkey driven cloud management", long_description=get_file_contents("README.rst"), author='Andres J. Diaz', author_email='ajdiaz@connectical.com', url='http://ajdiaz.github.com/mico', packages=find_packages(), install_requires = parse_requirements('requirements.txt'), dependency_links = parse_dependency_links('requirements.txt'), entry_points={ 'console_scripts': [ 'mico = mico.scripts.cmdline:main', ] }, classifiers=[ 'Development Status :: 4 - Beta', 'Intended Audience :: Developers', 'License :: OSI Approved :: GNU General Public License (GPL)', 'Operating System :: OS Independent', 'Programming Language :: Python', ], )
  • 33. Python eggs: complex setup.py setup( name = "mico", version = "0.1", description = "A monkey driven cloud management", long_description=get_file_contents("README.rst"), author='Andres J. Diaz', author_email='ajdiaz@connectical.com', url='http://ajdiaz.github.com/mico', packages=find_packages(), install_requires = parse_requirements('requirements.txt'), dependency_links = parse_dependency_links('requirements.txt'), entry_points={ 'console_scripts': [ 'mico = mico.scripts.cmdline:main', ] }, classifiers=[ 'Development Status :: 4 - Beta', 'Intended Audience :: Developers', 'License :: OSI Approved :: GNU General Public License (GPL)', 'Operating System :: OS Independent', 'Programming Language :: Python', ], )
  • 34. Applauses & questions Not necessarily in that order.