Python eggs, zc.buildout, zopeproject and zope3

45
Eggs, zc.buildout and Zope3 Getting started with eggs, zc.buildout and Zope3 Darryl Cousins [email protected] Tree Fern Web Services New Zealand Python User Group meeting, February 2008 Darryl Cousins [email protected] (Tree Fern Web Services) Zope3 NZPUG February 2008 1 / 25

description

A simple introduction to getting a start with Zope3 using eggs, zc.buildout and zopeproject

Transcript of Python eggs, zc.buildout, zopeproject and zope3

Page 1: Python eggs, zc.buildout, zopeproject and zope3

Eggs, zc.buildout and Zope3Getting started with eggs, zc.buildout and Zope3

Darryl [email protected]

Tree Fern Web Services

New Zealand Python User Group meeting, February 2008

Darryl Cousins [email protected] (Tree Fern Web Services) Zope3 NZPUG February 2008 1 / 25

Page 2: Python eggs, zc.buildout, zopeproject and zope3

Eggs

A Python Module

• A block of code which may imported by some other code.

Darryl Cousins [email protected] (Tree Fern Web Services) Zope3 NZPUG February 2008 2 / 25

Page 3: Python eggs, zc.buildout, zopeproject and zope3

Eggs

A Python Module: hello.py

def helloworld():print u"Hello World"

We can import the method from the module:

from hello import helloworld

Darryl Cousins [email protected] (Tree Fern Web Services) Zope3 NZPUG February 2008 3 / 25

Page 4: Python eggs, zc.buildout, zopeproject and zope3

Eggs

A Python Module: hello.py

def helloworld():print u"Hello World"

We can import the method from the module:

from hello import helloworld

Darryl Cousins [email protected] (Tree Fern Web Services) Zope3 NZPUG February 2008 3 / 25

Page 5: Python eggs, zc.buildout, zopeproject and zope3

Eggs

A Python Package: hello

A package is a module that contains other modules:

hello/__init__.pyhello.py

Now we must import the method from the module within the module.

from hello.hello import helloworld

Darryl Cousins [email protected] (Tree Fern Web Services) Zope3 NZPUG February 2008 4 / 25

Page 6: Python eggs, zc.buildout, zopeproject and zope3

Eggs

A Python Package: hello

A package is a module that contains other modules:

hello/__init__.pyhello.py

Now we must import the method from the module within the module.

from hello.hello import helloworld

Darryl Cousins [email protected] (Tree Fern Web Services) Zope3 NZPUG February 2008 4 / 25

Page 7: Python eggs, zc.buildout, zopeproject and zope3

Eggs

Distutils

Distutils was written so we have a unified way to install python modules.

python setup.py install

Darryl Cousins [email protected] (Tree Fern Web Services) Zope3 NZPUG February 2008 5 / 25

Page 8: Python eggs, zc.buildout, zopeproject and zope3

Eggs

Distutils - creating a distribution

To distribute the hello module we need have it in a directory with a setup.pyfile.

workingdir/setup.pyhello/

__init__.pyhello.py

The setup.py file needs at the least the following.

from distutils.core import setup

setup(name="hello",)

Darryl Cousins [email protected] (Tree Fern Web Services) Zope3 NZPUG February 2008 6 / 25

Page 9: Python eggs, zc.buildout, zopeproject and zope3

Eggs

Distutils - creating a distribution

To distribute the hello module we need have it in a directory with a setup.pyfile.

workingdir/setup.pyhello/

__init__.pyhello.py

The setup.py file needs at the least the following.

from distutils.core import setup

setup(name="hello",)

Darryl Cousins [email protected] (Tree Fern Web Services) Zope3 NZPUG February 2008 6 / 25

Page 10: Python eggs, zc.buildout, zopeproject and zope3

Eggs

Distutils - creating a distribution, continuedNow we can create a distribution tarball with disutils.

python setup.py sdist

Our directory now looks like this

workingdir/setup.pyhello/

__init__.pyhello.py

dist/hello-1.0.tar.gz

