I am working on writing a custom fixer for lib2to3, not to migrate code to Python 3, but to utilize the source code parsing functionality of lib2to3 rather than manually parsing source with regexs and the like.
I've written a basic fixer at this point, but I am not sure how to actually add this to lib2to3. I only want to use the single fixer, I do not intend to migrate any code to Python 3. This shouldn't be a problem as one can specify that only explicitly passed fixers be used:
2to3 -f fixer_name.py example.py
I could of course just add the fixer to the fixer path:
lib2to3/fixes/
but the script is intended to be distributed as a tool for users to migrate their old source code which uses deprecated import formats. Unfortunately, the documentation for lib2to3 is lacking and the only writeup I have found suggests using the deprecated distribute package.
Any suggestions are welcome, thanks.
Question is answered here included below (basically replicating the 2to3 driver code and passing in your own package path):
my2to3:
#!/usr/bin/env python2.7
import sys
from lib2to3.main import main
sys.path.append('path/to/my_own_package')
sys.exit(main('my_own_package.contained_fixers'))
put fix_my_fixer.py in the package directory and run with
./my2to3 -f my_fixer -w project