summaryrefslogtreecommitdiffstats
path: root/Misc/TextMate/Python-Dev.tmbundle
diff options
context:
space:
mode:
Diffstat (limited to 'Misc/TextMate/Python-Dev.tmbundle')
-rw-r--r--Misc/TextMate/Python-Dev.tmbundle/Commands/2 to 3 - Module Deletion.tmCommand42
-rw-r--r--Misc/TextMate/Python-Dev.tmbundle/info.plist2
2 files changed, 36 insertions, 8 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 31b8837..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
@@ -6,24 +6,50 @@
<string>nop</string>
<key>command</key>
<string>#!/usr/bin/python
+"""Generate code to warn about a module's removal in Python 3.0.
-template = """from warnings import warnpy3k
+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.
+
+"""
+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>
diff --git a/Misc/TextMate/Python-Dev.tmbundle/info.plist b/Misc/TextMate/Python-Dev.tmbundle/info.plist
index 2e0ea9a..644bc7e 100644
--- a/Misc/TextMate/Python-Dev.tmbundle/info.plist
+++ b/Misc/TextMate/Python-Dev.tmbundle/info.plist
@@ -22,10 +22,12 @@
<string>Python-Dev</string>
<key>ordering</key>
<array>
+ <string>9519C22B-6AB8-41A1-94F6-079E0B45C147</string>
<string>B545BB1B-A8E1-426C-B50A-426E78B96D38</string>
<string>6EF151E5-7149-4F82-8796-0CC40FE589FA</string>
<string>FD25A8DC-22DC-4ED4-B222-B943C8A9117D</string>
<string>BF336FFF-E14D-4BF1-A156-71CF768AC034</string>
+ <string>EDBB037F-AAE3-4512-863F-D9AA82C9E51E</string>
</array>
<key>uuid</key>
<string>A932ECD1-D43A-4F57-B7FB-A1CEC3B65D20</string>