Mercurial > repos > guerler > springsuite
comparison planemo/lib/python3.7/site-packages/libpasteurize/fixes/fix_features.py @ 1:56ad4e20f292 draft
"planemo upload commit 6eee67778febed82ddd413c3ca40b3183a3898f1"
author | guerler |
---|---|
date | Fri, 31 Jul 2020 00:32:28 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
0:d30785e31577 | 1:56ad4e20f292 |
---|---|
1 u""" | |
2 Warn about features that are not present in Python 2.5, giving a message that | |
3 points to the earliest version of Python 2.x (or 3.x, if none) that supports it | |
4 """ | |
5 | |
6 from .feature_base import Feature, Features | |
7 from lib2to3 import fixer_base | |
8 | |
9 FEATURES = [ | |
10 #(FeatureName, | |
11 # FeaturePattern, | |
12 # FeatureMinVersion, | |
13 #), | |
14 (u"memoryview", | |
15 u"power < 'memoryview' trailer < '(' any* ')' > any* >", | |
16 u"2.7", | |
17 ), | |
18 (u"numbers", | |
19 u"""import_from< 'from' 'numbers' 'import' any* > | | |
20 import_name< 'import' ('numbers' dotted_as_names< any* 'numbers' any* >) >""", | |
21 u"2.6", | |
22 ), | |
23 (u"abc", | |
24 u"""import_name< 'import' ('abc' dotted_as_names< any* 'abc' any* >) > | | |
25 import_from< 'from' 'abc' 'import' any* >""", | |
26 u"2.6", | |
27 ), | |
28 (u"io", | |
29 u"""import_name< 'import' ('io' dotted_as_names< any* 'io' any* >) > | | |
30 import_from< 'from' 'io' 'import' any* >""", | |
31 u"2.6", | |
32 ), | |
33 (u"bin", | |
34 u"power< 'bin' trailer< '(' any* ')' > any* >", | |
35 u"2.6", | |
36 ), | |
37 (u"formatting", | |
38 u"power< any trailer< '.' 'format' > trailer< '(' any* ')' > >", | |
39 u"2.6", | |
40 ), | |
41 (u"nonlocal", | |
42 u"global_stmt< 'nonlocal' any* >", | |
43 u"3.0", | |
44 ), | |
45 (u"with_traceback", | |
46 u"trailer< '.' 'with_traceback' >", | |
47 u"3.0", | |
48 ), | |
49 ] | |
50 | |
51 class FixFeatures(fixer_base.BaseFix): | |
52 | |
53 run_order = 9 # Wait until all other fixers have run to check for these | |
54 | |
55 # To avoid spamming, we only want to warn for each feature once. | |
56 features_warned = set() | |
57 | |
58 # Build features from the list above | |
59 features = Features([Feature(name, pattern, version) for \ | |
60 name, pattern, version in FEATURES]) | |
61 | |
62 PATTERN = features.PATTERN | |
63 | |
64 def match(self, node): | |
65 to_ret = super(FixFeatures, self).match(node) | |
66 # We want the mapping only to tell us the node's specific information. | |
67 try: | |
68 del to_ret[u'node'] | |
69 except Exception: | |
70 # We want it to delete the 'node' from the results | |
71 # if it's there, so we don't care if it fails for normal reasons. | |
72 pass | |
73 return to_ret | |
74 | |
75 def transform(self, node, results): | |
76 for feature_name in results: | |
77 if feature_name in self.features_warned: | |
78 continue | |
79 else: | |
80 curr_feature = self.features[feature_name] | |
81 if curr_feature.version >= u"3": | |
82 fail = self.cannot_convert | |
83 else: | |
84 fail = self.warning | |
85 fail(node, reason=curr_feature.message_text()) | |
86 self.features_warned.add(feature_name) |