<div class="gmail_quote">On Tue, Jun 21, 2011 at 9:27 AM, Tarek Ziadé <span dir="ltr">&lt;<a href="mailto:ziade.tarek@gmail.com" target="_blank">ziade.tarek@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">


<div>On Tue, Jun 21, 2011 at 3:12 PM, R. David Murray &lt;<a href="mailto:rdmurray@bitdance.com" target="_blank">rdmurray@bitdance.com</a>&gt; wrote:<br>
&gt; On Tue, 21 Jun 2011 13:42:05 +0200, =?ISO-8859-1?Q?Tarek_Ziad=E9?= &lt;<a href="mailto:ziade.tarek@gmail.com" target="_blank">ziade.tarek@gmail.com</a>&gt; wrote:<br>
&gt;&gt; Before I start to write my own refactoring tool, I was wondering if<br>
&gt;&gt; anyone here had some experience in this, and could give me some hints.<br>
&gt;<br>
&gt; Coul you could just write a 3to2 fixer?  I don&#39;t know how hard it is to<br>
&gt; run just a selected set of fixers (so that you could use it to generate<br>
&gt; python3 code), but it seems to me that renaming modules is something<br>
&gt; that 3to2 (and 2to3, of course) should be good at.<br>
<br>
</div>The one thing rope is good at is to find where a given variable name<br>
is used, and rename all occurrences recursively. So basically, when<br>
you rename an import, it renames all the code that uses it.<br>
<br>
I don&#39;t really know how 2to3/3to2 work but I assumed that it does not<br>
do this, but simply give you a hook for every visited node. IOW that<br>
looking for dependencies is to be done<br>
<br>
Cheers<br>
<font color="#888888">Tarek<br>
</font><div><br>
&gt;<br>
&gt; --<br>
&gt; R. David Murray           <a href="http://www.bitdance.com" target="_blank">http://www.bitdance.com</a><br>
&gt;<br>
<br>
<br>
<br>
</div><div>--<br>
Tarek Ziadé | <a href="http://ziade.org" target="_blank">http://ziade.org</a></div></blockquote><div><br></div><div>Yes, 2to3/3to2 does not do anything fancy like that.  The tools are purely concerned with syntax, whereas renaming imports is semantic.  The good news is that this line:</div>


<div><br></div><div><font face="&#39;courier new&#39;, monospace">import packaging as _myPackaging</font></div><div><br></div><div>can be replaced by:</div><div><br></div><div><font face="&#39;courier new&#39;, monospace">import distutils2 as _myPackaging</font></div>


<div><br></div><div>and code that uses _myPackaging will work.  I&#39;ve attached a fixer that can go into your lib3to2/fixes folder.  You should also edit fix_imports.py and add the line:</div><div><br></div><div><font face="&#39;courier new&#39;, monospace">&quot;packaging&quot; : &quot;distutils2&quot;,</font></div>


<div><br></div><div>to the MAPPING dictionary near the top, then you can run 3to2 like this:</div><div><br></div><div><font face="&#39;courier new&#39;, monospace">3to2 -fpackaging -fimports files_to_fix.py</font></div>
<div><br></div><div>(-w option to write changes to the files modified)</div><div><br></div><div>Hope this helps,</div><div>--Joe Amenta</div></div>