Trac admin and "completion"

34 views
Skip to first unread message

Emmanuel Blot

unread,
Jun 8, 2011, 6:23:08 AM6/8/11
to Trac Development
Hi,

I need to implement an IAdminCommandProvider component, and I failed
to understand what the "complete" feature actually does.

It seems it is used from the TracAdmin.complete_line() method, which
is itself invoked from:
* TracAdmin.complete_help()
* TracAdmin.completedefault()
* TracAdmin.completenames()
However I cannot find any call to these methods. What am I missing?

Moreover, I cannot trigger an autocompletion from the tracadmin
command line. How to use it?

Thanks,
Manu

Remy Blank

unread,
Jun 8, 2011, 6:48:26 AM6/8/11
to trac...@googlegroups.com
Emmanuel Blot wrote:
> It seems it is used from the TracAdmin.complete_line() method, which
> is itself invoked from:
> * TracAdmin.complete_help()
> * TracAdmin.completedefault()
> * TracAdmin.completenames()
> However I cannot find any call to these methods. What am I missing?

This is done by the base class, cmd.Cmd.

You don't need to understand how it works, though. Just implement the
required completion functions, looking at some of the existing commands
like trac.wiki.admin.WikiAdmin as an example.

> Moreover, I cannot trigger an autocompletion from the tracadmin
> command line. How to use it?

Auto-completion should be triggered by the "Tab" key. On Windows, IIRC
you need to install pyreadline:

http://pypi.python.org/pypi/pyreadline

-- Remy

signature.asc

osimons

unread,
Jun 8, 2011, 7:25:19 AM6/8/11
to Trac Development
On Jun 8, 12:48 pm, Remy Blank <remy.bl...@pobox.com> wrote:
> Emmanuel Blot wrote:
> > Moreover, I cannot trigger an autocompletion from the tracadmin
> > command line. How to use it?
>
> Auto-completion should be triggered by the "Tab" key. On Windows, IIRC
> you need to install pyreadline:

Ah. I wasn't aware of that either. Found it now in trac-admin
interactive mode which I hardly ever use...

Anyway, good to know.


:::simon

Emmanuel Blot

unread,
Jun 8, 2011, 7:42:40 AM6/8/11
to trac...@googlegroups.com
> You don't need to understand how it works, though. Just implement the
> required completion functions, looking at some of the existing commands
> like trac.wiki.admin.WikiAdmin as an example.

As I was unable to make it work, I started to look at the code. ;-)

> Auto-completion should be triggered by the "Tab" key. On Windows, IIRC
> you need to install pyreadline:

It seems it does not work for me (Mac OS X 10.6.7).
import readline
is successful from an interactive Python shell.

Is there some specific configuration (such as the terminal type) to
make it work on Mac OS X?

Thanks,
Manu

Remy Blank

unread,
Jun 8, 2011, 8:09:07 AM6/8/11
to trac...@googlegroups.com
Emmanuel Blot wrote:
> Is there some specific configuration (such as the terminal type) to
> make it work on Mac OS X?

Not that I know of. It's working fine here (Mac OS X 10.5.?), but I'm
using Python from MacPorts, so I don't know about the stock installed
Python.

-- Remy

signature.asc

Emmanuel Blot

unread,
Jun 8, 2011, 10:36:40 AM6/8/11
to trac...@googlegroups.com
> Not that I know of. It's working fine here (Mac OS X 10.5.?), but I'm
> using Python from MacPorts, so I don't know about the stock installed
> Python.

Ok, it does not work with the system Python, but it works fine with
the Homebrew Python.

Thanks,
Manu

Emmanuel Blot

unread,
Jun 9, 2011, 9:35:30 AM6/9/11
to trac...@googlegroups.com
>> Not that I know of. It's working fine here (Mac OS X 10.5.?), but I'm
>> using Python from MacPorts, so I don't know about the stock installed
>> Python.

Follow up:

To make it work with the system Python, the Python readline library
should be used (this is a Mac OS X specific issue, as Mac OS X is
shipped with libedit instead of GNU readline), see
http://pypi.python.org/pypi/readline

1/ Install this package with easy_install (not with pip, or you'll
have to deal with a sys.path inclusion order issue):
sudo easy_install readline

2/ Check out your installation
python
import readline
readline.__file__

should report the newly installed readline library (/Library/...)
if it reports the system library (/System/Library/...) the defaut
readline module will be used, and tab completion will not work.

HTH,
Manu

RjOllos

unread,
Aug 13, 2017, 7:54:52 PM8/13/17
to Trac Development

I made some comments when closing #6695 (1). I have Python 2.7.13 installed via Homebrew, and readline is installed as well.

I tested the default Python 2.6.9 that ships with OSX and there's no command-completion.
$python
Python 2.6.9 (unknown, Feb  7 2017, 00:08:08)
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.34)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import readline
>>> readline.__doc__
'Importing this module enables command line editing using libedit readline.'

Installing gnureadline (2), which is a replacement for readline on pypi, doesn't seem to fix the issue.

I'd like to improve the documentation for TracAdmin (3) if anyone can demonstrate more accurately when readline may be needed on OSX. I'm mainly concerned with Python 2.7 since Trac is moving towards dropping support for all earlier versions of Python. Since OSX does not appear to provide Python 2.7, it must be installed somehow, so I'd be interested to know if command completion works after installing the official Python distribution for OSX (4).

