command line exception under pythonwin

Bug #952132 reported by Scanferlato
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Bazaar
Confirmed
Medium
Unassigned

Bug Description

This looks like Bug #587868, but is caused by a different reason.

The problem is in win32utils.py line 551. That is, inside function get_unicode_argv() where

command_line = GetCommandLineW()

is assigned the value:

u'"C:\\Python27\\Lib\\site-packages\\pythonwin\\Pythonwin.exe" '

which is different from the value assigned when bzr runs WITHOUT the debugger, i.e.

"C:\Python27\python.exe" "F:\canonical\bzr\bzr\bzr.py" help init

Exception message follows:

PythonWin 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)] on win32.
Portions Copyright 1994-2008 Mark Hammond - see 'Help/About PythonWin' for further copyright information.
>>> bzr: ERROR: exceptions.AssertionError: Split command line can't be shorter than argv

Traceback (most recent call last):
  File "F:\canonical\bzr\bzr\bzrlib\commands.py", line 930, in exception_to_return_code
    return the_callable(*args, **kwargs)
  File "F:\canonical\bzr\bzr\bzrlib\commands.py", line 1037, in run_bzr
    argv = _specified_or_unicode_argv(argv)
  File "F:\canonical\bzr\bzr\bzrlib\commands.py", line 1196, in _specified_or_unicode_argv
    return osutils.get_unicode_argv()
  File "F:\canonical\bzr\bzr\bzrlib\win32utils.py", line 555, in get_unicode_argv
    argv = _command_line_to_argv(command_line, sys.argv)[1:]
  File "F:\canonical\bzr\bzr\bzrlib\win32utils.py", line 530, in _command_line_to_argv
    raise AssertionError("Split command line can't be shorter than argv")
AssertionError: Split command line can't be shorter than argv

bzr 2.6.0dev1 on python 2.7.2 (Windows-XP-5.1.2600-SP3)
arguments: ['F:\\canonical\\bzr\\bzr\\bzr.py', 'help', 'init']
plugins:
encoding: 'cp1252', fsenc: 'mbcs', lang: 'C'

*** Bazaar has encountered an internal error. This probably indicates a
    bug in Bazaar. You can help us fix it by filing a bug report at
        https://bugs.launchpad.net/bzr/+filebug
    including this traceback and a description of the problem.

Jelmer Vernooij (jelmer)
tags: added: win32
Revision history for this message
Alexander Belchenko (bialix) wrote :

So, as I understand it the problem in the fact that you load bzr.py into Pythonwin debugger and then run execution of the script. Therefore, original command-line is invokation of Pythonwin, and we need actually sys.argv.

I can only suggest add some workaround to win32util.py and check for Pythonwin. In that case we should skip all our smart command-line split code and simply use sys.argv.

Maybe Pythonwin created some environment variables we can check instead of create regexp for command-line? Can you check their documentation?

Changed in bzr:
status: New → Confirmed
importance: Undecided → Medium
Revision history for this message
Alexander Belchenko (bialix) wrote :

A quick look into their documentation reveals the following:

Command Line Arguments
The following command line arguments are recognised. Note that these are implemented in "intpyapp.py", so should be pretty easy to change!

/run scriptname args
Runs the named script. Works just like "Python.exe scriptname args", except it is run in the GUI environment, and output goes to the interactive window.

/runargs scriptname args
As above, except the normal Pythonwin 'Run Script' dialog is shown.

I think you should try invoke pythonwin with `/run bzr ...` or `/runargs bzr ...` and see what happens. That could be an easy workaround.

Revision history for this message
Scanferlato (jls-boost) wrote :

Thanks. The workaround works with minor change. Assuming bazaar script is located at

F:\canonical\bzr\bzr\bzr.py,

and needs to run with arguments "help init", the recipe is as follows:

create a link to pythonwin.exe
edit its properties and set:

destination: C:\Python27\Lib\site-packages\pythonwin\Pythonwin.exe F:\canonical\bzr\bzr\bzr.py help init
run from: F:\canonical\bzr\bzr

After Pythonwin starts, in the "Run Script" dialog box set the following:

Script file --> F:\canonical\bzr\bzr\bzr.py
Arguments --> help init
Debugging --> Step-through in the debugger

Finally, click OK to start debugging (see attached picture)

Now the value assigned to variable command_line is:

u'"C:\\Python27\\Lib\\site-packages\\pythonwin\\Pythonwin.exe" F:\\canonical\\bzr\\bzr\\bzr.py help init'

Revision history for this message
Alexander Belchenko (bialix) wrote : Re: [Bug 952132] Re: command line exception under pythonwin

Scanferlato пишет:
> Thanks. The workaround works with minor change.

Does it fixes problem for you? Or do you need to change something in bzr
itself?

Revision history for this message
Scanferlato (jls-boost) wrote :

Yes, problem is fixed. No changes required to Bazaar, but IMHO the exception message could be improved, i.e. one message when running under Pythonwin, and the usual message in all other cases.

Revision history for this message
Alexander Belchenko (bialix) wrote :

I agree about exception message. We'd better raise more specific error in the case if Pythonwin is detected and suggest your workaround. Would you like to provide a patch?

Revision history for this message
Scanferlato (jls-boost) wrote :

You can find the fix here:

lp:~jls-boost/bzr/bug952132

After some testing, the procedure posted in comment #3 needed some changes. The updated version is described here.

As said before, Python is installed in C:\Python27, and path to Pythonwin executable is

C:\Python27\Lib\site-packages\pythonwin\Pythonwin.exe

Bazaar branch is located under path F:\bzr. The script bzr was copied and renamed to bzr.py

To start debugging Bazaar with Pythonwin, open a DOS shell, change to folder F:\bzr and invoke bzr with some command, let's say "help init", so you need to type:

C:\Python27\Lib\site-packages\pythonwin\Pythonwin.exe ./bzr.py help init

Wait until Pythonwin starts up, open the Run Script dialog box (Ctrl-R or menu File, Run), select the options shown below:

Script file --> F:\bzr\bzr.py
Arguments --> arg1 arg2
Debugging --> Step-through in the debugger

and click the OK to start debugging.

Notice that the arguments are "arg1 arg2" and not "help init". In fact, you can name them anything you want because the "real" arguments passed to bzr are always those you type in the DOS shell. The important thing is that the NUMBER of arguments must be the same as in the DOS shell (two, in this example).

Jelmer Vernooij (jelmer)
tags: added: check-for-breezy
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.