summaryrefslogtreecommitdiffstats
path: root/Misc/TextMate
diff options
context:
space:
mode:
authorBrett Cannon <bcannon@gmail.com>2008-05-09 22:52:28 (GMT)
committerBrett Cannon <bcannon@gmail.com>2008-05-09 22:52:28 (GMT)
commitf0a0a0dbb958171ad5a97b7d760bc6ac9cea4607 (patch)
treec851344d823e599d655dfefe1a6c37a8b8e65b25 /Misc/TextMate
parent9ac3974de847a3d94a49b70ee7c6a70eaa43bbf6 (diff)
downloadcpython-f0a0a0dbb958171ad5a97b7d760bc6ac9cea4607.zip
cpython-f0a0a0dbb958171ad5a97b7d760bc6ac9cea4607.tar.gz
cpython-f0a0a0dbb958171ad5a97b7d760bc6ac9cea4607.tar.bz2
Add support for extension modules in 3.0 deprection command.
Diffstat (limited to 'Misc/TextMate')
-rw-r--r--Misc/TextMate/Python-Dev.tmbundle/Commands/2 to 3 - Module Deletion.tmCommand37
1 files changed, 28 insertions, 9 deletions
diff --git a/Misc/TextMate/Python-Dev.tmbundle/Commands/2 to 3 - Module Deletion.tmCommand b/Misc/TextMate/Python-Dev.tmbundle/Commands/2 to 3 - Module Deletion.tmCommand
index c24311f..3cfada8 100644
--- a/Misc/TextMate/Python-Dev.tmbundle/Commands/2 to 3 - Module Deletion.tmCommand
+++ b/Misc/TextMate/Python-Dev.tmbundle/Commands/2 to 3 - Module Deletion.tmCommand
@@ -11,26 +11,45 @@
XXX Not supported:
- Module's in a package do not have their full name generated.
- Package's __init__ module; should detect and use the package's name instead.
-- Extension modules; need to create template.
"""
-template = """from warnings import warnpy3k
+py_template = """from warnings import warnpy3k
warnpy3k("the ${1:%s} module has been removed in Python 3.0", stacklevel=2)
-del warnpy3k
-$0"""
+del warnpy3k$0"""
+
+c_template = """
+if (PyErr_WarnPy3k("the ${1:%s} module has been removed in "
+ "Python 3.0", 2) &lt; 0)
+ return;$0"""
+
import imp
import os
file_name = os.path.split(os.environ['TM_FILEPATH'])[1]
-for suffix in (tuple_[0] for tuple_ in imp.get_suffixes()):
- if not file_name.endswith(suffix):
+
+py_suffixes = reversed(sorted((suffix[0] for suffix in imp.get_suffixes() if suffix[2] == imp.PY_SOURCE), key=len))
+c_suffixes = reversed(sorted((os.path.splitext(suffix[0])[0] + '.c'
+ for suffix in imp.get_suffixes() if suffix[2] == imp.C_EXTENSION), key=len))
+
+pairings = ((py_suffixes, py_template), (c_suffixes, c_template))
+
+def create_template(suffixes, template):
+ for suffix in suffixes:
+ if not file_name.endswith(suffix):
+ continue
+ module_name = file_name[:-len(suffix)]
+ return template % module_name
+ else:
+ return None
+
+for template in (create_template(*pair) for pair in pairings):
+ if not template:
continue
- module_name = file_name[:-len(suffix)]
- print (template % module_name),
+ print template,
break
else:
- print (template % "XXX"),</string>
+ print 'XXX Could not generate code.'</string>
<key>input</key>
<string>none</string>
<key>name</key>