HowTo: Developing Plone with Eclipse IDE

Assumptions: You have installed Plone to your machine in (eg) d:\Plone25 and you have checked out your code to the Products folder. You have installed Eclipse 3.2.1 with the WebTools plugin and PyDev plugins
Known Limitations:

  1. from Windows you’ll need to do your Subversion stuff via TortiseCVS rather than Eclipse.  I did get around this by creating my Plone product as a separate Eclipse project (in addition to the project setup discussed below) and then using a sync tool (eg SyncBack) to copy the files to the Products folder under Plone.
  2. Full debug doesn’t work inside the Products folder.   You can step through unit tests and code under the Zope folder but to get step by step debug working inside Products you’ll need to get the PyDev extensions and follow the instructions here
  3. PyDev has trouble with the Python path for the Products folder because Products dir has no __init__.py   If you add this file (can be empty) then autocomplete and import statement check will work.   (Same goes for any Products without init.py)

This HowTo is based on an older guide: http://plone.org/documentation/how-to/developing-plone-with-eclipse-ide

Setting up the environment.

Open Eclipse and choose a workspace directory. Open the PyDev “Perspective” (and close the Java perspective :( !!)

To enable code completion and launching Python files inside IDE, you need to specify few things.

  • Setup available Python interpreters
    1. Window -> Preferences -> PyDev -> Interpreter – Python
    2. Add your Plone interpreter (eg d:\Plone25\python\Python.exe)

Associate page templates to HTML editor

  1. Window -> Preferences -> General -> Content Types
  2. Open Text -> HTML
    • Add .dtml, .pt and *.cpt
  3. Open Text -> CSS
    • Add *.dtml

This gives HTML and CSS code completion (via CNTRL+space) and validation. (NB The TAL attributes will show up as failed validations…)

Setting up the project.

  1. Create a PyDev project (call it, say, UNINterface)
    • Uncheck “Use default and enter the Plone install directory eg. d:\Plone25
    • Uncheck “Create default src folder…”

    New Project

  1. Right click the project, select Properties, then PyDev – PYTHONPATH
    • Select “Add source folder” and add the
      /Data/Products and
      /Zope/lib/python

    Project Properties
    At this stage you should be able to open a .py file or .dtml or .css in the correct editor (If you want to choose a specific editor use Right Click -> Open and select the correct editor. That one will become the next default.). Other good things to do. Highlight the name of a Type and press F3. The highlighted class should (eventually) appear in the editor window. Can also do this with variables but it can be slow as the tooling tries to find all the possible types that the variable could be.)

 

Setting up the Unit Test debug environment.

  1. From the menu select Run -> Run..
  2. Click Python Run and then the “new” Run Configuration button

Run Configuration

 

Name: “Run Zope Test”

Project: Plone25

Main module: D:\Plone25\Zope\bin\test.py

Click the “Arguments” tab

Base directory: D:\Plone25\Data\bin

Program arguments: -vv –config-file=../etc/zope.conf -m Products.<your-product>

Interpreter: d:\python\python24\python.exe

Click the “Environment” tab

Create two new env. variables

INSTANCE_HOME: D:\Plone25\Data

SOFTWARE_HOME: D:\Plone25\Zope\lib\python

The alternative is to set these as System Variables, then restart Eclipse – This is OK unless you have muliple Zope installations.

  1. At this point, if you click “Run” for the new Run configuration Eclipse should automatically run all the tests for your project
  2. If you choose Debug instead of Run you can set breakpoints in your tests and Eclipse will take you into the “Debug” perspective – Step by Step debug.

Setting up the server debug environment

  1. From the menu select Run -> Run..
  2. Click Python Run and then the “new” Run Configuration button Name: “Run Zope Server”Project: Plone25Main module: D:/Plone25/Zope/lib/python/Zope2/Startup/run.py

    Click the “Arguments” tab

    Base directory: D:\Plone25\Data\bin

    Program arguments: -C D:\Plone25\Data\etc\zope.conf

    Interpreter: d:\python\python24\python.exe

    Click the “Environment” tab

    Create two new env. variables:

    INSTANCE_HOME: D:\Plone25\Data

    SOFTWARE_HOME: D:\Plone25\Zope\lib\python

    The alternative is to set these as System Variables, then restart Eclipse – This is OK unless you have muliple Zope installations.

  3. You can now set Breakpoints in any python module in Zope or Plone and do stepwise debug. (hopefully)

About these ads
This entry was posted in Plone. Bookmark the permalink.

