Mercurial > repos > guerler > springsuite
comparison planemo/lib/python3.7/site-packages/libpasteurize/fixes/feature_base.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 Base classes for features that are backwards-incompatible. | |
3 | |
4 Usage: | |
5 features = Features() | |
6 features.add(Feature("py3k_feature", "power< 'py3k' any* >", "2.7")) | |
7 PATTERN = features.PATTERN | |
8 """ | |
9 | |
10 pattern_unformatted = u"%s=%s" # name=pattern, for dict lookups | |
11 message_unformatted = u""" | |
12 %s is only supported in Python %s and above.""" | |
13 | |
14 class Feature(object): | |
15 u""" | |
16 A feature has a name, a pattern, and a minimum version of Python 2.x | |
17 required to use the feature (or 3.x if there is no backwards-compatible | |
18 version of 2.x) | |
19 """ | |
20 def __init__(self, name, PATTERN, version): | |
21 self.name = name | |
22 self._pattern = PATTERN | |
23 self.version = version | |
24 | |
25 def message_text(self): | |
26 u""" | |
27 Format the above text with the name and minimum version required. | |
28 """ | |
29 return message_unformatted % (self.name, self.version) | |
30 | |
31 class Features(set): | |
32 u""" | |
33 A set of features that generates a pattern for the features it contains. | |
34 This set will act like a mapping in that we map names to patterns. | |
35 """ | |
36 mapping = {} | |
37 | |
38 def update_mapping(self): | |
39 u""" | |
40 Called every time we care about the mapping of names to features. | |
41 """ | |
42 self.mapping = dict([(f.name, f) for f in iter(self)]) | |
43 | |
44 @property | |
45 def PATTERN(self): | |
46 u""" | |
47 Uses the mapping of names to features to return a PATTERN suitable | |
48 for using the lib2to3 patcomp. | |
49 """ | |
50 self.update_mapping() | |
51 return u" |\n".join([pattern_unformatted % (f.name, f._pattern) for f in iter(self)]) | |
52 | |
53 def __getitem__(self, key): | |
54 u""" | |
55 Implement a simple mapping to get patterns from names. | |
56 """ | |
57 return self.mapping[key] |