I don't know if I'm dumb, ignorant, inexperienced, or asleep but while
I can sometimes beat a plugin into submission, once I have setup.py
working I treat it with superstition and reverence, unable to change
anything with a plan or with confidence that it will do the right
thing. I've looked and asked and I have never gotten a pointer to a
clear explanation of what to put in it. Help!
I'm working my IQueryPreprocessor
(
http://trac.edgewall.org/ticket/10983) I'm now trying to port my
ExtensionPoint in 0.11.6 to an OrderedExtensionsOption in 1.0 (or 1.1
or whatever the development branch is). In 0.11.6, I can test my
changes to query.py with my TracPM code but that's not ported to or
tested in 1.0 yet so I figured I'd just put together a trivial
implementation to illustrate and test the interface (at the end of
this message). My example translates "foo" to "id" so
[[TicketQuery(foo=1)]] is the same as [[TicketQuery(id=1)]] and
[[TicketQuery(id=1|2,foo=3)]] is the same as
[[TicketQuery(id=1|2|3)]]. I put my code in
trac/sample-plugins/sampleQueryPreprocessor/sampleQueryPreprocessor.py
and tried and tried to create a setup.py in that directory. Nothing I
try works. I build my egg and deploy it and my trac.log says:
2013-01-21 15:45:27,463 Trac[loader] DEBUG: Adding plugin
SampleQueryPreprocessor 0.1 from
/opt/trac/trac1.0/plugins/SampleQueryPreprocessor-0.1-py2.7.egg
2013-01-21 15:45:27,470 Trac[loader] DEBUG: Loading
SampleQueryPreprocessor from
/opt/trac/trac1.0/plugins/SampleQueryPreprocessor-0.1-py2.7.egg
2013-01-21 15:45:27,473 Trac[loader] ERROR: Skipping
"SampleQueryPreprocessor = SampleQueryPreprocessor":
Traceback (most recent call last):
File "build/bdist.linux-x86_64/egg/trac/loader.py", line 68, in _load_eggs
entry.load(require=True)
File "build/bdist.linux-i686/egg/pkg_resources.py", line 1954, in load
entry = __import__(self.module_name, globals(),globals(), ['__name__'])
ImportError: No module named SampleQueryPreprocessor
My setup.py (modeled on something else I found on my disk that I think
works) is:
#!/usr/bin/env python
# -*- coding: iso-8859-1 -*-
from setuptools import find_packages, setup
setup(
name = 'SampleQueryPreprocessor',
author = 'Chris Nelson',
author_email = 'Chris....@SIXNET.com',
description = 'Example of a IQueryPreprocessor implementation',
version = '0.1',
license='BSD',
packages=find_packages(exclude=['*tests*']),
entry_points = """
[trac.plugins]
SampleQueryPreprocessor=SampleQueryPreprocessor
""",
)
What should it be? Better yet, where can I find a tutorial or
reference so I can get this right next time. This is making me
insane!
----8<---- plugin source follows --->8-----
from trac.core import implements, Component
from trac.ticket import IQueryPreprocessor
# A sample implementation of IQueryPreprocessor
#
# This trivial example implements foo= as a synonym for id=. That is,
# [[TicketQuery(foo=1)]] is the same as [[TicketQuery(id=1)]]. Also,
# [[TicketQuery(id=1|2,foo=3)]] becomes [[TicketQuery(id=1|2|3)]].
class SampleQueryHelper(Component):
implements(IQueryPreprocessor)
def __init__(self):
self.myConstraint = 'foo'
self.env.log.info('SampleQueryHelper will translate "foo" to "id".')
# IQueryPreprocessor methods
# Return the list of constraints handled by process_constraints()
def custom_constraints(self):
self.env.log.info('SampleQueryPreprocessor.custom_constraints.')
return [ self.myConstraint ]
# Turn custom constraints (e.g., foo) into standard contraints (e.g., id)
#
# @param req the Trac web request object, may be None
# @param constraints hash indexed by contraint name (e.g., 'foo',
# 'id'). Each entry is a list of values.
#
# @return updated constraints.
def process_constraints(self, req, constraints):
self.env.log.info('SampleQueryPreprocessor.process_constraints.')
# constraint values are lists, TracPM.preQuery() expects
# pipe-delimited strings.
options = {}
for constraint in self.custom_constraints():
if constraint in constraints:
options[constraint] = "|".join(constraints[constraint])
del constraints[constraint]
# Our magic IDs are in 'foo'.
ids = constraints[ self.myConstraint ]
if len(ids):
if 'id' not in constraints:
constraints['id'] = []
for tid in ids:
if tid not in constraints['id']:
constraints['id'].append(tid)
return constraints