[issue14803] Add -C option to run code at Python startup

2012-05-14 Thread Antoine Pitrou

Antoine Pitrou pit...@free.fr added the comment:

It would be nice to have a comparison of the available alternatives. It's not 
obvious that asking people to type some -C ... boilerplate to get code 
coverage is very user-friendly. Or am I misunderstanding the request?

--
nosy: +pitrou

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue14803
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue14803] Add -C option to run code at Python startup

2012-05-14 Thread Ned Batchelder

Ned Batchelder n...@nedbatchelder.com added the comment:

The difficulty that coverage faces is not measuring python programs started 
from the command line like this, you can use coverage run myprog.py or 
python -m coverage run myprog.py.

The difficulty is when there are subprocesses running python programs.  Read 
http://nedbatchelder.com/code/coverage/subprocess.html for the two current 
hacks used to invoke coverage on subprocesses.  If -C is implemented, it should 
have a PYTHONRUNFIRST environment variable (or the like) to make these hacks 
unnecessary.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue14803
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue14803] Add -C option to run code at Python startup

2012-05-14 Thread Nick Coghlan

New submission from Nick Coghlan ncogh...@gmail.com:

Reading http://nedbatchelder.com/code/coverage/subprocess.html, it occurred to 
me that there are various tracing and profiling operations that could be 
cleanly handled with significantly less work on the part of the 
tracing/profiling tool authors if the interpreter supported a -C operation 
that was like the existing -c option, but *didn't* terminate the options list.

The interpreter would invoke such commands after the interpreter is fully 
initialised, but before it begins the processing to find and execute __main__.

Then, to use subprocess coverage with coverage.py as an example, you could just 
run a command like:

python -C 'import coverage; coverage.process_startup()' worker.py

Other things you could usefully do in such an invocation is reconfigure 
sys.std(in|out|err) to match the settings used on the invoking side (e.g. to 
ensure Unicode data is tunnelled correctly), configure the logging module with 
a custom configuration, configure the warnings module programmatically, enable 
a memory profiler, etc.

Providing a function that could be called from -C and then uses an atexit() 
handler to do any necessary post-processing may be significantly simpler than 
trying to use runpy.run_(path|module) to achieve a similar effect.

--
messages: 160597
nosy: ncoghlan
priority: normal
severity: normal
status: open
title: Add -C option to run code at Python startup

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue14803
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue14803] Add -C option to run code at Python startup

2012-05-14 Thread Nick Coghlan

Changes by Nick Coghlan ncogh...@gmail.com:


--
stage:  - needs patch
type:  - enhancement
versions: +Python 3.3

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue14803
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue14803] Add -C option to run code at Python startup

2012-05-14 Thread Nick Coghlan

Changes by Nick Coghlan ncogh...@gmail.com:


--
components: +Interpreter Core

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue14803
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue14803] Add -C option to run code at Python startup

2012-05-14 Thread Ned Batchelder

Changes by Ned Batchelder n...@nedbatchelder.com:


--
nosy: +nedbat

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue14803
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com