|
1 <?xml version="1.0" encoding="UTF-8"?> |
|
2 <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> |
|
3 <plist version="1.0"> |
|
4 <dict> |
|
5 <key>beforeRunningCommand</key> |
|
6 <string>nop</string> |
|
7 <key>command</key> |
|
8 <string>#!/usr/bin/python |
|
9 """Generate code to warn about a module's removal in Python 3.0. |
|
10 |
|
11 XXX Not supported: |
|
12 - Module's in a package do not have their full name generated. |
|
13 - Package's __init__ module; should detect and use the package's name instead. |
|
14 |
|
15 """ |
|
16 py_template = """from warnings import warnpy3k |
|
17 warnpy3k("the ${1:%s} module has been removed in Python 3.0", stacklevel=2) |
|
18 del warnpy3k$0""" |
|
19 |
|
20 c_template = """ |
|
21 if (PyErr_WarnPy3k("the ${1:%s} module has been removed in " |
|
22 "Python 3.0", 2) < 0) |
|
23 return;$0""" |
|
24 |
|
25 |
|
26 import imp |
|
27 import os |
|
28 |
|
29 file_name = os.path.split(os.environ['TM_FILEPATH'])[1] |
|
30 |
|
31 py_suffixes = reversed(sorted((suffix[0] for suffix in imp.get_suffixes() if suffix[2] == imp.PY_SOURCE), key=len)) |
|
32 c_suffixes = reversed(sorted((os.path.splitext(suffix[0])[0] + '.c' |
|
33 for suffix in imp.get_suffixes() if suffix[2] == imp.C_EXTENSION), key=len)) |
|
34 |
|
35 pairings = ((py_suffixes, py_template), (c_suffixes, c_template)) |
|
36 |
|
37 def create_template(suffixes, template): |
|
38 for suffix in suffixes: |
|
39 if not file_name.endswith(suffix): |
|
40 continue |
|
41 module_name = file_name[:-len(suffix)] |
|
42 return template % module_name |
|
43 else: |
|
44 return None |
|
45 |
|
46 for template in (create_template(*pair) for pair in pairings): |
|
47 if not template: |
|
48 continue |
|
49 print template, |
|
50 break |
|
51 else: |
|
52 print 'XXX Could not generate code.'</string> |
|
53 <key>input</key> |
|
54 <string>none</string> |
|
55 <key>name</key> |
|
56 <string>2 to 3 - Module Deletion</string> |
|
57 <key>output</key> |
|
58 <string>insertAsSnippet</string> |
|
59 <key>tabTrigger</key> |
|
60 <string>2to3moddel</string> |
|
61 <key>uuid</key> |
|
62 <string>9519C22B-6AB8-41A1-94F6-079E0B45C147</string> |
|
63 </dict> |
|
64 </plist> |