[RFC] fake editor for testing edit_commit_message

John Arbash Meinel john at arbash-meinel.com
Thu Jan 5 00:01:12 GMT 2006


Alexander Belchenko wrote:
> John Arbash Meinel пишет:
> 
>> Alexander Belchenko wrote:
>>
>>> I've got WindowsError in subprocess.py when I'm trying to do commit. I
>>> don't understand why. Fully qualfied path to script also does not
>>> help. :-(
>>
>>
>> I think the problem is that it is trying to spawn a program named
>> "python fed.py" not a program "python" feeding it the argument "fed.py".
>> This is definitely a tricky thing to do on windows, since windows
>> doesn't support having executable scripts (other than .bat files).
>> I suppose you could do:
>>
>> echo '@echo off' > test.bat
>> echo 'python fed.py' >> test.bat
>> And then use
>> set BZR_EDITOR='test.bat'
> 
> 
> Hmm. It seems working solution. I'm trying to use batch wrapper but
> without visible success. But this one is working:
> 
> echo @echo off > fed.bat
> echo python fed.py %1 >> fed.bat
> 
> But what about Linux systems? For Linux it should be fed.sh script,
> isn't? If I simply create in test directory fed.bat or fed.sh depending
> on what current OS is it will enough? Probably for Linux it should be
> setting executable permission bit. I'm no Linux expert so someone help
> is needed.

For anything but windows (including cygwin), you can put this as the
first line:
#!/usr/bin/env python

And then chmod 755 the file. I suppose if you wanted to be pedantic you
should do:

f = open('fed.py', 'wb)
f.write('#!')
f.write(sys.executable)
f.write('\n')
f.write(text_for_fed.py)
f.close()
os.chmod('fed.py', 0755)

You can see what I did in the ExternalCommand tests.

> 
>> We also can't just split based on whitespace, especially on windows,
>> where you have "C:\Program Files\..."
> 
> 
> Hmm... Looks on this code (msgeditor.py:: _run_editor() function):
> 
> def _run_editor(filename):
>     """Try to execute an editor to edit the commit message."""
>     for e in _get_editor():
>         edargs = e.split(' ')          # <<<<<<< HERE SPLIT ON SPACE
>         x = call(edargs + [filename])
>         if x == 0:
>             return True
>         elif x == 127:
>             continue
>         else:
>             break
>     raise BzrError("Could not start any editor. "
>                    "Please specify $EDITOR or use ~/.bzr.conf/editor")
> 
> 
> Probably this split is incorrect?

Well, to me it is incorrect. But I'm not really sure what is correct.
Because you have the problem that EDITOR might need arguments passed to it.
For example EDITOR='gvim -f', which will spawn the gui, but tell it not
to release the terminal.

So maybe the specific problem on Windows was that when you gave it just
'python', python isn't in your default path, and when you gave it the
full path, it had spaces in the path.

> 
> 
>>> 1) Is this `fed` is appropriate for using as part of selftest for
>>> testing bzrlib/msgeditor.py::edit_commit_message() function?
> 
> 
>> The problem is now bzr selftest requires that you have a working
>> compiler, and that we know what it is. (cl, icc, gcc, mingw, etc)
> 
> 
> That's why I want to use SCons.

Scons is great (I use it myself), but it is an even bigger (or at least
less common) than having a working compiler.

> 
>> If we can stay with python, it would be greatly prefered. We require
>> python, and it would be nice to not require other dependencies (yet :).
> 
> 
> I'm +1 and +1 on this. May be I hasten to write C-program. I will try
> another one fed with batch file.
> 
> Thanks for the reply.
> 
> -- 
> Alexander
> 

Hopefully we can get a batch script to work properly.
As I mentioned you probably want to use sys.executable rather than just
a bare 'python'. Because sys.executable should be the full path to the file.

Oh, and on linux, you'll probably need './fed.py' so that it will run
the one in the current directory. While on windows you can't used
forward slashes for executable names. (It defaults to including the
local directory in the search path, but I think .\fed.bat would work)

John
=:->

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 256 bytes
Desc: OpenPGP digital signature
Url : https://lists.ubuntu.com/archives/bazaar/attachments/20060104/3f238188/attachment.pgp 


More information about the bazaar mailing list