If we unpack the source distribution it looks like this:

hello-1.0/PKG-INFOsetup.pyhello/

__init__.pyhello.py

Darryl Cousins [email protected] (Tree Fern Web Services) Zope3 NZPUG February 2008 7 / 25

Page 11: Python eggs, zc.buildout, zopeproject and zope3

Eggs

Distutils - creating a distribution, continuedNow we can create a distribution tarball with disutils.

python setup.py sdist

Our directory now looks like this

workingdir/setup.pyhello/

__init__.pyhello.py

dist/hello-1.0.tar.gz

If we unpack the source distribution it looks like this:

hello-1.0/PKG-INFOsetup.pyhello/

__init__.pyhello.py

Darryl Cousins [email protected] (Tree Fern Web Services) Zope3 NZPUG February 2008 7 / 25

Page 12: Python eggs, zc.buildout, zopeproject and zope3

Eggs

Distutils - creating a distribution, continuedNow we can create a distribution tarball with disutils.

python setup.py sdist

Our directory now looks like this

workingdir/setup.pyhello/

__init__.pyhello.py

dist/hello-1.0.tar.gz

If we unpack the source distribution it looks like this:

hello-1.0/PKG-INFOsetup.pyhello/

__init__.pyhello.py

Darryl Cousins [email protected] (Tree Fern Web Services) Zope3 NZPUG February 2008 7 / 25

Page 13: Python eggs, zc.buildout, zopeproject and zope3

Eggs

Setuptools

• Setuptools is built on top of distutils

• uses the setup.py

• uses eggs for distribution

• allows us to save our modules as eggs to pypi

Installing setuptools

wget http://peak.telecommunity.com/dist/ez_setup.pypython ez_setup.py

Darryl Cousins [email protected] (Tree Fern Web Services) Zope3 NZPUG February 2008 8 / 25

Page 14: Python eggs, zc.buildout, zopeproject and zope3

Eggs

Setuptools

• Setuptools is built on top of distutils

• uses the setup.py

• uses eggs for distribution

• allows us to save our modules as eggs to pypi

Installing setuptools

wget http://peak.telecommunity.com/dist/ez_setup.pypython ez_setup.py

Darryl Cousins [email protected] (Tree Fern Web Services) Zope3 NZPUG February 2008 8 / 25

Page 15: Python eggs, zc.buildout, zopeproject and zope3

Eggs

Eggs

To create an egg change the import line in setup.py

from setuptools import setup

setup(name="hello",version="1.0",)

We can call that with:

python setup.py bdist_egg

Which creates a binary egg in our dist directory

dist/hello-1.0-py2.4.egg

Darryl Cousins [email protected] (Tree Fern Web Services) Zope3 NZPUG February 2008 9 / 25

Page 16: Python eggs, zc.buildout, zopeproject and zope3

Eggs

Eggs

To create an egg change the import line in setup.py

from setuptools import setup

setup(name="hello",version="1.0",)

We can call that with:

python setup.py bdist_egg

Which creates a binary egg in our dist directory

dist/hello-1.0-py2.4.egg

Darryl Cousins [email protected] (Tree Fern Web Services) Zope3 NZPUG February 2008 9 / 25

Page 17: Python eggs, zc.buildout, zopeproject and zope3

Eggs

Eggs

To create an egg change the import line in setup.py

from setuptools import setup

setup(name="hello",version="1.0",)

We can call that with:

python setup.py bdist_egg

Which creates a binary egg in our dist directory

dist/hello-1.0-py2.4.egg

Darryl Cousins [email protected] (Tree Fern Web Services) Zope3 NZPUG February 2008 9 / 25

Page 18: Python eggs, zc.buildout, zopeproject and zope3

Eggs

Pypi

If we want that egg available on pypi and we have an account we can do thatwith a single command.

python setup.py sdist upload

Which all the world can use

easy_install hello

Darryl Cousins [email protected] (Tree Fern Web Services) Zope3 NZPUG February 2008 10 / 25

