tags:

views:

37

answers:

3

I have a python code base and want to know whether pyxml is really used in the code any where. The python version i have is 2.6. pyxml's last binary distribution ended with 2.4 python version. Any clues or ideas to judge the code whether it is free of pyxml 0.8.4 on python 2.6 ?

Thanks in Advance.

+1  A: 

grep your codebase for from xml import or import xml.

Johnsyweb
A: 

Search pyxml.py (or .pyc or similar). Rename it to something else say pyxmltest.py. See if it something crashes or if you want to be more sure and more gentle. Put in the same place file pyxml.py:

print('pyxml imported')
import pyxmltest.py

After test remove the test file and rename back the original.

Alternatively you could put the same print in the beginning of the actual module if it is written in python (plain .py)

Also some editors like IDLE has search in files function where you can search for pyxml. It works recursively in subdirectories.

Tony Veijalainen
Thanks to all for sharing the info. The interesting thing is that pyxml gets the priority when simple xml modules are used. On a plane machine, if there is no pyxml installed, and the code uses xml modules, it goes to Lib/xml where as when pyxml is installed, it tries to use Lib/site-packages/_xmlplus. I did grep for "from xml" in my code base, and verified whether the actual class or module that is getting imported is a standard xml module or pyxml.
narayana
+2  A: 

When you run

python -v script.py

Python prints all the modules imported to stderr. You can then inspect that output for the string "import pyxml":

python -v script.py 2>&1 | grep "import pyxml"

This works even if script.py imported pyxml in an unconventional way, such as __import__('pyxml').

It even works if the import were buried inside of a function:

def foo():
    import pyxml
    ...

provided that function eventually gets called.

unutbu