I wrote own fixer, how can i run it? I don't find obvious way to do this.
Only this:
> cd /usr/lib/python2.7/lib2to3/fixes/
> ln -s path/to/my_fixer.py
And then run it:
> cd path/to/project
> 2to3 -f my_fixer .
I wrote own fixer, how can i run it? I don't find obvious way to do this.
Only this:
> cd /usr/lib/python2.7/lib2to3/fixes/
> ln -s path/to/my_fixer.py
And then run it:
> cd path/to/project
> 2to3 -f my_fixer .
I got it! (file: 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'))
And then run it:
> ./my2to3 -f my_fixer -w project
/mypath/custom_fixers
Generate a file /mypath/custom_fixers/fix_custom_fixers.py
with this content:
from lib2to3.fixer_base import BaseFix
from lib2to3.pgen2 import token
class FixCustomFixers(BaseFix):
_accept_type = token.NAME
def match(self, node):
if node.value == 'oldname':
return True
return False
def transform(self, node, results):
node.value = 'newname'
node.changed()
Create a file /mypath/myfixer.py
with this content:
import sys
from lib2to3.main import main
sys.exit(main('custom_fixers'))
Run PYTHONPATH=/mypath python3 /mypath/myfixer.py -f custom_fixers python_file_to_fix.py