Loading in-process hooks under Windows

Roman V. Kiseliov roman.kiseliov at gmail.com
Thu Aug 6 01:17:02 CDT 2009


I think it would be cleaner to have some formal mechanism for adding
paths to sys.path via an hgrc file.

This way gives more freedom and flexibility (but uncovers Mercurial's
pythonic origin :) ). On the other hand if someone is using in-process
hooks, hi's definitely knows Python, sys.path and all the coupled
stuff and wants more control about such things in hgrc.

It would be also nice if hgrc allows on righthand sides Python
functions and expressions with syntax

some_var = python:`some python expression having access to ui & repo`

or syntax that is more pleasant for you than that.

To make happy shell users syntax can be

some_var = `some schell expression having access to environment variables`

Roman

2009/8/6 Steve Borho <steve at borho.org>:
> On Wed, Aug 5, 2009 at 11:14 PM, Steve Borho<steve at borho.org> wrote:
>> On Wed, Aug 5, 2009 at 9:39 AM, Steve Borho<steve at borho.org> wrote:
>>> On Wed, Aug 5, 2009 at 3:29 AM, Dirkjan Ochtman<dirkjan at ochtman.nl> wrote:
>>>> On Wed, Aug 5, 2009 at 10:14, Roman V. Kiseliov<roman.kiseliov at gmail.com> wrote:
>>>>> Attached patch fixes loading in-process hooks with full path specified
>>>>> (including drive letter and following colon) under Windows.
>>>>
>>>> Looks good to me. If Steve likes it, maybe he can push it to crew-stable?
>>>
>>> That was my thought as well.  I would like to smoke test it in a
>>> binary installer first.
>>
>> Dang.  This patch does work with a source install of Mercurial on
>> Windows, but it still does not work with a binary installer.
>>
>> I wrote a simple test hook, stored in C:\myhook.py
>>
>> def myhook(ui, repo, **kwargs):
>>    print ui, repo
>>    print kwargs.keys()
>>    return True
>>
>> Then set hooks.pretxncommit = python:C:\myhook.py:myhook in the repo hgrc
>>
>> Using source install:
>>
>> C:\thg-installer>hg commit -v -m "test"
>> build-stable.bat
>> setup.py
>> calling hook pretxncommit: <function myhook at 0x01244330>
>> <mercurial.ui.ui object at 0x00F60CF0> <hgext.mq.mqrepo object at 0x00F66790>
>> ['node', 'pending', 'hooktype', 'parent1', 'parent2']
>> transaction abort!
>> rollback completed
>> abort: pretxncommit hook failed
>>
>>
>> Using binary installer:
>>
>> C:\thg-installer>hg.exe commit -v -m "test"
>> build-stable.bat
>> setup.py
>> calling hook pretxncommit: C:/myhook.py:myhook
>> transaction abort!
>> rollback completed
>> abort: pretxncommit hook is invalid (import of "C:/myhook" failed)
>>
>> I then tried --debugger and experimented with just about every import
>> path I could think of, but Python refused to import the myhook.py or
>> myhook.pyc file.  At this point I don't know if there's some dark
>> magic that I need to find, or whether this has been specifically
>> broken by py2exe.
>
> I've found that if I manually append the hook dirname to sys.path, I
> can then import the hook without any absolute path.  In other words,
> turning:
>
> __import__(r'C:\hooks\myhook')
>
> into
>
> sys.path.append(r'C:\hooks')
> __import__('myhook')
>
> does work in a binary installer.  Would it be ok to put some 'if
> sys.frozen' type code in hook.py, or would it be cleaner to have some
> formal mechanism for adding paths to sys.path via an hgrc file?  The
> normal method for manipulating sys.path (PYTHONPATH) is crippled by
> py2exe.
>
> --
> Steve Borho
>



More information about the Mercurial-devel mailing list