aridity 69__tar.gz → 70__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- aridity-69/README.md → aridity-70/PKG-INFO +14 -19
- aridity-69/aridity.egg-info/PKG-INFO → aridity-70/README.md +2 -32
- aridity-70/aridity/__init__.py +18 -0
- {aridity-69 → aridity-70}/aridity/arid_config.py +0 -17
- {aridity-69 → aridity-70}/aridity/config.py +2 -18
- {aridity-69 → aridity-70}/aridity/directives.py +2 -18
- {aridity-69 → aridity-70}/aridity/functions.py +0 -20
- {aridity-69 → aridity-70}/aridity/grammar.py +0 -17
- {aridity-69 → aridity-70}/aridity/keyring.py +0 -17
- {aridity-69 → aridity-70}/aridity/model.py +6 -19
- aridity-70/aridity/processtemplate.py +13 -0
- {aridity-69 → aridity-70}/aridity/repl.py +0 -17
- {aridity-69 → aridity-70}/aridity/scope.py +15 -77
- aridity-70/aridity/search.py +59 -0
- {aridity-69 → aridity-70}/aridity/stacks.py +0 -17
- {aridity-69 → aridity-70}/aridity/util.py +0 -17
- {aridity-69 → aridity-70/aridity.egg-info}/PKG-INFO +5 -23
- {aridity-69 → aridity-70}/aridity.egg-info/SOURCES.txt +1 -1
- {aridity-69 → aridity-70}/setup.py +3 -55
- aridity-69/COPYING +0 -674
- aridity-69/aridity/__init__.py +0 -35
- aridity-69/aridity/processtemplate.py +0 -30
- {aridity-69 → aridity-70}/aridity.egg-info/dependency_links.txt +0 -0
- {aridity-69 → aridity-70}/aridity.egg-info/entry_points.txt +0 -0
- {aridity-69 → aridity-70}/aridity.egg-info/requires.txt +0 -0
- {aridity-69 → aridity-70}/aridity.egg-info/top_level.txt +0 -0
- {aridity-69 → aridity-70}/setup.cfg +0 -0
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: aridity
|
|
3
|
+
Version: 70
|
|
4
|
+
Summary: DRY config and template system, easily extensible with Python
|
|
5
|
+
Home-page: UNKNOWN
|
|
6
|
+
Author: foyono
|
|
7
|
+
License: UNKNOWN
|
|
8
|
+
Platform: UNKNOWN
|
|
9
|
+
Description-Content-Type: text/markdown
|
|
10
|
+
|
|
1
11
|
# aridity
|
|
2
12
|
DRY config and template system, easily extensible with Python
|
|
3
13
|
|
|
@@ -24,12 +34,12 @@ DRY config and template system, easily extensible with Python
|
|
|
24
34
|
* Often tools/libraries must be configured using config files
|
|
25
35
|
* Support for config file interpolation is not enough to stay DRY, and comes with a different set of gotchas per tool
|
|
26
36
|
* In particular Helm/Terraform have their own ways of sharing config between envs
|
|
27
|
-
* aridity is a general purpose solution for all the above, also see [soak](https://
|
|
37
|
+
* aridity is a general purpose solution for all the above, also see [soak](https://pypi.org/project/soak/)
|
|
28
38
|
|
|
29
39
|
## Config API
|
|
30
40
|
* Normally you pass around a Config object, and application code can get data out via attribute access e.g. config.foo.bar
|
|
31
41
|
* Here config.foo is also a Config object, a child scope of config named foo
|
|
32
|
-
* The passing around can be taken care of by a dependency injection container such as [diapyr](https://
|
|
42
|
+
* The passing around can be taken care of by a dependency injection container such as [diapyr](https://pypi.org/project/diapyr/)
|
|
33
43
|
* Every Config has an associated ConfigCtrl on which Python API such as processtemplate is available
|
|
34
44
|
* Use negation to get ConfigCtrl when you have a Config e.g. (-config).processtemplate(...)
|
|
35
45
|
* Use the node attribute to get Config when you have a ConfigCtrl, this is a rare situation in practice
|
|
@@ -69,23 +79,6 @@ venvname/bin/pip install aridity
|
|
|
69
79
|
. venvname/bin/activate
|
|
70
80
|
```
|
|
71
81
|
|
|
72
|
-
### To develop
|
|
73
|
-
First clone the repo using HTTP or SSH:
|
|
74
|
-
```
|
|
75
|
-
git clone https://github.com/combatopera/aridity.git
|
|
76
|
-
git clone git@github.com:combatopera/aridity.git
|
|
77
|
-
```
|
|
78
|
-
Now use pyven's pipify to create a setup.py, which pip can then use to install the project editably:
|
|
79
|
-
```
|
|
80
|
-
python3 -m venv pyvenvenv
|
|
81
|
-
pyvenvenv/bin/pip install pyven
|
|
82
|
-
pyvenvenv/bin/pipify aridity
|
|
83
|
-
|
|
84
|
-
python3 -m venv venvname
|
|
85
|
-
venvname/bin/pip install -e aridity
|
|
86
|
-
. venvname/bin/activate
|
|
87
|
-
```
|
|
88
|
-
|
|
89
82
|
## Config file syntax
|
|
90
83
|
```
|
|
91
84
|
: Until aridity gets support for comments, you can use the colon directive to ignore data.
|
|
@@ -226,3 +219,5 @@ Interactive REPL.
|
|
|
226
219
|
|
|
227
220
|
### processtemplate
|
|
228
221
|
Process the given template to stdout using config from stdin.
|
|
222
|
+
|
|
223
|
+
|
|
@@ -1,14 +1,3 @@
|
|
|
1
|
-
Metadata-Version: 2.1
|
|
2
|
-
Name: aridity
|
|
3
|
-
Version: 69
|
|
4
|
-
Summary: DRY config and template system, easily extensible with Python
|
|
5
|
-
Home-page: https://github.com/combatopera/aridity
|
|
6
|
-
Author: Andrzej Cichocki
|
|
7
|
-
License: UNKNOWN
|
|
8
|
-
Platform: UNKNOWN
|
|
9
|
-
Description-Content-Type: text/markdown
|
|
10
|
-
License-File: COPYING
|
|
11
|
-
|
|
12
1
|
# aridity
|
|
13
2
|
DRY config and template system, easily extensible with Python
|
|
14
3
|
|
|
@@ -35,12 +24,12 @@ DRY config and template system, easily extensible with Python
|
|
|
35
24
|
* Often tools/libraries must be configured using config files
|
|
36
25
|
* Support for config file interpolation is not enough to stay DRY, and comes with a different set of gotchas per tool
|
|
37
26
|
* In particular Helm/Terraform have their own ways of sharing config between envs
|
|
38
|
-
* aridity is a general purpose solution for all the above, also see [soak](https://
|
|
27
|
+
* aridity is a general purpose solution for all the above, also see [soak](https://pypi.org/project/soak/)
|
|
39
28
|
|
|
40
29
|
## Config API
|
|
41
30
|
* Normally you pass around a Config object, and application code can get data out via attribute access e.g. config.foo.bar
|
|
42
31
|
* Here config.foo is also a Config object, a child scope of config named foo
|
|
43
|
-
* The passing around can be taken care of by a dependency injection container such as [diapyr](https://
|
|
32
|
+
* The passing around can be taken care of by a dependency injection container such as [diapyr](https://pypi.org/project/diapyr/)
|
|
44
33
|
* Every Config has an associated ConfigCtrl on which Python API such as processtemplate is available
|
|
45
34
|
* Use negation to get ConfigCtrl when you have a Config e.g. (-config).processtemplate(...)
|
|
46
35
|
* Use the node attribute to get Config when you have a ConfigCtrl, this is a rare situation in practice
|
|
@@ -80,23 +69,6 @@ venvname/bin/pip install aridity
|
|
|
80
69
|
. venvname/bin/activate
|
|
81
70
|
```
|
|
82
71
|
|
|
83
|
-
### To develop
|
|
84
|
-
First clone the repo using HTTP or SSH:
|
|
85
|
-
```
|
|
86
|
-
git clone https://github.com/combatopera/aridity.git
|
|
87
|
-
git clone git@github.com:combatopera/aridity.git
|
|
88
|
-
```
|
|
89
|
-
Now use pyven's pipify to create a setup.py, which pip can then use to install the project editably:
|
|
90
|
-
```
|
|
91
|
-
python3 -m venv pyvenvenv
|
|
92
|
-
pyvenvenv/bin/pip install pyven
|
|
93
|
-
pyvenvenv/bin/pipify aridity
|
|
94
|
-
|
|
95
|
-
python3 -m venv venvname
|
|
96
|
-
venvname/bin/pip install -e aridity
|
|
97
|
-
. venvname/bin/activate
|
|
98
|
-
```
|
|
99
|
-
|
|
100
72
|
## Config file syntax
|
|
101
73
|
```
|
|
102
74
|
: Until aridity gets support for comments, you can use the colon directive to ignore data.
|
|
@@ -237,5 +209,3 @@ Interactive REPL.
|
|
|
237
209
|
|
|
238
210
|
### processtemplate
|
|
239
211
|
Process the given template to stdout using config from stdin.
|
|
240
|
-
|
|
241
|
-
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
'Interactive REPL.'
|
|
2
|
+
from .model import Stream
|
|
3
|
+
from .repl import Repl
|
|
4
|
+
from .scope import Scope
|
|
5
|
+
from .util import NoSuchPathException
|
|
6
|
+
import sys
|
|
7
|
+
|
|
8
|
+
assert NoSuchPathException
|
|
9
|
+
|
|
10
|
+
def main():
|
|
11
|
+
scope = Scope()
|
|
12
|
+
scope['stdout',] = Stream(sys.stdout)
|
|
13
|
+
with Repl(scope, True) as repl:
|
|
14
|
+
for line in sys.stdin:
|
|
15
|
+
repl(line)
|
|
16
|
+
|
|
17
|
+
if '__main__' == __name__:
|
|
18
|
+
main()
|
|
@@ -1,20 +1,3 @@
|
|
|
1
|
-
# Copyright 2017, 2020 Andrzej Cichocki
|
|
2
|
-
|
|
3
|
-
# This file is part of aridity.
|
|
4
|
-
#
|
|
5
|
-
# aridity is free software: you can redistribute it and/or modify
|
|
6
|
-
# it under the terms of the GNU General Public License as published by
|
|
7
|
-
# the Free Software Foundation, either version 3 of the License, or
|
|
8
|
-
# (at your option) any later version.
|
|
9
|
-
#
|
|
10
|
-
# aridity is distributed in the hope that it will be useful,
|
|
11
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13
|
-
# GNU General Public License for more details.
|
|
14
|
-
#
|
|
15
|
-
# You should have received a copy of the GNU General Public License
|
|
16
|
-
# along with aridity. If not, see <http://www.gnu.org/licenses/>.
|
|
17
|
-
|
|
18
1
|
'Print given config (with optional path in config) as shell snippet.'
|
|
19
2
|
from .model import Boolean, Entry, Locator, Number, Text
|
|
20
3
|
from .scope import Scope
|
|
@@ -1,23 +1,7 @@
|
|
|
1
|
-
# Copyright 2017, 2020 Andrzej Cichocki
|
|
2
|
-
|
|
3
|
-
# This file is part of aridity.
|
|
4
|
-
#
|
|
5
|
-
# aridity is free software: you can redistribute it and/or modify
|
|
6
|
-
# it under the terms of the GNU General Public License as published by
|
|
7
|
-
# the Free Software Foundation, either version 3 of the License, or
|
|
8
|
-
# (at your option) any later version.
|
|
9
|
-
#
|
|
10
|
-
# aridity is distributed in the hope that it will be useful,
|
|
11
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13
|
-
# GNU General Public License for more details.
|
|
14
|
-
#
|
|
15
|
-
# You should have received a copy of the GNU General Public License
|
|
16
|
-
# along with aridity. If not, see <http://www.gnu.org/licenses/>.
|
|
17
|
-
|
|
18
1
|
from .model import Entry, Function, Locator, Number, Resource, Scalar, Stream, Text, wrap
|
|
19
2
|
from .repl import Repl
|
|
20
3
|
from .scope import Scope
|
|
4
|
+
from .search import resolvedscopeornone
|
|
21
5
|
from .util import CycleException, dotpy, NoSuchPathException, qualname, selectentrypoints, solo
|
|
22
6
|
from functools import partial
|
|
23
7
|
from itertools import chain
|
|
@@ -143,7 +127,7 @@ class ConfigCtrl:
|
|
|
143
127
|
|
|
144
128
|
def scope(self, strict = False):
|
|
145
129
|
if strict:
|
|
146
|
-
s = self.basescope
|
|
130
|
+
s = resolvedscopeornone(self.basescope, self.prefix)
|
|
147
131
|
if s is None:
|
|
148
132
|
raise ForeignScopeException
|
|
149
133
|
return s
|
|
@@ -1,21 +1,5 @@
|
|
|
1
|
-
# Copyright 2017, 2020 Andrzej Cichocki
|
|
2
|
-
|
|
3
|
-
# This file is part of aridity.
|
|
4
|
-
#
|
|
5
|
-
# aridity is free software: you can redistribute it and/or modify
|
|
6
|
-
# it under the terms of the GNU General Public License as published by
|
|
7
|
-
# the Free Software Foundation, either version 3 of the License, or
|
|
8
|
-
# (at your option) any later version.
|
|
9
|
-
#
|
|
10
|
-
# aridity is distributed in the hope that it will be useful,
|
|
11
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13
|
-
# GNU General Public License for more details.
|
|
14
|
-
#
|
|
15
|
-
# You should have received a copy of the GNU General Public License
|
|
16
|
-
# along with aridity. If not, see <http://www.gnu.org/licenses/>.
|
|
17
|
-
|
|
18
1
|
from .model import Stream, Text
|
|
2
|
+
from .search import resolvedscopeornone
|
|
19
3
|
import os, sys
|
|
20
4
|
|
|
21
5
|
class Precedence:
|
|
@@ -60,7 +44,7 @@ class Source:
|
|
|
60
44
|
# XXX: Use full algo to get phrasescope?
|
|
61
45
|
phrasescope = scope
|
|
62
46
|
for word in prefix.topath(scope):
|
|
63
|
-
s =
|
|
47
|
+
s = resolvedscopeornone(phrasescope, [word])
|
|
64
48
|
if s is None:
|
|
65
49
|
break
|
|
66
50
|
phrasescope = s
|
|
@@ -1,20 +1,3 @@
|
|
|
1
|
-
# Copyright 2017, 2020 Andrzej Cichocki
|
|
2
|
-
|
|
3
|
-
# This file is part of aridity.
|
|
4
|
-
#
|
|
5
|
-
# aridity is free software: you can redistribute it and/or modify
|
|
6
|
-
# it under the terms of the GNU General Public License as published by
|
|
7
|
-
# the Free Software Foundation, either version 3 of the License, or
|
|
8
|
-
# (at your option) any later version.
|
|
9
|
-
#
|
|
10
|
-
# aridity is distributed in the hope that it will be useful,
|
|
11
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13
|
-
# GNU General Public License for more details.
|
|
14
|
-
#
|
|
15
|
-
# You should have received a copy of the GNU General Public License
|
|
16
|
-
# along with aridity. If not, see <http://www.gnu.org/licenses/>.
|
|
17
|
-
|
|
18
1
|
from __future__ import division
|
|
19
2
|
from .model import Boolean, Number, Resource, Text, wrap
|
|
20
3
|
from .util import allfunctions, dotpy, NoSuchPathException, realname
|
|
@@ -153,9 +136,6 @@ class Functions:
|
|
|
153
136
|
def str(scope, resolvable):
|
|
154
137
|
return resolvable.resolve(scope).totext()
|
|
155
138
|
|
|
156
|
-
def java(scope, resolvable):
|
|
157
|
-
return resolvable.resolve(scope).tojava()
|
|
158
|
-
|
|
159
139
|
def list(scope, *resolvables):
|
|
160
140
|
v = scope.createchild(islist = True)
|
|
161
141
|
for r in resolvables:
|
|
@@ -1,20 +1,3 @@
|
|
|
1
|
-
# Copyright 2017, 2020 Andrzej Cichocki
|
|
2
|
-
|
|
3
|
-
# This file is part of aridity.
|
|
4
|
-
#
|
|
5
|
-
# aridity is free software: you can redistribute it and/or modify
|
|
6
|
-
# it under the terms of the GNU General Public License as published by
|
|
7
|
-
# the Free Software Foundation, either version 3 of the License, or
|
|
8
|
-
# (at your option) any later version.
|
|
9
|
-
#
|
|
10
|
-
# aridity is distributed in the hope that it will be useful,
|
|
11
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13
|
-
# GNU General Public License for more details.
|
|
14
|
-
#
|
|
15
|
-
# You should have received a copy of the GNU General Public License
|
|
16
|
-
# along with aridity. If not, see <http://www.gnu.org/licenses/>.
|
|
17
|
-
|
|
18
1
|
from .model import Blank, Boolean, Boundary, Call, Concat, Entry, nullmonitor, Number, Text
|
|
19
2
|
from decimal import Decimal
|
|
20
3
|
from functools import partial, reduce
|
|
@@ -1,20 +1,3 @@
|
|
|
1
|
-
# Copyright 2017, 2020 Andrzej Cichocki
|
|
2
|
-
|
|
3
|
-
# This file is part of aridity.
|
|
4
|
-
#
|
|
5
|
-
# aridity is free software: you can redistribute it and/or modify
|
|
6
|
-
# it under the terms of the GNU General Public License as published by
|
|
7
|
-
# the Free Software Foundation, either version 3 of the License, or
|
|
8
|
-
# (at your option) any later version.
|
|
9
|
-
#
|
|
10
|
-
# aridity is distributed in the hope that it will be useful,
|
|
11
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13
|
-
# GNU General Public License for more details.
|
|
14
|
-
#
|
|
15
|
-
# You should have received a copy of the GNU General Public License
|
|
16
|
-
# along with aridity. If not, see <http://www.gnu.org/licenses/>.
|
|
17
|
-
|
|
18
1
|
from .model import Scalar
|
|
19
2
|
from .util import null_exc_info
|
|
20
3
|
from base64 import b64decode
|
|
@@ -1,20 +1,3 @@
|
|
|
1
|
-
# Copyright 2017, 2020 Andrzej Cichocki
|
|
2
|
-
|
|
3
|
-
# This file is part of aridity.
|
|
4
|
-
#
|
|
5
|
-
# aridity is free software: you can redistribute it and/or modify
|
|
6
|
-
# it under the terms of the GNU General Public License as published by
|
|
7
|
-
# the Free Software Foundation, either version 3 of the License, or
|
|
8
|
-
# (at your option) any later version.
|
|
9
|
-
#
|
|
10
|
-
# aridity is distributed in the hope that it will be useful,
|
|
11
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13
|
-
# GNU General Public License for more details.
|
|
14
|
-
#
|
|
15
|
-
# You should have received a copy of the GNU General Public License
|
|
16
|
-
# along with aridity. If not, see <http://www.gnu.org/licenses/>.
|
|
17
|
-
|
|
18
1
|
from __future__ import division
|
|
19
2
|
from .util import dotpy, ispy2
|
|
20
3
|
from contextlib import contextmanager
|
|
@@ -229,12 +212,15 @@ class Resource(Resolved, Openable):
|
|
|
229
212
|
package = m.__package__
|
|
230
213
|
return (self.package_or_requirement if hasattr(m, '__path__') else self.package_or_requirement[:self.package_or_requirement.rindex('.')]) if package is None else package
|
|
231
214
|
|
|
215
|
+
def _resource_words(self):
|
|
216
|
+
return [] if self.resource_name is None else self.resource_name.split('/')
|
|
217
|
+
|
|
232
218
|
@contextmanager
|
|
233
219
|
def open(self, write):
|
|
234
220
|
assert not write
|
|
235
221
|
package = self._packagename()
|
|
236
222
|
path = importlib_resources.files(package)
|
|
237
|
-
for name in self.
|
|
223
|
+
for name in self._resource_words():
|
|
238
224
|
path /= name
|
|
239
225
|
with path.open('rb') as f:
|
|
240
226
|
if ispy2:
|
|
@@ -243,7 +229,8 @@ class Resource(Resolved, Openable):
|
|
|
243
229
|
yield f
|
|
244
230
|
|
|
245
231
|
def slash(self, words, rstrip):
|
|
246
|
-
|
|
232
|
+
v = list(chain(self._resource_words()[:-1 if rstrip else None], words))
|
|
233
|
+
return self._of(self.package_or_requirement, '/'.join(v) if v else None, self.encoding)
|
|
247
234
|
|
|
248
235
|
def modulenameornone(self):
|
|
249
236
|
if self.resource_name.endswith(dotpy):
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
'Process the given template to stdout using config from stdin.'
|
|
2
|
+
from .repl import Repl
|
|
3
|
+
import os, sys
|
|
4
|
+
|
|
5
|
+
def main():
|
|
6
|
+
templatepath, = sys.argv[1:]
|
|
7
|
+
with Repl() as repl:
|
|
8
|
+
for line in sys.stdin:
|
|
9
|
+
repl(line)
|
|
10
|
+
repl.printf("< %s", os.path.abspath(templatepath))
|
|
11
|
+
|
|
12
|
+
if '__main__' == __name__:
|
|
13
|
+
main()
|
|
@@ -1,20 +1,3 @@
|
|
|
1
|
-
# Copyright 2017, 2020 Andrzej Cichocki
|
|
2
|
-
|
|
3
|
-
# This file is part of aridity.
|
|
4
|
-
#
|
|
5
|
-
# aridity is free software: you can redistribute it and/or modify
|
|
6
|
-
# it under the terms of the GNU General Public License as published by
|
|
7
|
-
# the Free Software Foundation, either version 3 of the License, or
|
|
8
|
-
# (at your option) any later version.
|
|
9
|
-
#
|
|
10
|
-
# aridity is distributed in the hope that it will be useful,
|
|
11
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13
|
-
# GNU General Public License for more details.
|
|
14
|
-
#
|
|
15
|
-
# You should have received a copy of the GNU General Public License
|
|
16
|
-
# along with aridity. If not, see <http://www.gnu.org/licenses/>.
|
|
17
|
-
|
|
18
1
|
from .grammar import commandparser
|
|
19
2
|
from .model import Entry, Text
|
|
20
3
|
from .scope import Scope
|
|
@@ -1,26 +1,11 @@
|
|
|
1
|
-
# Copyright 2017, 2020 Andrzej Cichocki
|
|
2
|
-
|
|
3
|
-
# This file is part of aridity.
|
|
4
|
-
#
|
|
5
|
-
# aridity is free software: you can redistribute it and/or modify
|
|
6
|
-
# it under the terms of the GNU General Public License as published by
|
|
7
|
-
# the Free Software Foundation, either version 3 of the License, or
|
|
8
|
-
# (at your option) any later version.
|
|
9
|
-
#
|
|
10
|
-
# aridity is distributed in the hope that it will be useful,
|
|
11
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13
|
-
# GNU General Public License for more details.
|
|
14
|
-
#
|
|
15
|
-
# You should have received a copy of the GNU General Public License
|
|
16
|
-
# along with aridity. If not, see <http://www.gnu.org/licenses/>.
|
|
17
|
-
|
|
18
1
|
from . import directives
|
|
19
2
|
from .directives import Precedence
|
|
20
3
|
from .functions import getfunctions, OpaqueKey
|
|
21
4
|
from .model import CatNotSupportedException, Directive, Function, Resolvable, Scalar, star, Stream, Text
|
|
5
|
+
from .search import Query, resolvedscopeornone, scopedepths, slices
|
|
22
6
|
from .stacks import IndentStack, SimpleStack, ThreadLocalResolvable
|
|
23
|
-
from .util import CycleException, NoSuchPathException, OrderedDict, solo, TreeNoSuchPathException,
|
|
7
|
+
from .util import CycleException, NoSuchPathException, OrderedDict, solo, TreeNoSuchPathException, UnsupportedEntryException
|
|
8
|
+
from itertools import chain
|
|
24
9
|
import collections, os, sys, threading, unicodedata
|
|
25
10
|
|
|
26
11
|
class NotAPathException(Exception): pass
|
|
@@ -142,66 +127,22 @@ class AbstractScope(Resolvable): # TODO LATER: Some methods should probably be m
|
|
|
142
127
|
raise CycleException(path)
|
|
143
128
|
resolving.add(path)
|
|
144
129
|
try:
|
|
145
|
-
return self._resolved(path,
|
|
130
|
+
return self._resolved(path, Query(path).search(self), kwargs) if path else self
|
|
146
131
|
finally:
|
|
147
132
|
resolving.remove(path)
|
|
148
133
|
|
|
149
|
-
def
|
|
150
|
-
|
|
151
|
-
for name in path:
|
|
152
|
-
r = s.resolvables.getornone(name)
|
|
153
|
-
if r is None:
|
|
154
|
-
return
|
|
155
|
-
s = r.resolve(s)
|
|
156
|
-
if not hasattr(s, 'resolvables'):
|
|
157
|
-
return
|
|
158
|
-
return s
|
|
159
|
-
|
|
160
|
-
def _selfandparents(self):
|
|
161
|
-
scopes = [self]
|
|
162
|
-
depth = 0
|
|
163
|
-
while scopes:
|
|
164
|
-
nextscopes = []
|
|
165
|
-
for s in scopes:
|
|
166
|
-
yield depth, s
|
|
167
|
-
nextscopes.extend(s.parents)
|
|
168
|
-
scopes = nextscopes
|
|
169
|
-
depth += 1
|
|
170
|
-
|
|
171
|
-
def _scoreresolvables(self, path):
|
|
172
|
-
tail = path[1:]
|
|
173
|
-
for k, s in self._selfandparents():
|
|
174
|
-
r = s.resolvables.getornone(path[0])
|
|
175
|
-
if r is not None:
|
|
176
|
-
if tail:
|
|
177
|
-
obj = r.resolve(s) # XXX: Wise?
|
|
178
|
-
try:
|
|
179
|
-
obj_score = obj._scoreresolvables
|
|
180
|
-
except AttributeError:
|
|
181
|
-
pass
|
|
182
|
-
else:
|
|
183
|
-
for score, rr in obj_score(tail):
|
|
184
|
-
yield score + [k], rr
|
|
185
|
-
else:
|
|
186
|
-
yield [k], r
|
|
187
|
-
|
|
188
|
-
def _findresolvable(self, path):
|
|
189
|
-
pairs = list(self._scoreresolvables(path))
|
|
190
|
-
try:
|
|
191
|
-
return min(pairs, key = lambda t: t[0])[1]
|
|
192
|
-
except ValueError:
|
|
193
|
-
raise UnparseNoSuchPathException(path)
|
|
134
|
+
def resolvableornone(self, key):
|
|
135
|
+
return self.resolvables.getornone(key)
|
|
194
136
|
|
|
195
137
|
def _resolved(self, path, resolvable, kwargs): # TODO: Review this algo.
|
|
196
138
|
errors = []
|
|
197
|
-
for
|
|
198
|
-
for
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
errors.append(e)
|
|
139
|
+
for words in slices(path):
|
|
140
|
+
for s in (resolvedscopeornone(s, words) for s in chain.from_iterable(scopedepths(self))):
|
|
141
|
+
if s is not None:
|
|
142
|
+
try:
|
|
143
|
+
return resolvable.resolve(s, **kwargs)
|
|
144
|
+
except NoSuchPathException as e:
|
|
145
|
+
errors.append(e)
|
|
205
146
|
raise TreeNoSuchPathException(path, errors)
|
|
206
147
|
|
|
207
148
|
def unravel(self):
|
|
@@ -209,7 +150,7 @@ class AbstractScope(Resolvable): # TODO LATER: Some methods should probably be m
|
|
|
209
150
|
return list(d) if self.islist or (d and all(OpaqueKey.isopaque(k) for k in d.keys())) else d
|
|
210
151
|
|
|
211
152
|
def staticscope(self):
|
|
212
|
-
for
|
|
153
|
+
for s in chain.from_iterable(scopedepths(self)):
|
|
213
154
|
pass
|
|
214
155
|
return s
|
|
215
156
|
|
|
@@ -224,7 +165,7 @@ class AbstractScope(Resolvable): # TODO LATER: Some methods should probably be m
|
|
|
224
165
|
initialcategory = _categoryornone(word[0])
|
|
225
166
|
if initialcategory is None or initialcategory[0] not in 'PS':
|
|
226
167
|
continue
|
|
227
|
-
d =
|
|
168
|
+
d = Query([word]).search(self).directivevalue
|
|
228
169
|
p = Precedence.ofdirective(d)
|
|
229
170
|
if p > precedence:
|
|
230
171
|
del directives[:]
|
|
@@ -335,9 +276,6 @@ class Scope(AbstractScope):
|
|
|
335
276
|
def resolve(self, scope):
|
|
336
277
|
return self
|
|
337
278
|
|
|
338
|
-
def tojava(self):
|
|
339
|
-
return Text(''.join("%s %s\n" % (k, v.resolve(self).unravel()) for k, v in self.resolvables.items())) # TODO: Escaping.
|
|
340
|
-
|
|
341
279
|
class ScalarScope(Scope):
|
|
342
280
|
|
|
343
281
|
def __init__(self, parents, scalarobj):
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
from .util import UnparseNoSuchPathException
|
|
2
|
+
|
|
3
|
+
def scopedepths(scope):
|
|
4
|
+
scopes = [scope]
|
|
5
|
+
while scopes:
|
|
6
|
+
nextscopes = []
|
|
7
|
+
for s in scopes:
|
|
8
|
+
nextscopes.extend(s.parents)
|
|
9
|
+
yield scopes
|
|
10
|
+
scopes = nextscopes
|
|
11
|
+
|
|
12
|
+
def resolvedscopeornone(s, path):
|
|
13
|
+
for name in path:
|
|
14
|
+
r = s.resolvableornone(name)
|
|
15
|
+
if r is None:
|
|
16
|
+
return
|
|
17
|
+
s = r.resolve(s)
|
|
18
|
+
if not hasattr(s, 'resolvableornone'):
|
|
19
|
+
return
|
|
20
|
+
return s
|
|
21
|
+
|
|
22
|
+
class Query:
|
|
23
|
+
|
|
24
|
+
@classmethod
|
|
25
|
+
def _of(cls, *args):
|
|
26
|
+
return cls(*args)
|
|
27
|
+
|
|
28
|
+
def __init__(self, path):
|
|
29
|
+
self.path = path
|
|
30
|
+
|
|
31
|
+
def _scoreresolvables(self, scope):
|
|
32
|
+
tail = self.path[1:]
|
|
33
|
+
for k, v in enumerate(scopedepths(scope)):
|
|
34
|
+
for s in v:
|
|
35
|
+
r = s.resolvables.getornone(self.path[0])
|
|
36
|
+
if r is not None:
|
|
37
|
+
if tail:
|
|
38
|
+
obj = r.resolve(s) # XXX: Wise?
|
|
39
|
+
if hasattr(obj, 'parents'):
|
|
40
|
+
for score, rr in self._of(tail)._scoreresolvables(obj):
|
|
41
|
+
yield score + [k], rr
|
|
42
|
+
else:
|
|
43
|
+
yield [k], r
|
|
44
|
+
|
|
45
|
+
def search(self, scope):
|
|
46
|
+
pairs = list(self._scoreresolvables(scope))
|
|
47
|
+
try:
|
|
48
|
+
return min(pairs, key = lambda t: t[0])[1]
|
|
49
|
+
except ValueError:
|
|
50
|
+
raise UnparseNoSuchPathException(self.path)
|
|
51
|
+
|
|
52
|
+
def slices(path):
|
|
53
|
+
n = len(path)
|
|
54
|
+
for k in range(n)[::-1]:
|
|
55
|
+
for start in range(n - k):
|
|
56
|
+
v = path[start:start + k]
|
|
57
|
+
yield v
|
|
58
|
+
if not v:
|
|
59
|
+
return
|
|
@@ -1,20 +1,3 @@
|
|
|
1
|
-
# Copyright 2017, 2020 Andrzej Cichocki
|
|
2
|
-
|
|
3
|
-
# This file is part of aridity.
|
|
4
|
-
#
|
|
5
|
-
# aridity is free software: you can redistribute it and/or modify
|
|
6
|
-
# it under the terms of the GNU General Public License as published by
|
|
7
|
-
# the Free Software Foundation, either version 3 of the License, or
|
|
8
|
-
# (at your option) any later version.
|
|
9
|
-
#
|
|
10
|
-
# aridity is distributed in the hope that it will be useful,
|
|
11
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13
|
-
# GNU General Public License for more details.
|
|
14
|
-
#
|
|
15
|
-
# You should have received a copy of the GNU General Public License
|
|
16
|
-
# along with aridity. If not, see <http://www.gnu.org/licenses/>.
|
|
17
|
-
|
|
18
1
|
from .model import Resolvable, Text
|
|
19
2
|
from .util import NoSuchPathException
|
|
20
3
|
from contextlib import contextmanager
|
|
@@ -1,20 +1,3 @@
|
|
|
1
|
-
# Copyright 2017, 2020 Andrzej Cichocki
|
|
2
|
-
|
|
3
|
-
# This file is part of aridity.
|
|
4
|
-
#
|
|
5
|
-
# aridity is free software: you can redistribute it and/or modify
|
|
6
|
-
# it under the terms of the GNU General Public License as published by
|
|
7
|
-
# the Free Software Foundation, either version 3 of the License, or
|
|
8
|
-
# (at your option) any later version.
|
|
9
|
-
#
|
|
10
|
-
# aridity is distributed in the hope that it will be useful,
|
|
11
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13
|
-
# GNU General Public License for more details.
|
|
14
|
-
#
|
|
15
|
-
# You should have received a copy of the GNU General Public License
|
|
16
|
-
# along with aridity. If not, see <http://www.gnu.org/licenses/>.
|
|
17
|
-
|
|
18
1
|
from importlib_metadata import entry_points
|
|
19
2
|
import collections, inspect, sys
|
|
20
3
|
|