This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: incorrect commands import
Type: Stage:
Components: 2to3 (2.x to 3.x conversion tool) Versions: Python 2.6
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: alejolp, benjamin.peterson
Priority: normal Keywords:

Created on 2009-07-02 13:09 by alejolp, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (7)
msg90010 - (view) Author: Alejandro Santos (alejolp) Date: 2009-07-02 13:09
I'm porting a project to Py3k wich contains a "commands.py" script on
the project's module. 

Inside "a.py" there is an "import commands" statement:

/mymodule/commands.py
/mymodule/a.py

The 2to3 tool replaces the "import commands" and all the "commands"
ocurrences with the word "subprocess".

Is is possible to adapt the fix_imports fixer to detect a local import,
like the fix_import fixer (probably_a_local_import)?
msg90015 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2009-07-02 14:38
What version of 2to3 are you using?
msg90018 - (view) Author: Alejandro Santos (alejolp) Date: 2009-07-02 15:00
The one included on Python 3.1-rc2.
msg90019 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2009-07-02 15:22
Oh, I see the problem. mymodule/ isn't a package. If it has __init__.py,
this should work.
msg90021 - (view) Author: Alejandro Santos (alejolp) Date: 2009-07-02 15:28
Sorry. Yes, there is an "__init__.py" script on the same level as the
"commands.py". I forgot to mention it.

/mymodule/commands.py
/mymodule/a.py
/mymodule/__init__.py

This is the real repository:

http://selenic.com/repo/hg/file/b81baf9e4dd6/mercurial
msg90022 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2009-07-02 15:59
Thanks for the bug report! Fixed in r73771. Now when I run it on
mercurial/dispatch.py I get:

--- mercurial/dispatch.py (original)
+++ mercurial/dispatch.py (refactored)
@@ -5,11 +5,11 @@
 # This software may be used and distributed according to the terms of the
 # GNU General Public License version 2, incorporated herein by reference.
 
-from i18n import _
+from .i18n import _
 import os, sys, atexit, signal, pdb, socket, errno, shlex, time
-import util, commands, hg, fancyopts, extensions, hook, error
-import cmdutil, encoding
-import ui as _ui
+from . import util, commands, hg, fancyopts, extensions, hook, error
+from . import cmdutil, encoding
+from . import ui as _ui
 
 def run():
     "run the command in sys.argv"
@@ -486,7 +486,7 @@
             p.disable()
 
             if format == 'kcachegrind':
-                import lsprofcalltree
+                from . import lsprofcalltree
                 calltree = lsprofcalltree.KCacheGrind(p)
                 calltree.output(ostream)
             else:
RefactoringTool: Files that need to be modified:
RefactoringTool: mercurial/dispatch.py

Much better. :)

I'm glad to see someone is working on porting mercurial. You might want
to use the 2to3 development version, since it's always up to date wiht
bug fixes. [1] If you need any help, feel free to email the
python-porting list.

[1] http://svn.python.org/projects/sandbox/trunk/2to3
msg90023 - (view) Author: Alejandro Santos (alejolp) Date: 2009-07-02 16:02
Thanks!
History
Date User Action Args
2022-04-11 14:56:50adminsetgithub: 50649
2009-07-02 16:02:56alejolpsetmessages: + msg90023
2009-07-02 15:59:46benjamin.petersonsetstatus: open -> closed
resolution: fixed
2009-07-02 15:59:18benjamin.petersonsetmessages: + msg90022
2009-07-02 15:28:08alejolpsetmessages: + msg90021
2009-07-02 15:22:02benjamin.petersonsetmessages: + msg90019
2009-07-02 15:00:25alejolpsetmessages: + msg90018
2009-07-02 14:38:03benjamin.petersonsetnosy: + benjamin.peterson
messages: + msg90015
2009-07-02 13:09:37alejolpcreate