0
Smoothing Software Project Scripting




                       Kevin Dangoor
                       BlueSkyOnMars.com
   ...
Python is not
          compiled
(actually, it is, but that’s not important right now)
Python projects
certainly do not need
•   Redistributable files to move
    around
•   Deployment to other machines
•   In...
If only there was
  some scripting
language that we
  already knew.
Waitasec. Isn’t
Python a scripting
    language?
Project-related
      scripts need...
•   Command line argument handling
•   Configuration
•   Often work with files
•   S...
Command-line argument handling




 bin/start-server --port 8675309
Configuration



 [messages]
 greeting=Hello

 [thing1]
 who=World
 message=${messages.greeting}, ${who}
Lots of working with files



 import os

 if not os.path.exists(“foo”):
     os.mkdir(“foo”)
 if not os.path.exists(os.pa...
Working with distutils/setuptools




 #!/bin/sh

 sphinx-build (blah blah blah)
 python setup.py sdist upload
Other common tools



 sphinx-build ...

 subprocess.Popen(“svn info”... # and do something with the
 output

 virtualenv....
Do you really want
     separate scripts for
         everything?
•   /usr/local/bin/git                         /usr/loca...
easy_install Paver
paver paverdocs
pavement.py
Why Python build
         files?
•   You already know Python
•   The language rules are well-defined
•   The language rule...
Pavements are almost standard
Python




 from paver.defaults import *
Configuration
   options(
    setup = setup_meta,
    minilib=Bunch(
         extra_files=['doctools', 'virtual']
    ),
 ...
Configuration
   options(
    setup = setup_meta,
    minilib=Bunch(
         extra_files=['doctools', 'virtual']
    ),
 ...
Configuration
   options(
    setup = setup_meta,
    minilib=Bunch(
         extra_files=['doctools', 'virtual']
    ),
 ...
Configuration
   options(
    setup = setup_meta,
    minilib=Bunch(
         extra_files=['doctools', 'virtual']
    ),
 ...
Configuration
   options(
    setup = setup_meta,
    minilib=Bunch(
         extra_files=['doctools', 'virtual']
    ),
 ...
Configuration
   options(
    setup = setup_meta,
    minilib=Bunch(
         extra_files=['doctools', 'virtual']
    ),
 ...
Configuration
   options(
    setup = setup_meta,
    minilib=Bunch(
         extra_files=['doctools', 'virtual']
    ),
 ...
Dynamic config values




 >>> from paver.defaults import *
 >>> import time
 >>> options(current=lambda: time.time())
 >>...
Namespace searching



 >>> options(
 ...     setup=Bunch(version=quot;1.0quot;),
 ...     sphinx=Bunch(builddir=quot;docb...
Namespace searching (continued)


 >>> options(
 ...     setup=Bunch(version=quot;1.0quot;),
 ...     sphinx=Bunch(builddi...
Namespace searching (continued)


 >>> options(
 ...     setup=Bunch(version=quot;1.0quot;),
 ...     sphinx=Bunch(builddi...
Namespace searching (continued)


 >>> options(
 ...     setup=Bunch(version=quot;1.0quot;),
 ...     sphinx=Bunch(builddi...
Configuration is
     still standard
         Python
•   You can treat options like a normal,
    nested dictionary
•   Th...
Tasks



 @task
 def clean():
     quot;quot;quot;Cleans up this paver directory. Removes the virtualenv
 traces and
     ...
Tasks



 @task
 def clean():
     quot;quot;quot;Cleans up this paver directory. Removes the virtualenv
 traces and
     ...
Tasks



 @task
 def clean():
     quot;quot;quot;Cleans up this paver directory. Removes the virtualenv
 traces and
     ...
Tasks



 @task
 def clean():
     quot;quot;quot;Cleans up this paver directory. Removes the virtualenv
 traces and
     ...
Tasks



 @task
 def clean():
     quot;quot;quot;Cleans up this paver directory. Removes the virtualenv
 traces and
     ...
paver help
 $ paver help
 ---> help
 Paver 0.8.1

 Usage: paver [global options] [option.name=value] task [task
 options] ...
paver help
 $ paver help
 ---> help
 Paver 0.8.1

 Usage: paver [global options] [option.name=value] task [task
 options] ...
paver help
 $ paver help
 ---> help
 Paver 0.8.1

 Usage: paver [global options] [option.name=value] task [task
 options] ...
paver help
 $ paver help
 ---> help
 Paver 0.8.1

 Usage: paver [global options] [option.name=value] task [task
 options] ...
paver help
 $ paver help
 ---> help
 Paver 0.8.1

 Usage: paver [global options] [option.name=value] task [task
 options] ...
paver help tasks
 Tasks defined in and imported by your pavement:
   bootstrap                - Build a virtualenv bootstr...
paver help <taskname>

 Details for minilib:
 Create a Paver mini library that contains enough for a simple
      pavement...
@needs



 @task
 @needs(quot;uncogquot;)
 def commit():
     quot;quot;quot;Removes the generated code from the docs and ...
@needs



 @task
 @needs(quot;uncogquot;)
 def commit():
     quot;quot;quot;Removes the generated code from the docs and ...
@needs



 @task
 @needs(quot;uncogquot;)
 def commit():
     quot;quot;quot;Removes the generated code from the docs and ...
call_task




 call_task(‘commit’)
@cmdopts



 @task
 @cmdopts([(quot;username=quot;, quot;uquot;, quot;Username for remote serverquot;),
           (quot;s...
paver <taskname>




 $ paver generate_setup minilib
 ---> generate_setup
 Write setup.py
 ---> minilib
 Generate paver-mi...
Paver and Distutils/
    Setuptools
“Using the Distutils is quite
  simple, both for module
 developers and for users/
 administrators installing
    third-pa...
python setup.py
    install
Paver extends
  Distutils
paver install
setup.py example




   from distutils.core import setup
setup(name='foo',
       version='1.0',
       py_modules=['foo']...
setup.py example




   from distutils.core import setup
setup(name='foo',
       version='1.0',
       py_modules=['foo']...
setup.py example




   from distutils.core import setup
setup(name='foo',
       version='1.0',
       py_modules=['foo']...
setup.py example




   from distutils.core import setup
setup(name='foo',
       version='1.0',
       py_modules=['foo']...
setup.py example




   from distutils.core import setup
setup(name='foo',
       version='1.0',
       py_modules=['foo']...
Upgrading to Paver



    options(
     setup = Bunch(name='foo',
        version='1.0',
        py_modules=['foo'],
     ...
Keeping it simple for users




 $ paver generate_setup minilib
 ---> generate_setup
 Write setup.py
 ---> minilib
 Genera...
Generated setup.py



  import os
if os.path.exists(quot;paver-minilib.zipquot;):
    import sys
    sys.path.insert(0, qu...
The Paver Standard Library
(is actually newer and less musty)
The Paver Standard
      Library
•   Runtime helpers (paver.runtime)
•   Distutils integration (paver.setuputils)
•   File...
paver.runtime



 # display text if verbose is set
 debug(“Hi there. Feeling chatty today?”)

 # display text if quiet is ...
paver.runtime



 # display text if verbose is set
 debug(“Hi there. Feeling chatty today?”)

 # display text if quiet is ...
paver.runtime



 # display text if verbose is set
 debug(“Hi there. Feeling chatty today?”)

 # display text if quiet is ...
paver.runtime



 # display text if verbose is set
 debug(“Hi there. Feeling chatty today?”)

 # display text if quiet is ...
paver.runtime



 # display text if verbose is set
 debug(“Hi there. Feeling chatty today?”)

 # display text if quiet is ...
paver.runtime



 # display text if verbose is set
 debug(“Hi there. Feeling chatty today?”)

 # display text if quiet is ...
paver.runtime



 # display text if verbose is set
 debug(“Hi there. Feeling chatty today?”)

 # display text if quiet is ...
paver.runtime (continued)



 # run a command, as long as dry-run is off
 # capture the output into myval
 myval = sh(“cat...
paver.runtime (continued)



 # run a command, as long as dry-run is off
 # capture the output into myval
 myval = sh(“cat...
paver.runtime (continued)



 # run a command, as long as dry-run is off
 # capture the output into myval
 myval = sh(“cat...
paver.runtime (continued)



 # run a command, as long as dry-run is off
 # capture the output into myval
 myval = sh(“cat...
paver.runtime (continued)



 # run a command, as long as dry-run is off
 # capture the output into myval
 myval = sh(“cat...
paver.setuputils




 options.setup.package_data =
    setuputils.find_package_data(quot;paverquot;, package=quot;paverquo...
paver.path
•   Jason Orendorff’s path.py module
    (also available separately)
•   It’s a subclass of string!
•   Fun use...
paver.path examples




   p = path(quot;docsquot;)
tmpdir = p / quot;tmpquot;
tmpdir.mkdir()
fn = tmpdir / quot;myfile.tx...
paver.path examples




   p = path(quot;docsquot;)
tmpdir = p / quot;tmpquot;
tmpdir.mkdir()
fn = tmpdir / quot;myfile.tx...
paver.path examples




   p = path(quot;docsquot;)
tmpdir = p / quot;tmpquot;
tmpdir.mkdir()
fn = tmpdir / quot;myfile.tx...
paver.path examples




   p = path(quot;docsquot;)
tmpdir = p / quot;tmpquot;
tmpdir.mkdir()
fn = tmpdir / quot;myfile.tx...
paver.path examples




   p = path(quot;docsquot;)
tmpdir = p / quot;tmpquot;
tmpdir.mkdir()
fn = tmpdir / quot;myfile.tx...
paver.path examples




   p = path(quot;docsquot;)
tmpdir = p / quot;tmpquot;
tmpdir.mkdir()
fn = tmpdir / quot;myfile.tx...
paver.path examples




   p = path(quot;docsquot;)
tmpdir = p / quot;tmpquot;
tmpdir.mkdir()
fn = tmpdir / quot;myfile.tx...
paver.doctools




 # add this to use
 import paver.doctools
paver.doctools – Sphinx

   paver.doctools.html()¶
Build HTML documentation using Sphinx. This uses the following options ...
paver.doctools –
Cog & SectionedFile
•   Solutions to common problems of
    creating high-quality docs
•   Ideally, your ...
paver.doctools sample code



  # mysample.py

# [[[section mysample]]]
def sample_func():
    print quot;To sample, or no...
paver.doctools in docs




 And then when you want to print the sample string, you just
 call::

     # [[[cog include(“co...
paver.doctools in docs (2)



 And then when you want to print the sample string, you just
 call::

     # [[[cog include(...
paver.doctools uncog before
commit



 @task
 @needs(quot;uncogquot;)
 def commit():
     quot;quot;quot;Removes the gener...
paver.svn

  paver.svn.checkout(url, dest, revision='')
Checks out the specified URL to the given destination.

paver.svn.c...
paver.ssh




 paver.ssh.scp(source, dest)
     Copy the source file to the destination.
paver.virtual

   paver.virtual.bootstrap()
Creates a virtualenv bootstrap script. The script will create a bootstrap scri...
paver.misctasks


   paver.misctasks.generate_setup()

paver.misctasks.help()

paver.misctasks.minilib()
Options:
extra_fil...
Pulling it all
         together
•   write functions with the @task
    decorator.
•   Just plain old Python with lots of
...
Remember this?




 #!/bin/sh

 sphinx-build (blah blah blah)
 python setup.py sdist upload
Paver needs to do that too



 @task
 @needs(['html', quot;minilibquot;, quot;generate_setupquot;,
 “setuptools.command.sd...
But wait, it does more!


 @task
 @needs(['cog', 'paver.doctools.html'])
 def html():
     quot;quot;quot;Build Paver's do...
Changes coming to
      Paver
•   The little bit of magic goes away
•   Support for CloudControl
•   Ability to run sub-bu...
Credits
•   Thanks to SitePen for supporting Paver
•   Bumpy road
    http://flickr.com/photos/ilya/442034/sizes/o/
•   Sm...
http://
www.blueskyonmars.
  com/projects/
      paver/
Paver For PyWorks 2008
Paver For PyWorks 2008
Paver For PyWorks 2008
Paver For PyWorks 2008
Upcoming SlideShare
Loading in...5
×

Paver For PyWorks 2008

782

Published on

My presentation on Paver given at PyWorks php|works 2008 in Atlanta, GA.

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
782
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
5
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Transcript of "Paver For PyWorks 2008"

  1. 1. Smoothing Software Project Scripting Kevin Dangoor BlueSkyOnMars.com php|works PyWorks 2008
  2. 2. Python is not compiled (actually, it is, but that’s not important right now)
  3. 3. Python projects certainly do not need • Redistributable files to move around • Deployment to other machines • Interaction with source control systems • Documentation that’s built from the source code • Documentation that’s built from a format other than its final display format
  4. 4. If only there was some scripting language that we already knew.
  5. 5. Waitasec. Isn’t Python a scripting language?
  6. 6. Project-related scripts need... • Command line argument handling • Configuration • Often work with files • Sometimes need to use distutils/ setuptools, but wish they could do a little more • Need to work with other common tools (Sphinx, svn, virtualenv)
  7. 7. Command-line argument handling bin/start-server --port 8675309
  8. 8. Configuration [messages] greeting=Hello [thing1] who=World message=${messages.greeting}, ${who}
  9. 9. Lots of working with files import os if not os.path.exists(“foo”): os.mkdir(“foo”) if not os.path.exists(os.path.join(“foo, “bar”)): open(os.path.join(“foo”, “bar”), “w”).write(“Hi”)
  10. 10. Working with distutils/setuptools #!/bin/sh sphinx-build (blah blah blah) python setup.py sdist upload
  11. 11. Other common tools sphinx-build ... subprocess.Popen(“svn info”... # and do something with the output virtualenv.create_bootstrap_script(“# more code”)
  12. 12. Do you really want separate scripts for everything? • /usr/local/bin/git /usr/local/bin/git-merge-resolve • /usr/local/bin/git-fast-import /usr/local/bin/git-runstatus • /usr/local/bin/git-add /usr/local/bin/git-merge-stupid • /usr/local/bin/git-fetch /usr/local/bin/git-send-email • /usr/local/bin/git-add--interactive /usr/local/bin/git-merge-subtree • /usr/local/bin/git-fetch--tool /usr/local/bin/git-send-pack • /usr/local/bin/git-am /usr/local/bin/git-merge-tree • /usr/local/bin/git-fetch-pack /usr/local/bin/git-sh-setup • /usr/local/bin/git-annotate /usr/local/bin/git-mergetool • /usr/local/bin/git-filter-branch /usr/local/bin/git-shell • /usr/local/bin/git-apply /usr/local/bin/git-mktag • /usr/local/bin/git-fmt-merge-msg /usr/local/bin/git-shortlog • /usr/local/bin/git-archimport /usr/local/bin/git-mktree • /usr/local/bin/git-for-each-ref /usr/local/bin/git-show • /usr/local/bin/git-archive /usr/local/bin/git-mv • /usr/local/bin/git-format-patch /usr/local/bin/git-show-branch • /usr/local/bin/git-bisect /usr/local/bin/git-name-rev • /usr/local/bin/git-fsck /usr/local/bin/git-show-index • /usr/local/bin/git-blame /usr/local/bin/git-pack-objects • /usr/local/bin/git-fsck-objects /usr/local/bin/git-show-ref • /usr/local/bin/git-branch /usr/local/bin/git-pack-redundant • /usr/local/bin/git-gc /usr/local/bin/git-ssh-fetch • /usr/local/bin/git-bundle /usr/local/bin/git-pack-refs • /usr/local/bin/git-get-tar-commit-id /usr/local/bin/git-ssh-pull • /usr/local/bin/git-cat-file /usr/local/bin/git-parse-remote • /usr/local/bin/git-grep /usr/local/bin/git-ssh-push • /usr/local/bin/git-check-attr /usr/local/bin/git-patch-id • /usr/local/bin/git-gui /usr/local/bin/git-ssh-upload • /usr/local/bin/git-check-ref-format /usr/local/bin/git-peek-remote • /usr/local/bin/git-hash-object /usr/local/bin/git-stash • /usr/local/bin/git-checkout /usr/local/bin/git-prune • /usr/local/bin/git-http-fetch /usr/local/bin/git-status • /usr/local/bin/git-checkout-index /usr/local/bin/git-prune-packed • /usr/local/bin/git-imap-send /usr/local/bin/git-stripspace • /usr/local/bin/git-cherry /usr/local/bin/git-pull • /usr/local/bin/git-index-pack /usr/local/bin/git-submodule • /usr/local/bin/git-cherry-pick /usr/local/bin/git-push • /usr/local/bin/git-init /usr/local/bin/git-svn • /usr/local/bin/git-citool /usr/local/bin/git-quiltimport • /usr/local/bin/git-init-db /usr/local/bin/git-svnimport • /usr/local/bin/git-clean /usr/local/bin/git-read-tree • /usr/local/bin/git-instaweb /usr/local/bin/git-symbolic-ref • /usr/local/bin/git-clone /usr/local/bin/git-rebase • /usr/local/bin/git-local-fetch /usr/local/bin/git-tag • /usr/local/bin/git-commit /usr/local/bin/git-rebase-- • /usr/local/bin/git-log /usr/local/bin/git-tar-tree interactive • /usr/local/bin/git-lost-found /usr/local/bin/git-unpack-file • /usr/local/bin/git-commit-tree /usr/local/bin/git-receive-pack • /usr/local/bin/git-ls-files /usr/local/bin/git-unpack-objects • /usr/local/bin/git-config /usr/local/bin/git-reflog • /usr/local/bin/git-ls-remote /usr/local/bin/git-update-index • /usr/local/bin/git-convert-objects /usr/local/bin/git-relink • /usr/local/bin/git-ls-tree /usr/local/bin/git-update-ref • /usr/local/bin/git-count-objects /usr/local/bin/git-remote • /usr/local/bin/git-mailinfo /usr/local/bin/git-update-server-info • /usr/local/bin/git-cvsexportcommit /usr/local/bin/git-repack • /usr/local/bin/git-mailsplit /usr/local/bin/git-upload-archive • /usr/local/bin/git-cvsimport /usr/local/bin/git-repo-config • /usr/local/bin/git-merge /usr/local/bin/git-upload-pack • /usr/local/bin/git-cvsserver /usr/local/bin/git-request-pull • /usr/local/bin/git-merge-base /usr/local/bin/git-var • /usr/local/bin/git-daemon /usr/local/bin/git-rerere • /usr/local/bin/git-merge-file /usr/local/bin/git-verify-pack • /usr/local/bin/git-describe /usr/local/bin/git-reset • /usr/local/bin/git-merge-index /usr/local/bin/git-verify-tag • /usr/local/bin/git-diff /usr/local/bin/git-rev-list • /usr/local/bin/git-merge-octopus /usr/local/bin/git-whatchanged • /usr/local/bin/git-diff-files /usr/local/bin/git-rev-parse • /usr/local/bin/git-merge-one-file /usr/local/bin/git-write-tree • /usr/local/bin/git-diff-index /usr/local/bin/git-revert • /usr/local/bin/git-merge-ours /usr/local/bin/gitk • /usr/local/bin/git-diff-tree /usr/local/bin/git-rm • /usr/local/bin/git-merge-recursive
  13. 13. easy_install Paver
  14. 14. paver paverdocs
  15. 15. pavement.py
  16. 16. Why Python build files? • You already know Python • The language rules are well-defined • The language rules are well- documented • Python is powerful, so you’ll never be left hanging or need an escape hatch
  17. 17. Pavements are almost standard Python from paver.defaults import *
  18. 18. Configuration options( setup = setup_meta, minilib=Bunch( extra_files=['doctools', 'virtual'] ), sphinx=Bunch( builddir=quot;buildquot;, sourcedir=quot;sourcequot; ), virtualenv=Bunch( packages_to_install=[quot;nosequot;, quot;sphinxquot;, quot;docutilsquot;, quot;virtualenvquot;], install_paver=False, script_name='bootstrap.py', paver_command_line=None ) )
  19. 19. Configuration options( setup = setup_meta, minilib=Bunch( extra_files=['doctools', 'virtual'] ), sphinx=Bunch( builddir=quot;buildquot;, sourcedir=quot;sourcequot; ), virtualenv=Bunch( packages_to_install=[quot;nosequot;, quot;sphinxquot;, quot;docutilsquot;, quot;virtualenvquot;], install_paver=False, script_name='bootstrap.py', paver_command_line=None ) )
  20. 20. Configuration options( setup = setup_meta, minilib=Bunch( extra_files=['doctools', 'virtual'] ), sphinx=Bunch( builddir=quot;buildquot;, sourcedir=quot;sourcequot; ), virtualenv=Bunch( packages_to_install=[quot;nosequot;, quot;sphinxquot;, quot;docutilsquot;, quot;virtualenvquot;], install_paver=False, script_name='bootstrap.py', paver_command_line=None ) )
  21. 21. Configuration options( setup = setup_meta, minilib=Bunch( extra_files=['doctools', 'virtual'] ), sphinx=Bunch( builddir=quot;buildquot;, sourcedir=quot;sourcequot; ), virtualenv=Bunch( packages_to_install=[quot;nosequot;, quot;sphinxquot;, quot;docutilsquot;, quot;virtualenvquot;], install_paver=False, script_name='bootstrap.py', paver_command_line=None ) )
  22. 22. Configuration options( setup = setup_meta, minilib=Bunch( extra_files=['doctools', 'virtual'] ), sphinx=Bunch( builddir=quot;buildquot;, sourcedir=quot;sourcequot; ), virtualenv=Bunch( packages_to_install=[quot;nosequot;, quot;sphinxquot;, quot;docutilsquot;, quot;virtualenvquot;], install_paver=False, script_name='bootstrap.py', paver_command_line=None ) )
  23. 23. Configuration options( setup = setup_meta, minilib=Bunch( extra_files=['doctools', 'virtual'] ), sphinx=Bunch( builddir=quot;buildquot;, sourcedir=quot;sourcequot; ), virtualenv=Bunch( packages_to_install=[quot;nosequot;, quot;sphinxquot;, quot;docutilsquot;, quot;virtualenvquot;], install_paver=False, script_name='bootstrap.py', paver_command_line=None ) )
  24. 24. Configuration options( setup = setup_meta, minilib=Bunch( extra_files=['doctools', 'virtual'] ), sphinx=Bunch( builddir=quot;buildquot;, sourcedir=quot;sourcequot; ), virtualenv=Bunch( packages_to_install=[quot;nosequot;, quot;sphinxquot;, quot;docutilsquot;, quot;virtualenvquot;], install_paver=False, script_name='bootstrap.py', paver_command_line=None ) )
  25. 25. Dynamic config values >>> from paver.defaults import * >>> import time >>> options(current=lambda: time.time()) >>> options.current 1216726815.0027969
  26. 26. Namespace searching >>> options( ... setup=Bunch(version=quot;1.0quot;), ... sphinx=Bunch(builddir=quot;docbuildquot;) ... ) >>> options.version '1.0'
  27. 27. Namespace searching (continued) >>> options( ... setup=Bunch(version=quot;1.0quot;), ... sphinx=Bunch(builddir=quot;docbuildquot;) ... ) >>> options.order('sphinx') >>> options.version Traceback (most recent call last): File quot;<stdin>quot;, line 1, in <module> File quot;/Users/admin/projects/paver/paver/runtime.pyquot;, line 31, in __getattr__ raise AttributeError(name) AttributeError: version
  28. 28. Namespace searching (continued) >>> options( ... setup=Bunch(version=quot;1.0quot;), ... sphinx=Bunch(builddir=quot;docbuildquot;) ... ) >>> options.order('sphinx') >>> options.version Traceback (most recent call last): File quot;<stdin>quot;, line 1, in <module> File quot;/Users/admin/projects/paver/paver/runtime.pyquot;, line 31, in __getattr__ raise AttributeError(name) AttributeError: version
  29. 29. Namespace searching (continued) >>> options( ... setup=Bunch(version=quot;1.0quot;), ... sphinx=Bunch(builddir=quot;docbuildquot;) ... ) >>> options.order('sphinx') >>> options.version Traceback (most recent call last): File quot;<stdin>quot;, line 1, in <module> File quot;/Users/admin/projects/paver/paver/runtime.pyquot;, line 31, in __getattr__ raise AttributeError(name) AttributeError: version
  30. 30. Configuration is still standard Python • You can treat options like a normal, nested dictionary • The only unusual thing would be that callables are called.
  31. 31. Tasks @task def clean(): quot;quot;quot;Cleans up this paver directory. Removes the virtualenv traces and the build directory.quot;quot;quot; pass
  32. 32. Tasks @task def clean(): quot;quot;quot;Cleans up this paver directory. Removes the virtualenv traces and the build directory.quot;quot;quot; pass
  33. 33. Tasks @task def clean(): quot;quot;quot;Cleans up this paver directory. Removes the virtualenv traces and the build directory.quot;quot;quot; pass
  34. 34. Tasks @task def clean(): quot;quot;quot;Cleans up this paver directory. Removes the virtualenv traces and the build directory.quot;quot;quot; pass
  35. 35. Tasks @task def clean(): quot;quot;quot;Cleans up this paver directory. Removes the virtualenv traces and the build directory.quot;quot;quot; pass
  36. 36. paver help $ paver help ---> help Paver 0.8.1 Usage: paver [global options] [option.name=value] task [task options] [task...] Run 'paver help [section]' to see the following sections of info: options global command line options setup available distutils/setuptools tasks tasks all tasks that have been imported by your pavement 'paver help taskname' will display details for a task. Tasks defined in your pavement: bootstrap - Build a virtualenv bootstrap for developing
  37. 37. paver help $ paver help ---> help Paver 0.8.1 Usage: paver [global options] [option.name=value] task [task options] [task...] Run 'paver help [section]' to see the following sections of info: options global command line options setup available distutils/setuptools tasks tasks all tasks that have been imported by your pavement 'paver help taskname' will display details for a task. Tasks defined in your pavement: bootstrap - Build a virtualenv bootstrap for developing
  38. 38. paver help $ paver help ---> help Paver 0.8.1 Usage: paver [global options] [option.name=value] task [task options] [task...] Run 'paver help [section]' to see the following sections of info: options global command line options setup available distutils/setuptools tasks tasks all tasks that have been imported by your pavement 'paver help taskname' will display details for a task. Tasks defined in your pavement: bootstrap - Build a virtualenv bootstrap for developing
  39. 39. paver help $ paver help ---> help Paver 0.8.1 Usage: paver [global options] [option.name=value] task [task options] [task...] Run 'paver help [section]' to see the following sections of info: options global command line options setup available distutils/setuptools tasks tasks all tasks that have been imported by your pavement 'paver help taskname' will display details for a task. Tasks defined in your pavement: bootstrap - Build a virtualenv bootstrap for developing
  40. 40. paver help $ paver help ---> help Paver 0.8.1 Usage: paver [global options] [option.name=value] task [task options] [task...] Run 'paver help [section]' to see the following sections of info: options global command line options setup available distutils/setuptools tasks tasks all tasks that have been imported by your pavement 'paver help taskname' will display details for a task. Tasks defined in your pavement: bootstrap - Build a virtualenv bootstrap for developing
  41. 41. paver help tasks Tasks defined in and imported by your pavement: bootstrap - Build a virtualenv bootstrap for developing paver clean - Cleans up this paver directory cog - Runs the cog code generator against the files matching your specification commit - Removes the generated code from the docs and then commits to bzr deploy - Copy the Paver website up doc_clean - Clean (delete) the built docs generate_setup - Generates a setup help - Displays the list of commands and the details html - Build Paver's documentation and install it into paver/docs minilib - Create a Paver mini library that contains enough for a simple
  42. 42. paver help <taskname> Details for minilib: Create a Paver mini library that contains enough for a simple pavement.py to be installed using a generated setup.py. This is a good temporary measure until more people have deployed paver. The output file is 'paver-minilib.zip' in the current directory. Options: extra_files list of other paver modules to include (don't include the .py extension)
  43. 43. @needs @task @needs(quot;uncogquot;) def commit(): quot;quot;quot;Removes the generated code from the docs and then commits to bzr.quot;quot;quot; pass
  44. 44. @needs @task @needs(quot;uncogquot;) def commit(): quot;quot;quot;Removes the generated code from the docs and then commits to bzr.quot;quot;quot; pass
  45. 45. @needs @task @needs(quot;uncogquot;) def commit(): quot;quot;quot;Removes the generated code from the docs and then commits to bzr.quot;quot;quot; pass
  46. 46. call_task call_task(‘commit’)
  47. 47. @cmdopts @task @cmdopts([(quot;username=quot;, quot;uquot;, quot;Username for remote serverquot;), (quot;server=quot;, quot;squot;, quot;Server to deploy toquot;)]) def deploy(): quot;quot;quot;Copy the Paver website up.quot;quot;quot; pass
  48. 48. paver <taskname> $ paver generate_setup minilib ---> generate_setup Write setup.py ---> minilib Generate paver-minilib.zip
  49. 49. Paver and Distutils/ Setuptools
  50. 50. “Using the Distutils is quite simple, both for module developers and for users/ administrators installing third-party modules.” – Distributing Python Modules, section 1.1
  51. 51. python setup.py install
  52. 52. Paver extends Distutils
  53. 53. paver install
  54. 54. setup.py example from distutils.core import setup setup(name='foo', version='1.0', py_modules=['foo'], )
  55. 55. setup.py example from distutils.core import setup setup(name='foo', version='1.0', py_modules=['foo'], )
  56. 56. setup.py example from distutils.core import setup setup(name='foo', version='1.0', py_modules=['foo'], )
  57. 57. setup.py example from distutils.core import setup setup(name='foo', version='1.0', py_modules=['foo'], )
  58. 58. setup.py example from distutils.core import setup setup(name='foo', version='1.0', py_modules=['foo'], )
  59. 59. Upgrading to Paver options( setup = Bunch(name='foo', version='1.0', py_modules=['foo'], ) )
  60. 60. Keeping it simple for users $ paver generate_setup minilib ---> generate_setup Write setup.py ---> minilib Generate paver-minilib.zip
  61. 61. Generated setup.py import os if os.path.exists(quot;paver-minilib.zipquot;): import sys sys.path.insert(0, quot;paver-minilib.zipquot;) import paver.command paver.command.main()
  62. 62. The Paver Standard Library (is actually newer and less musty)
  63. 63. The Paver Standard Library • Runtime helpers (paver.runtime) • Distutils integration (paver.setuputils) • File handling (paver.path) • Documentation tools (paver.doctools) • Subversion (paver.svn) • SSH (paver.ssh) • Virtualenv (paver.virtual) • Miscellaneous Tasks (paver.misctasks)
  64. 64. paver.runtime # display text if verbose is set debug(“Hi there. Feeling chatty today?”) # display text if quiet is not set info(“Glad we don’t have to keep quiet”) # display text regardless of setting error(“HA! I’M SHOUTING AND YOU CAN’T STOP ME!”)
  65. 65. paver.runtime # display text if verbose is set debug(“Hi there. Feeling chatty today?”) # display text if quiet is not set info(“Glad we don’t have to keep quiet”) # display text regardless of setting error(“HA! I’M SHOUTING AND YOU CAN’T STOP ME!”)
  66. 66. paver.runtime # display text if verbose is set debug(“Hi there. Feeling chatty today?”) # display text if quiet is not set info(“Glad we don’t have to keep quiet”) # display text regardless of setting error(“HA! I’M SHOUTING AND YOU CAN’T STOP ME!”)
  67. 67. paver.runtime # display text if verbose is set debug(“Hi there. Feeling chatty today?”) # display text if quiet is not set info(“Glad we don’t have to keep quiet”) # display text regardless of setting error(“HA! I’M SHOUTING AND YOU CAN’T STOP ME!”)
  68. 68. paver.runtime # display text if verbose is set debug(“Hi there. Feeling chatty today?”) # display text if quiet is not set info(“Glad we don’t have to keep quiet”) # display text regardless of setting error(“HA! I’M SHOUTING AND YOU CAN’T STOP ME!”)
  69. 69. paver.runtime # display text if verbose is set debug(“Hi there. Feeling chatty today?”) # display text if quiet is not set info(“Glad we don’t have to keep quiet”) # display text regardless of setting error(“HA! I’M SHOUTING AND YOU CAN’T STOP ME!”)
  70. 70. paver.runtime # display text if verbose is set debug(“Hi there. Feeling chatty today?”) # display text if quiet is not set info(“Glad we don’t have to keep quiet”) # display text regardless of setting error(“HA! I’M SHOUTING AND YOU CAN’T STOP ME!”)
  71. 71. paver.runtime (continued) # run a command, as long as dry-run is off # capture the output into myval myval = sh(“cat /tmp/foo”, capture=True) # run a function (delete_all(‘/’) to be exact). # if dry-run is set, then # just print the message instead dry(“Delete everything”, delete_all, ‘/’)
  72. 72. paver.runtime (continued) # run a command, as long as dry-run is off # capture the output into myval myval = sh(“cat /tmp/foo”, capture=True) # run a function (delete_all(‘/’) to be exact). # if dry-run is set, then # just print the message instead dry(“Delete everything”, delete_all, ‘/’)
  73. 73. paver.runtime (continued) # run a command, as long as dry-run is off # capture the output into myval myval = sh(“cat /tmp/foo”, capture=True) # run a function (delete_all(‘/’) to be exact). # if dry-run is set, then # just print the message instead dry(“Delete everything”, delete_all, ‘/’)
  74. 74. paver.runtime (continued) # run a command, as long as dry-run is off # capture the output into myval myval = sh(“cat /tmp/foo”, capture=True) # run a function (delete_all(‘/’) to be exact). # if dry-run is set, then # just print the message instead dry(“Delete everything”, delete_all, ‘/’)
  75. 75. paver.runtime (continued) # run a command, as long as dry-run is off # capture the output into myval myval = sh(“cat /tmp/foo”, capture=True) # run a function (delete_all(‘/’) to be exact). # if dry-run is set, then # just print the message instead dry(“Delete everything”, delete_all, ‘/’)
  76. 76. paver.setuputils options.setup.package_data = setuputils.find_package_data(quot;paverquot;, package=quot;paverquot;, only_in_packages=False)
  77. 77. paver.path • Jason Orendorff’s path.py module (also available separately) • It’s a subclass of string! • Fun use of operator overloading • Lots of great methods • Makes working with files/directories fun and easy
  78. 78. paver.path examples p = path(quot;docsquot;) tmpdir = p / quot;tmpquot; tmpdir.mkdir() fn = tmpdir / quot;myfile.txtquot; fn.write_text(quot;Hi there!quot;)
  79. 79. paver.path examples p = path(quot;docsquot;) tmpdir = p / quot;tmpquot; tmpdir.mkdir() fn = tmpdir / quot;myfile.txtquot; fn.write_text(quot;Hi there!quot;)
  80. 80. paver.path examples p = path(quot;docsquot;) tmpdir = p / quot;tmpquot; tmpdir.mkdir() fn = tmpdir / quot;myfile.txtquot; fn.write_text(quot;Hi there!quot;)
  81. 81. paver.path examples p = path(quot;docsquot;) tmpdir = p / quot;tmpquot; tmpdir.mkdir() fn = tmpdir / quot;myfile.txtquot; fn.write_text(quot;Hi there!quot;)
  82. 82. paver.path examples p = path(quot;docsquot;) tmpdir = p / quot;tmpquot; tmpdir.mkdir() fn = tmpdir / quot;myfile.txtquot; fn.write_text(quot;Hi there!quot;)
  83. 83. paver.path examples p = path(quot;docsquot;) tmpdir = p / quot;tmpquot; tmpdir.mkdir() fn = tmpdir / quot;myfile.txtquot; fn.write_text(quot;Hi there!quot;)
  84. 84. paver.path examples p = path(quot;docsquot;) tmpdir = p / quot;tmpquot; tmpdir.mkdir() fn = tmpdir / quot;myfile.txtquot; fn.write_text(quot;Hi there!quot;)
  85. 85. paver.doctools # add this to use import paver.doctools
  86. 86. paver.doctools – Sphinx paver.doctools.html()¶ Build HTML documentation using Sphinx. This uses the following options in a “sphinx” section of the options. docroot the root under which Sphinx will be working. Default: docs builddir directory under the docroot where the resulting files are put. default: build sourcedir directory under the docroot for the source files default: (empty string) paver.doctools.doc_clean()¶ Clean (delete) the built docs. Specifically, this deletes the build directory under the docroot. See the html task for the options list.
  87. 87. paver.doctools – Cog & SectionedFile • Solutions to common problems of creating high-quality docs • Ideally, your code samples will be in convenient runnable code files and have unit tests. • But you also want nice, minimal code samples in your text as you’re writing.
  88. 88. paver.doctools sample code # mysample.py # [[[section mysample]]] def sample_func(): print quot;To sample, or not to sample?quot; # [[[endsection]]]
  89. 89. paver.doctools in docs And then when you want to print the sample string, you just call:: # [[[cog include(“code/mysample.py”, “mysample”)]]] # [[[end]]]
  90. 90. paver.doctools in docs (2) And then when you want to print the sample string, you just call:: # [[[cog include(“code/mysample.py”, “mysample”)]]] def sample_func(): print quot;To sample, or not to sample?quot; # [[[end]]]
  91. 91. paver.doctools uncog before commit @task @needs(quot;uncogquot;) def commit(): quot;quot;quot;Removes the generated code from the docs and then commits to bzr.quot;quot;quot; sh(quot;bzr commitquot;)
  92. 92. paver.svn paver.svn.checkout(url, dest, revision='') Checks out the specified URL to the given destination. paver.svn.checkup(url, dest, revision='') Does a checkout or update, depending on whether the destination exists and is up to date (if a revision is passed in). Returns true if a checkout or update was performed. False otherwise. paver.svn.info(path='') Retrieves the svn info for the path and returns a dictionary of the values. Names are normalized to lower case with spaces converted to underscores. paver.svn.update(path='', revision='') Run an svn update on the given path. Example at: https://projects.sitepen.com/toolbox/svn/trunk/pavement.py
  93. 93. paver.ssh paver.ssh.scp(source, dest) Copy the source file to the destination.
  94. 94. paver.virtual paver.virtual.bootstrap() Creates a virtualenv bootstrap script. The script will create a bootstrap script that populates a virtualenv in the current directory. The environment will have paver, the packages of your choosing and will run the paver command of your choice. This task looks in the virtualenv options for: script_name name of the generated script packages_to_install packages to install with easy_install. The version of paver that you are using is included automatically. This should be a list of strings. paver_command_line run this paver command line after installation (just the command line arguments, not the paver command itself).
  95. 95. paver.misctasks paver.misctasks.generate_setup() paver.misctasks.help() paver.misctasks.minilib() Options: extra_files list of other paver modules to include (donʼt include the .py extension) paver.misctasks.paverdocs()
  96. 96. Pulling it all together • write functions with the @task decorator. • Just plain old Python with lots of conveniences • Paver’s pavement.py is a good example • Even better, take a look at “Getting Started with Paver” http://bit.ly/starting_paver
  97. 97. Remember this? #!/bin/sh sphinx-build (blah blah blah) python setup.py sdist upload
  98. 98. Paver needs to do that too @task @needs(['html', quot;minilibquot;, quot;generate_setupquot;, “setuptools.command.sdist”]) def sdist(): quot;quot;quot;Builds the documentation and the tarball.quot;quot;quot; pass
  99. 99. But wait, it does more! @task @needs(['cog', 'paver.doctools.html']) def html(): quot;quot;quot;Build Paver's documentation and install it into paver/ docsquot;quot;quot; builtdocs = path(quot;docsquot;) / options.sphinx.builddir / quot;htmlquot; destdir = path(quot;paverquot;) / quot;docsquot; destdir.rmtree() builtdocs.move(destdir)
  100. 100. Changes coming to Paver • The little bit of magic goes away • Support for CloudControl • Ability to run sub-builds easily • Virtualenv/pyinstall management • zc.buildout recipe running
  101. 101. Credits • Thanks to SitePen for supporting Paver • Bumpy road http://flickr.com/photos/ilya/442034/sizes/o/ • Smooth road http://flickr.com/photos/nicholas_t/317528561/ • Options (Anna’s hairdo) http://flickr.com/photos/alangley/2136034468/ • Tasks http://flickr.com/photos/mpwillis/470557535/
  102. 102. http:// www.blueskyonmars. com/projects/ paver/
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×