Page 19: Python eggs, zc.buildout, zopeproject and zope3

Eggs

Pypi

If we want that egg available on pypi and we have an account we can do thatwith a single command.

python setup.py sdist upload

Which all the world can use

easy_install hello

Darryl Cousins [email protected] (Tree Fern Web Services) Zope3 NZPUG February 2008 10 / 25

Page 20: Python eggs, zc.buildout, zopeproject and zope3

zc.buildout

zc.buildout - what is it?

• Buildout is a system of configuring repeatable steps for assemblingcomplicated systems (applications) from multiple parts.

• A real world example of my own includes:• apache• postgresql• ramdb• zope3• sqlalchemy• pyxml• egenix-mx-base• psycopg2

Darryl Cousins [email protected] (Tree Fern Web Services) Zope3 NZPUG February 2008 11 / 25

Page 21: Python eggs, zc.buildout, zopeproject and zope3

zc.buildout

zc.buildout - what is it?

• Buildout is a system of configuring repeatable steps for assemblingcomplicated systems (applications) from multiple parts.

• A real world example of my own includes:• apache• postgresql• ramdb• zope3• sqlalchemy• pyxml• egenix-mx-base• psycopg2

Darryl Cousins [email protected] (Tree Fern Web Services) Zope3 NZPUG February 2008 11 / 25

Page 22: Python eggs, zc.buildout, zopeproject and zope3

zc.buildout

Example buildout.cfg

[buildout]develop = .parts = py

[py]recipe = zc.recipe.egginterpreter = pyeggs = hello

Darryl Cousins [email protected] (Tree Fern Web Services) Zope3 NZPUG February 2008 12 / 25

Page 23: Python eggs, zc.buildout, zopeproject and zope3

zc.buildout

So - how to get started with Zope3

• Download tarball.

Wrong!

• Use zopeproject

Darryl Cousins [email protected] (Tree Fern Web Services) Zope3 NZPUG February 2008 13 / 25

Page 24: Python eggs, zc.buildout, zopeproject and zope3

zc.buildout

So - how to get started with Zope3

• Download tarball. Wrong!

• Use zopeproject

Darryl Cousins [email protected] (Tree Fern Web Services) Zope3 NZPUG February 2008 13 / 25

Page 25: Python eggs, zc.buildout, zopeproject and zope3

zc.buildout

So - how to get started with Zope3

• Download tarball. Wrong!

• Use zopeproject

Darryl Cousins [email protected] (Tree Fern Web Services) Zope3 NZPUG February 2008 13 / 25

Page 26: Python eggs, zc.buildout, zopeproject and zope3

zc.buildout

Virtual Environment

virtualenv nzpug

cd nzpug./bin/easy_install zopeproject

bin/zopeproject nzpugEnter user (Name of an initial administrator): darrylEnter passwd (Password for .. ): secretEnter eggs_dir (Location ..) [’/opt/buildout/eggs’]: **Creating directory ./nzpugDownloading zc.buildout..Invoking zc.buildout..

Darryl Cousins [email protected] (Tree Fern Web Services) Zope3 NZPUG February 2008 14 / 25

Page 27: Python eggs, zc.buildout, zopeproject and zope3

zc.buildout

Virtual Environment

virtualenv nzpug

cd nzpug./bin/easy_install zopeproject

bin/zopeproject nzpugEnter user (Name of an initial administrator): darrylEnter passwd (Password for .. ): secretEnter eggs_dir (Location ..) [’/opt/buildout/eggs’]: **Creating directory ./nzpugDownloading zc.buildout..Invoking zc.buildout..

Darryl Cousins [email protected] (Tree Fern Web Services) Zope3 NZPUG February 2008 14 / 25

Page 28: Python eggs, zc.buildout, zopeproject and zope3

zc.buildout

Virtual Environment

virtualenv nzpug

cd nzpug./bin/easy_install zopeproject

bin/zopeproject nzpugEnter user (Name of an initial administrator): darrylEnter passwd (Password for .. ): secretEnter eggs_dir (Location ..) [’/opt/buildout/eggs’]: **Creating directory ./nzpugDownloading zc.buildout..Invoking zc.buildout..

