PyCharm usage tips for developing Plone? (fixing global module imports)

Here are instructions to use PyCharm without undermaintained Buildout support:

At first, add part for interpreter named "python" into buildout.cfg:

[buildout]
parts =
    ...
    python

[python]
recipe = zc.recipe.egg
eggs =
    ${instance:eggs}
    plone.recipe.zope2instance
interpreter = python-interpreter

This will create a new interpreter ./bin/python-interpreter, which can be configured as a new local Project Python interpreter into PyCharm.

This is enough for all basic features and also for running bin/instance fg as configured task directly from PyCharm.

I struggled a bit to get PyCharm debugger working today. It used to work, but possibly something has changed in the recent versions and now it manages to drop all Plone eggs from its working set. That can be patched in buildout.cfg with:

[instance]
recipe = plone.recipe.zope2instance
...
initialization =
    import pkg_resources
    pkg_resources._initialize_master_working_set()

Obviously, this should only be added to instance parts used during development. It will enforce pkg_resources' working set to include all paths in sys.path (otherwise PyCharm debugger manages to reset it and drop all packages add by ./bin/python).

Now also configured ./bin/instance fg tasks can also be run with PyCharm debugger with its great features.

With this configuration, please, disable omelette from buildout so that you won't accidentally import stuff with omelette paths.

Update: I changed interpreter = python to python-interpreter so that developers having virtualenv in the project directory would not broke their environments. (PyCharm requires Python interpreter binary to start with python.)

1 Like