Pyroot overrides -h option parsing

Hello everyone!

I am encountering a strange error with pyroot.

I am using an opt-parser in my python script to read in some parameters (see attached minimal working example, which also defines a -h|–help option and others, like -b. Additionally I am including some ROOT classes, e.g. TH1F

import ROOT from ROOT import TH1F

If I call the script with the -b option, it fulfills the desired behaviour

$python -b INFO :: Triggered parameter -b

But if I use the -h paramter to trigger the help for the script, I get the help output from pyroot

[code]$python -h
Usage: python [-l] [-b] [-n] [-q] [dir] [[file:]data.root] [file1.C … fileN.C]
-b : run in batch mode without graphics
-x : exit on exception
-n : do not execute logon and logoff macros as specified in .rootrc
-q : exit after processing command line macro files
-l : do not show splash screen
dir : if dir is a valid directory cd to it before executing

-? : print usage
-h : print usage
–help : print usage
-config : print ./configure options
-memstat : run with memory usage monitoring[/code]

If I uncomment the import of TH1F, the script again runs as it should

$python -h INFO :: Triggered parameter -h

I am using

[code]$which root

$which python
/cvmfs/[/code] (697 Bytes)

I’ve run into this problem as well. Based on [url]How do I tell PyRoot to ignore command line options? the solution is to always import pyroot as follows.

import ROOT
ROOT.PyConfig.IgnoreCommandLineOptions = True

I would recommend adding this line in every module that imports the ROOT namespace. Otherwise, if your main script imports that module before importing ROOT, that module could use a ROOT object before this option is changed, causing the override of “-h” to happen anyways.

This works smoothly, thanks a lot!

[quote=“Mere Interest”]I would recommend adding this line in every module that imports the ROOT namespace.[/quote]If you want this option set for all your local modules, you can also add a local to your code/package, like e.g. so:import imp, sys for path in sys.path: try: modtuple = imp.find_module( 'ROOT', [path] ) except ImportError: pass else: if modtuple and modtuple[1] != __file__: sys.modules[ 'ROOT' ] = imp.load_module( 'ROOT', *modtuple ) break else: raise ImportError( 'ROOT' ) import ROOT ROOT.PyConfig.IgnoreCommandLineOptions = True