Darryl Cousins [email protected] (Tree Fern Web Services) Zope3 NZPUG February 2008 14 / 25

Page 29: Python eggs, zc.buildout, zopeproject and zope3

zc.buildout

.buildout/default.cfg

[buildout]eggs-directory=/opt/buildout/eggsdevelop-eggs-directory=/opt/buildout/develop-eggsdownload-cache=/opt/buildout/cache

Darryl Cousins [email protected] (Tree Fern Web Services) Zope3 NZPUG February 2008 15 / 25

Page 30: Python eggs, zc.buildout, zopeproject and zope3

zc.buildout

nzpug/buildout.cfg

[buildout]develop = .parts = app testfind-links = http://download.zope.org/distribution/newest = false# eggs will be installed in the default buildout location# (see ~/.buildout/default.cfg)

extends = http://download.zope.org/zope3.4/versions-3.4.0.cfg

Darryl Cousins [email protected] (Tree Fern Web Services) Zope3 NZPUG February 2008 16 / 25

Page 31: Python eggs, zc.buildout, zopeproject and zope3

zc.buildout

nzpug/buildout.cfg

[buildout]develop = .parts = app testfind-links = http://download.zope.org/distribution/newest = false# eggs will be installed in the default buildout location# (see ~/.buildout/default.cfg)

extends = http://download.zope.org/zope3.4/versions-3.4.0.cfg

Darryl Cousins [email protected] (Tree Fern Web Services) Zope3 NZPUG February 2008 16 / 25

Page 32: Python eggs, zc.buildout, zopeproject and zope3

zc.buildout

nzpug/buildout.cfg (continued)

[app]recipe = zc.recipe.eggeggs = nzpug

zope.app.apidoczope.app.securitypolicyz3c.evalexception>=2.0PastePasteScriptPasteDeploy

interpreter = python

[test]recipe = zc.recipe.testrunnereggs = nzpugdefaults = [’--tests-pattern’, ’^f?tests$’, ’-v’]

Darryl Cousins [email protected] (Tree Fern Web Services) Zope3 NZPUG February 2008 17 / 25

Page 33: Python eggs, zc.buildout, zopeproject and zope3

zc.buildout

nzpug/buildout.cfg (continued)

[app]recipe = zc.recipe.eggeggs = nzpug

zope.app.apidoczope.app.securitypolicyz3c.evalexception>=2.0PastePasteScriptPasteDeploy

interpreter = python

[test]recipe = zc.recipe.testrunnereggs = nzpugdefaults = [’--tests-pattern’, ’^f?tests$’, ’-v’]

Darryl Cousins [email protected] (Tree Fern Web Services) Zope3 NZPUG February 2008 17 / 25

Page 34: Python eggs, zc.buildout, zopeproject and zope3

zc.buildout

Directory contents

bin/log/parts/src/var/apidoc.zcmlbuildout.cfgdebug.inideploy.inisetup.pysite.zcmlzdaemon.confzope.conf

Darryl Cousins [email protected] (Tree Fern Web Services) Zope3 NZPUG February 2008 18 / 25

Page 35: Python eggs, zc.buildout, zopeproject and zope3

zc.buildout

What’s in the bin directory?

buildoutnzpug-ctlnzpug-debugpasterpythonstatic-apidoctest

Darryl Cousins [email protected] (Tree Fern Web Services) Zope3 NZPUG February 2008 19 / 25

Page 36: Python eggs, zc.buildout, zopeproject and zope3

zc.buildout

nzpug/deploy.ini

[app:main]use = egg:nzpug

[server:main]use = egg:Paste#httphost = 127.0.0.1port = 8080

Darryl Cousins [email protected] (Tree Fern Web Services) Zope3 NZPUG February 2008 20 / 25

Page 37: Python eggs, zc.buildout, zopeproject and zope3

zc.buildout

What’s in the src/nzpug directory?

