Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

import antigravity

2,679 views

Published on

No matter how much we love writing software, there are times it makes us want to set fire to our keyboards. We'll take a look at virtualenv, pip, and other module-related technologies that make life a more enjoyable experience.

Published in: Technology
  • Be the first to comment

import antigravity

  1. 1. import antigravity Making life more enjoyable with Python
  2. 2. My name is Jeremy Carbaugh
  3. 3. sucks at technology
  4. 4. Python
  5. 5. modules
  6. 6. $ cat markdown.py ... def markdown(text, ...): ... >>> from markdown import markdown >>> markdown(‘# Python!’) u’<h1>Python!</h1>’
  7. 7. congress/__init__.py congress/house.py congress/senate.py >>> import congress >>> congress.senate <module ‘senate’ from ... >>> from congress import senate >>> senate <module ‘senate’ from ...
  8. 8. $ cat congress/house.py def impeach(president): ... >>> from congress.house import impeach >>> if user.party != president.party: >>> impeach(president)
  9. 9. $ cat congress/__init__.py class Bill(object): def __init__(self, chamber, number, title): self.chamber = chamber self.number = number self.title = title >>> from congress import Bill >>> hr45 = Bill(‘House’, 1811, ‘GREEN Act’)
  10. 10. GREEN Act To authorize the President to review and approve oil and gas exploration, development, and production projects under existing Federal oil and gas leases, both onshore and offshore, and to limit administrative and judicial proceedings with respect to such projects, upon finding that such a project complies with all applicable Federal laws, and for other purposes.
  11. 11. sys.path
  12. 12. current directory $PYTHONPATH default paths
  13. 13. >>> import sys >>> for path in sys.path: ... print path /usr/lib/python2.5 /usr/lib/python2.5/plat-linux2 /usr/lib/python2.5/lib-dynload /usr/local/lib/python2.5/site-packages /usr/lib/python2.5/site-packages /var/lib/python-support/python2.5
  14. 14. >>> sys.path.append(‘/path/to/lib’) >>> ‘/path/to/lib’ in sys.path True
  15. 15. distutils
  16. 16. $ cat setup.py from distutils.core import setup from serpente import __version__ setup( name='python-serpente', version=__version__, py_modules=['serpente'], )
  17. 17. $ python setup.py install running install running build ... $ python >>> import serpente >>> serpente.encode(2009) u’MMIX’
  18. 18. $ python setup.py sdist running sdist ... creating python-serpente-0.1 ... creating dist ... $ ls dist python-serpente-0.1.tar.gz
  19. 19. PyPI
  20. 20. $ cat setup.py from distutils.core import setup from serpente import __version__ setup( name='python-serpente', version=__version__, description='Roman numeral encoder and decoder', license='BSD License', author='Jeremy Carbaugh', author_email='jeremy@200ok.net', url='http://github.com/jcarbaugh/python-serpente/', py_modules=['serpente'], classifiers=[ 'Development Status :: 4 - Beta', 'Intended Audience :: Developers', 'License :: OSI Approved :: BSD License', 'Natural Language :: English', 'Operating System :: OS Independent', 'Programming Language :: Python', ], )
  21. 21. $ python setup.py register running register Using PyPI login from ~/.pypirc Server response (200): OK
  22. 22. setuptools distutils
  23. 23. $ easy_install markdown Searching for markdown ... Finished processing dependencies for markdown
  24. 24. pip setuptools distutils
  25. 25. $ pip install markdown ... Successfully installed markdown
  26. 26. $ pip freeze reqs.txt $ cat reqs.txt markdown==1.7 $ pip install -r reqs.txt ... Successfully installed
  27. 27. $ cat reqs.txt markdown==1.7 -e git://.../python-serpente.git#egg=serpente $ pip install -r reqs.txt Requirement already satisfied: markdown==1.7 ... Checking out serpente from git+git://... ... Successfully installed
  28. 28. So what about version conflicts?
  29. 29. virtualenv pip setuptools distutils
  30. 30. $ python virtualenv.py sandbox $ ls sandbox/ bin build include lib src $ ls sandbox/bin/python* sandbox/bin/python sandbox/bin/python2.5
  31. 31. $ pip install -E sandbox/ markdown ... Successfully installed markdown $ cd sandbox/lib/python2.5/site-packages $ ls markdown-1.7-py2.5.egg-info markdown.py python_serpente-0.1-py2.5.egg-info serpente.py
  32. 32. That’s too much typing.
  33. 33. virtualenvwrapper virtualenv pip setuptools distutils
  34. 34. $ mkvirtualenv sandbox (sandbox)$ (sandbox)$ deactivate $ $ workon sandbox (sandbox)$
  35. 35. $ pip install -E sandbox/ markdown $ workon sandbox (sandbox)$ pip install markdown
  36. 36. (sandbox)$ add2virtualenv > /usr/local/src/django-trunk (sandbox)$ cdsitepackages (sandbox)$ cdvirtualenv
  37. 37. (sandbox)$ cat bin/postactivate svn up /usr/local/src/django-trunk (sandbox)$ deactivate $ workon sandbox ... Updated to revision 10844.
  38. 38. let’s wrap this up
  39. 39. $ mkvirtualenv labs (labs)$ svn co http://.../trunk/ sunlightlabs (labs)$ cd sunlightlabs (labs)$ pip install -r reqs.txt (labs)$ mate . (labs)$ ./manage.py runserver
  40. 40. @jcarbaugh github.com/sunlightlabs github.com/jcarbaugh
  41. 41. The End Creative Commons Attribution-Noncommercial-Share Alike 3.0
  42. 42. photo credits nostri-imago sailorganymede zkorb psmith fotopakismo su-lin

×