On 21/01/2010 21:08, Daniel Harding wrote:
Jonathan Hartley wrote:
Hi,

I didn't see anyone follow up on Daniel Harding's assertion that his adapted pylint.bat fix could be improved to "detect and remove the --exitcode parameter from any position in the argument list." Has anyone done any work on this?

I could implement this if anyone wants it - the main reason I required
it to be the first option is that it is not context-sensitive with
regards to the other arguments - it wouldn't work in the extraordinary
edge case that "--exitcode" was a modifier for another argument in the
argument list.  However, either way of implementing the batch file
argument parsing is much more complicated than the approach you have
proposed below, which has the added bonus that it Just Works without
having to mess with any additional command line arguments.

I'm no batch file expert, but I just discovered an alternative solution which may be a better because it doesn't require introducing a new command-line switch.


SUMMARY

Replace the current pylint.bat with:

    @echo off
    python "%~dp0%~n0-script.py" %*

This just executes the file pylint-script.py, in the same directory. This is a new file:

    import sys
    from pylint import lint
    lint.Run(sys.argv[1:])

The result will execute pylint without ever exiting the current shell, and will always propagate the exit value from lint.Run() back to the invoker as a process exit value. As a bonus, despite introducing an extra .py file, this seems a much tidier and more understandable mechanism than the existing pylint.bat.

Am I overlooking something? Thoughts and criticism much appreciated.

Great thinking.  Sometimes it is easy to get sidetracked trying to make
something complicated work, when a much more straightforward solution
would do just as well if not better.

I would make one improvement on what you have, and simply pass the code
to python using the -c command line option.  This removes the need for
an additional file.  pylint.bat then becomes:


    @echo off
python -c "import sys; from pylint import lint; lint.Run(sys.argv[1:])" %*


Genius. By jove, I think we've cracked it. :-)

If no-one points out any outrageous idiocy in this idea then I'll see if I can put together a patch to submit, if that's helpful. Please be gentle with me as I do so, since I am a bear of little brain.

Thanks, Daniel, for explaining the sys.exit behaviour that was befuddling me.

    Jonathan

Jonathan Hartley      Made of meat.      http://tartley.com
tart...@tartley.com   +44 7737 062 225   twitter/skype: tartley



_______________________________________________
Python-Projects mailing list
Python-Projects@lists.logilab.org
http://lists.logilab.org/mailman/listinfo/python-projects

Reply via email to