__init__.pyconfigure.zcmlftesting.zcmlstartup.pytesting.py

Darryl Cousins [email protected] (Tree Fern Web Services) Zope3 NZPUG February 2008 21 / 25

Page 38: Python eggs, zc.buildout, zopeproject and zope3

zc.buildout

A HelloWorld - step 1: The template

hello.pt

<html i18n:domain="nzpug"><head>

<title i18n:translate="">Hello World</title></head><body i18n:translate="">

Hello World</body>

</html>

Darryl Cousins [email protected] (Tree Fern Web Services) Zope3 NZPUG February 2008 22 / 25

Page 39: Python eggs, zc.buildout, zopeproject and zope3

zc.buildout

A HelloWorld - step 2: The registration

configure.zcml

<configure xmlns="http://namespaces.zope.org/zope"xmlns:browser="http://namespaces.zope.org/browser"i18n_domain="nzpug">

<pagefor="*"name="hello"permission="zope.Public"template="hello.pt"

/>

</configure>

./bin/nzpug-ctl fg

http://localhost:8080/helloHello World

Darryl Cousins [email protected] (Tree Fern Web Services) Zope3 NZPUG February 2008 23 / 25

Page 40: Python eggs, zc.buildout, zopeproject and zope3

zc.buildout

A HelloWorld - step 2: The registration

configure.zcml

<configure xmlns="http://namespaces.zope.org/zope"xmlns:browser="http://namespaces.zope.org/browser"i18n_domain="nzpug">

<pagefor="*"name="hello"permission="zope.Public"template="hello.pt"

/>

</configure>

./bin/nzpug-ctl fg

http://localhost:8080/helloHello World

Darryl Cousins [email protected] (Tree Fern Web Services) Zope3 NZPUG February 2008 23 / 25

Page 41: Python eggs, zc.buildout, zopeproject and zope3

zc.buildout

A HelloWorld - step 2: The registration

configure.zcml

<configure xmlns="http://namespaces.zope.org/zope"xmlns:browser="http://namespaces.zope.org/browser"i18n_domain="nzpug">

<pagefor="*"name="hello"permission="zope.Public"template="hello.pt"

/>

</configure>

./bin/nzpug-ctl fg

http://localhost:8080/helloHello World

Darryl Cousins [email protected] (Tree Fern Web Services) Zope3 NZPUG February 2008 23 / 25

Page 42: Python eggs, zc.buildout, zopeproject and zope3

zc.buildout

Hello who?

hello.pt

<html i18n:domain="nzpug"><head>

<title i18n:translate="">Hello World</title></head><body i18n:translate="">

Hello <spantal:replace="view/request/who|default">World</span>

</body></html>

./bin/nzpug-ctl fg

http://localhost:8080/hello?who=DarrylHello Darryl

Darryl Cousins [email protected] (Tree Fern Web Services) Zope3 NZPUG February 2008 24 / 25

Page 43: Python eggs, zc.buildout, zopeproject and zope3

zc.buildout

Hello who?

hello.pt

<html i18n:domain="nzpug"><head>

<title i18n:translate="">Hello World</title></head><body i18n:translate="">

Hello <spantal:replace="view/request/who|default">World</span>

</body></html>

./bin/nzpug-ctl fg

http://localhost:8080/hello?who=DarrylHello Darryl

Darryl Cousins [email protected] (Tree Fern Web Services) Zope3 NZPUG February 2008 24 / 25

Page 44: Python eggs, zc.buildout, zopeproject and zope3

zc.buildout

Create a distribution of our app

python setup.py bdist_egg

ls distnzpug-0.1-py2.4.egg

Darryl Cousins [email protected] (Tree Fern Web Services) Zope3 NZPUG February 2008 25 / 25

Page 45: Python eggs, zc.buildout, zopeproject and zope3

zc.buildout

Create a distribution of our app

python setup.py bdist_egg

ls distnzpug-0.1-py2.4.egg

Darryl Cousins [email protected] (Tree Fern Web Services) Zope3 NZPUG February 2008 25 / 25