Thanks,
- Ryan

(1) https://trac.edgewall.org/ticket/6695#comment:10
(2) https://pypi.python.org/pypi/gnureadline
(3) https://trac.edgewall.org/wiki/TracAdmin
(4) https://www.python.org/downloads/release/python-2713/

Emmanuel Blot

unread,
Aug 17, 2017, 7:54:30 AM8/17/17
to Trac Development
Hi Ryan,

I have not used trac on OSX for a while, but I’ve extracted the command line interpreter from trac-admin to test-drive several IoT projects.
I’m not using Python 2.x either (AFAICT, among the numerous Python projects/modules I use on a regular basis, Trac is the only one that still requires Python 2.x :-)).

However, whenever I need Python on macOs, whether it’s Python 2.7.x or Python 3.x, I install it from (home)brew, and I now always use the excellent pyreadline library in replacement of the native GNU readline - another native dependency dropped for a pure Python module.

One special attention with brew is that it’s quite easy to break a working installation, when the minor Python version is automatically updated (from 3.5 to 3.6 for example). Either the Python installation needs to be pinned down (‘brew pin’) or the proper virtual env should be set up.

The snippet that goes into the equivalent of console.py now looks like:

try:
    import readline as rl
except ImportError:
    try:
        import pyreadline as rl
    except ImportError:
        rl = None
 
I’ve observed no regression while using the Python implementation vs. the native library.

HTH,
Manu

--
You received this message because you are subscribed to the Google Groups "Trac Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to trac-dev+unsubscribe@googlegroups.com.
To post to this group, send email to trac...@googlegroups.com.
Visit this group at https://groups.google.com/group/trac-dev.
For more options, visit https://groups.google.com/d/optout.



--
Manu

RjOllos

unread,
Aug 21, 2017, 1:31:05 AM8/21/17
to Trac Development


On Thursday, August 17, 2017 at 7:54:30 AM UTC-4, Emmanuel Blot wrote:
Hi Ryan,

I have not used trac on OSX for a while, but I’ve extracted the command line interpreter from trac-admin to test-drive several IoT projects.
I’m not using Python 2.x either (AFAICT, among the numerous Python projects/modules I use on a regular basis, Trac is the only one that still requires Python 2.x :-)).

However, whenever I need Python on macOs, whether it’s Python 2.7.x or Python 3.x, I install it from (home)brew, and I now always use the excellent pyreadline library in replacement of the native GNU readline - another native dependency dropped for a pure Python module.

One special attention with brew is that it’s quite easy to break a working installation, when the minor Python version is automatically updated (from 3.5 to 3.6 for example). Either the Python installation needs to be pinned down (‘brew pin’) or the proper virtual env should be set up.

Yeah, I've found that I need to recreate my virtualenvs whenever Brew's Python is upgraded. I get an error like "cannot read image". Since my virtualenvs for trac development are always the same, I just wrote a script to recreate the virtualenv, so it's no trouble now that I know what behavior to expect.
 
The snippet that goes into the equivalent of console.py now looks like:

try:
    import readline as rl
except ImportError:
    try:
        import pyreadline as rl
    except ImportError:
        rl = None
 
I’ve observed no regression while using the Python implementation vs. the native library.

That looks interesting. We could reorder the operations to prefer pyreadline when installed:


try:
    import pyreadline as rl
except ImportError:
    try:
        import readline as rl
    except ImportError:
        rl = None


- Ryan

RjOllos

unread,
Aug 21, 2017, 1:59:45 AM8/21/17
to Trac Development


On Monday, August 21, 2017 at 1:31:05 AM UTC-4, RjOllos wrote:

The snippet that goes into the equivalent of console.py now looks like:

try:
    import readline as rl
except ImportError:
    try:
        import pyreadline as rl
    except ImportError:
        rl = None
 
I’ve observed no regression while using the Python implementation vs. the native library.

That looks interesting. We could reorder the operations to prefer pyreadline when installed:

try:
    import pyreadline as rl
except ImportError:
    try:
        import readline as rl
    except ImportError:
        rl = None

I misunderstood. It looks like pyreadline is only for Windows. On OSX I get:

>>> import pyreadline
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/rjollos/Documents/Workspace/trac-dev/pve/lib/python2.7/site-packages/pyreadline/__init__.py", line 12, in <module>
    from . import logger, clipboard, lineeditor, modes, console
  File "/Users/rjollos/Documents/Workspace/trac-dev/pve/lib/python2.7/site-packages/pyreadline/clipboard/__init__.py", line 13, in <module>
    from .win32_clipboard import GetClipboardText, SetClipboardText
  File "/Users/rjollos/Documents/Workspace/trac-dev/pve/lib/python2.7/site-packages/pyreadline/clipboard/win32_clipboard.py", line 37, in <module>
    import ctypes.wintypes as wintypes
  File "/usr/local/Cellar/python/2.7.13_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ctypes/wintypes.py", line 19, in <module>
    class VARIANT_BOOL(_SimpleCData):
ValueError: _type_ 'v' not supported


On Windows, with pyreadline installed "import readline" succeeds (if I remember correctly from testing last week), so I'm not sure why we'd need special import handling.

- Ryan
Reply all
Reply to author
Forward
0 new messages