9 Responses to HowTo: Developing Plone with Eclipse IDE

  1. Pingback: plonewars.com - » HowTo: Developing Plone with Eclipse IDE « The Pooken Hole

  2. ed k says:

    If you are using pydev extensions, you need to do a few more things-

    add an __init__.py file to your products directory with
    __ac_permissions__=()
    in the contents.

    Also, use the following as a PYTHONPATH
    /-zopecoredir-/lib/python
    /-ploneinstance-

    !In that order! – if you do not use that order Zope will be unable to find the Products folder in /-zopecoredir-/lib/python

  3. Error: positional arguments are not supported
    For help, use D:\Program Files\Plone 2\Zope\lib\python\Zope2\Startup\run.py -h

    Please help me !

  4. Hi there. I’m guessing that you’re trying to start Plone from Eclipse and that you’ve set up the variables and arguments as above but I suspect that you have installed Plone under “Program Files”. The space in the directory name may be causing the issue. Perhaps try putting quotes around the Run dialog arguments. Also, try clicking the “See resulting command line for the given parameters” button on the Run dialog “arguments” tab. This will show you exactly what you’re trying to run.

  5. I reinstalled Plone and Python.
    And now:

    Traceback (most recent call last):
    File “D:\Plone25\Zope\lib\python\Zope2\Startup\run.py”, line 56, in
    run()
    File “D:\Plone25\Zope\lib\python\Zope2\Startup\run.py”, line 19, in run
    opts = _setconfig()
    File “D:\Plone25\Zope\lib\python\Zope2\Startup\run.py”, line 48, in _setconfig
    opts.realize(doc=”Sorry, no option docs yet.”)
    File “D:\Plone25\Zope\lib\python\zdaemon\zdoptions.py”, line 273, in realize
    self.load_schema()
    File “D:\Plone25\Zope\lib\python\zdaemon\zdoptions.py”, line 321, in load_schema
    self.schema = ZConfig.loadSchema(self.schemafile)
    File “D:\Plone25\Zope\lib\python\ZConfig\loader.py”, line 31, in loadSchema
    return SchemaLoader().loadURL(url)
    File “D:\Plone25\Zope\lib\python\ZConfig\loader.py”, line 65, in loadURL
    return self.loadResource(r)
    File “D:\Plone25\Zope\lib\python\ZConfig\loader.py”, line 159, in loadResource
    schema = ZConfig.schema.parseResource(resource, self)
    File “D:\Plone25\Zope\lib\python\ZConfig\schema.py”, line 27, in parseResource
    xml.sax.parse(resource.file, parser)
    File “D:\Python25\Lib\xml\sax\__init__.py”, line 33, in parse
    parser.parse(source)
    File “D:\Python25\Lib\xml\sax\expatreader.py”, line 107, in parse
    xmlreader.IncrementalParser.parse(self, source)
    File “D:\Python25\Lib\xml\sax\xmlreader.py”, line 123, in parse
    self.feed(buffer)
    File “D:\Python25\Lib\xml\sax\expatreader.py”, line 207, in feed
    self._parser.Parse(data, isFinal)
    File “D:\Python25\Lib\xml\sax\expatreader.py”, line 301, in start_element
    self._cont_handler.startElement(name, AttributesImpl(attrs))
    File “D:\Plone25\Zope\lib\python\ZConfig\schema.py”, line 99, in startElement
    getattr(self, “start_” + name)(attrs)
    File “D:\Plone25\Zope\lib\python\ZConfig\schema.py”, line 475, in start_schema
    keytype, valuetype, datatype = self.get_sect_typeinfo(attrs)
    File “D:\Plone25\Zope\lib\python\ZConfig\schema.py”, line 201, in get_sect_typeinfo
    datatype = self.get_datatype(attrs, “datatype”, “null”, base)
    File “D:\Plone25\Zope\lib\python\ZConfig\schema.py”, line 194, in get_datatype
    return self._registry.get(dtname)
    File “D:\Plone25\Zope\lib\python\ZConfig\datatypes.py”, line 398, in get
    t = self.search(name)
    File “D:\Plone25\Zope\lib\python\ZConfig\datatypes.py”, line 423, in search
    package = __import__(n, g, g, component)
    File “D:\Plone25\Zope\lib\python\Zope2\Startup\datatypes.py”, line 20, in
    from ZODB.config import ZODBDatabase
    File “D:\Plone25\Zope\lib\python\ZODB\__init__.py”, line 20, in
    from persistent import TimeStamp
    File “D:\Plone25\Zope\lib\python\persistent\__init__.py”, line 19, in
    from cPersistence import Persistent, GHOST, UPTODATE, CHANGED, STICKY
    ImportError: DLL load failed: The specified module could not be found.

  6. Are you starting Plone from Eclipse? Have you tried to start Plone from the command line? Does that work? Also, you shouldn’t need to install Python as Plone comes with Python in the “unified installer”

  7. I start Plone from Eclipse.
    I want to create a product on Plone.
    Please show me how to.

  8. в конце концов: прелестно!

  9. Simply want to say your article is as astonishing. The clarity
    in your post is simply cool and i could assume you’re
    an expert on this subject. Fine with your permission let me to grab your feed to keep up to date with forthcoming post.

    Thanks a million and please carry on the rewarding work.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s