aridity 94__tar.gz → 95__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: aridity
3
- Version: 94
3
+ Version: 95
4
4
  Summary: DRY config and template system, easily extensible with Python
5
5
  Home-page: https://pypi.org/project/aridity/
6
6
  Author: foyono
@@ -158,6 +158,17 @@ def source(prefix, suffix, scope)
158
158
 
159
159
  Include path or resource at prefix.
160
160
 
161
+ <a id="aridity.directives.sourceifexists"></a>
162
+
163
+ ###### sourceifexists
164
+
165
+ ```python
166
+ @prime
167
+ def sourceifexists(prefix, suffix, scope)
168
+ ```
169
+
170
+ Like `.` but allow the resource to be absent.
171
+
161
172
  <a id="aridity.directives.equals"></a>
162
173
 
163
174
  ###### equals
@@ -148,6 +148,17 @@ def source(prefix, suffix, scope)
148
148
 
149
149
  Include path or resource at prefix.
150
150
 
151
+ <a id="aridity.directives.sourceifexists"></a>
152
+
153
+ ###### sourceifexists
154
+
155
+ ```python
156
+ @prime
157
+ def sourceifexists(prefix, suffix, scope)
158
+ ```
159
+
160
+ Like `.` but allow the resource to be absent.
161
+
151
162
  <a id="aridity.directives.equals"></a>
152
163
 
153
164
  ###### equals
@@ -1,7 +1,10 @@
1
1
  from .model import Stream
2
2
  from .search import resolvedscopeornone
3
+ from .util import Burial
3
4
  from itertools import chain
4
- import os, sys, unicodedata
5
+ import logging, os, sys, unicodedata
6
+
7
+ log = logging.getLogger(__name__)
5
8
 
6
9
  def acceptdirectivename(word):
7
10
  return word and unicodedata.category(word[0])[0] in 'PS'
@@ -48,7 +51,19 @@ def source(prefix, suffix, scope):
48
51
  if s is None:
49
52
  break
50
53
  phrasescope = s
51
- suffix.tophrase().resolve(phrasescope).openable(phrasescope).source(scope, prefix.subentry(k, n))
54
+ with Burial.bumping(FileNotFoundError):
55
+ openable = suffix.tophrase().resolve(phrasescope).openable(phrasescope)
56
+ openable.source(scope, prefix.subentry(k, n))
57
+
58
+ @prime
59
+ def sourceifexists(prefix, suffix, scope):
60
+ 'Like `.` but allow the resource to be absent.'
61
+ try:
62
+ source(prefix, suffix, scope)
63
+ except FileNotFoundError as e:
64
+ if Burial.value(e):
65
+ raise
66
+ log.debug("Ignore absence: %s", e)
52
67
 
53
68
  @prime
54
69
  def _cd(prefix, suffix, scope):
@@ -95,6 +110,7 @@ def coredirectives():
95
110
  yield '!redirect', _redirect
96
111
  yield '!write', _write
97
112
  yield '.', source
113
+ yield '.?', sourceifexists
98
114
  yield '!cd', _cd
99
115
  yield '!test', _test
100
116
  yield '=', equals
@@ -1,4 +1,4 @@
1
- from .util import dotpy, Forkable
1
+ from .util import Burial, dotpy, Forkable
2
2
  from contextlib import contextmanager
3
3
  from importlib import import_module
4
4
  from importlib.resources import files
@@ -232,7 +232,7 @@ class Openable:
232
232
  yield f
233
233
 
234
234
  def source(self, scope, prefix):
235
- with self.pushopen(scope) as f:
235
+ with self.pushopen(scope) as f, Burial.bumping(FileNotFoundError):
236
236
  Stream(f).source(scope, prefix)
237
237
 
238
238
  def processtemplate(self, scope):
@@ -1,3 +1,4 @@
1
+ from contextlib import contextmanager
1
2
  from importlib.metadata import entry_points
2
3
  import sys
3
4
 
@@ -72,3 +73,20 @@ class Forkable:
72
73
  @classmethod
73
74
  def _of(cls, *args, **kwargs):
74
75
  return cls(*args, **kwargs)
76
+
77
+ class Burial:
78
+
79
+ name = 'burial'
80
+
81
+ @classmethod
82
+ def value(cls, e):
83
+ return getattr(e, cls.name, 0)
84
+
85
+ @classmethod
86
+ @contextmanager
87
+ def bumping(cls, exctype):
88
+ try:
89
+ yield
90
+ except exctype as e:
91
+ setattr(e, cls.name, cls.value(e) + 1)
92
+ raise
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: aridity
3
- Version: 94
3
+ Version: 95
4
4
  Summary: DRY config and template system, easily extensible with Python
5
5
  Home-page: https://pypi.org/project/aridity/
6
6
  Author: foyono
@@ -158,6 +158,17 @@ def source(prefix, suffix, scope)
158
158
 
159
159
  Include path or resource at prefix.
160
160
 
161
+ <a id="aridity.directives.sourceifexists"></a>
162
+
163
+ ###### sourceifexists
164
+
165
+ ```python
166
+ @prime
167
+ def sourceifexists(prefix, suffix, scope)
168
+ ```
169
+
170
+ Like `.` but allow the resource to be absent.
171
+
161
172
  <a id="aridity.directives.equals"></a>
162
173
 
163
174
  ###### equals
@@ -49,7 +49,7 @@ class SourceInfo:
49
49
  sourceinfo = SourceInfo('.')
50
50
  setup(
51
51
  name = 'aridity',
52
- version = '94',
52
+ version = '95',
53
53
  description = 'DRY config and template system, easily extensible with Python',
54
54
  url = 'https://pypi.org/project/aridity/',
55
55
  author = 'foyono',
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes