codeplain 0.3.13.dev46__py3-none-any.whl → 0.3.13.dev48__py3-none-any.whl
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.
- {codeplain-0.3.13.dev46.dist-info → codeplain-0.3.13.dev48.dist-info}/METADATA +2 -2
- {codeplain-0.3.13.dev46.dist-info → codeplain-0.3.13.dev48.dist-info}/RECORD +22 -25
- {codeplain-0.3.13.dev46.dist-info → codeplain-0.3.13.dev48.dist-info}/WHEEL +1 -1
- concept_utils.py +2 -220
- file_utils.py +6 -106
- plain2code.py +39 -6
- plain2code_arguments.py +30 -0
- plain2code_exceptions.py +12 -42
- plain2code_nodes.py +2 -118
- plain2code_state.py +6 -2
- plain2code_utils.py +1 -16
- plain_file.py +2 -870
- plain_spec.py +9 -413
- tests/test_arg_provenance.py +20 -0
- tests/test_file_utils.py +1 -70
- tests/test_plain2code_state.py +5 -0
- tests/test_render_finished_report.py +1 -0
- tests/test_render_range.py +42 -0
- tests/test_terminal_attachment.py +1 -0
- tests/test_user_error_message.py +36 -0
- tests/test_imports.py +0 -53
- tests/test_plainfile.py +0 -271
- tests/test_plainfileparser.py +0 -775
- tests/test_plainspec.py +0 -103
- tests/test_requires.py +0 -28
- {codeplain-0.3.13.dev46.dist-info → codeplain-0.3.13.dev48.dist-info}/entry_points.txt +0 -0
- {codeplain-0.3.13.dev46.dist-info → codeplain-0.3.13.dev48.dist-info}/licenses/LICENSE +0 -0
plain2code_exceptions.py
CHANGED
|
@@ -1,3 +1,15 @@
|
|
|
1
|
+
from plain_parser.exceptions import ( # noqa: F401
|
|
2
|
+
ImportedModuleWithFunctionalitiesError,
|
|
3
|
+
InvalidFridArgument,
|
|
4
|
+
InvalidLiquidVariableName,
|
|
5
|
+
MissingFunctionalitiesError,
|
|
6
|
+
ModuleDoesNotExistError,
|
|
7
|
+
PlainSyntaxError,
|
|
8
|
+
UnsupportedBase64Content,
|
|
9
|
+
UnsupportedResourceType,
|
|
10
|
+
)
|
|
11
|
+
|
|
12
|
+
|
|
1
13
|
class FunctionalRequirementTooComplex(Exception):
|
|
2
14
|
def __init__(self, message, proposed_breakdown=None):
|
|
3
15
|
self.message = message
|
|
@@ -21,19 +33,6 @@ class MissingResource(Exception):
|
|
|
21
33
|
pass
|
|
22
34
|
|
|
23
35
|
|
|
24
|
-
class UnsupportedResourceType(Exception):
|
|
25
|
-
pass
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
class PlainSyntaxError(Exception):
|
|
29
|
-
pass
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
class UnsupportedBase64Content(Exception):
|
|
33
|
-
|
|
34
|
-
pass
|
|
35
|
-
|
|
36
|
-
|
|
37
36
|
class InternalClientError(Exception):
|
|
38
37
|
pass
|
|
39
38
|
|
|
@@ -50,24 +49,12 @@ class OutdatedClientVersion(Exception):
|
|
|
50
49
|
pass
|
|
51
50
|
|
|
52
51
|
|
|
53
|
-
class InvalidFridArgument(Exception):
|
|
54
|
-
pass
|
|
55
|
-
|
|
56
|
-
|
|
57
52
|
class InvalidGitRepositoryError(Exception):
|
|
58
53
|
"""Raised when the git repository is in an invalid state."""
|
|
59
54
|
|
|
60
55
|
pass
|
|
61
56
|
|
|
62
57
|
|
|
63
|
-
class InvalidLiquidVariableName(Exception):
|
|
64
|
-
pass
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
class ModuleDoesNotExistError(Exception):
|
|
68
|
-
pass
|
|
69
|
-
|
|
70
|
-
|
|
71
58
|
class InternalServerError(Exception):
|
|
72
59
|
pass
|
|
73
60
|
|
|
@@ -78,23 +65,6 @@ class MissingPreviousFunctionalitiesError(Exception):
|
|
|
78
65
|
pass
|
|
79
66
|
|
|
80
67
|
|
|
81
|
-
class MissingFunctionalitiesError(Exception):
|
|
82
|
-
"""Raised when a module to be rendered has no functionalities specified at all."""
|
|
83
|
-
|
|
84
|
-
pass
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
class ImportedModuleWithFunctionalitiesError(Exception):
|
|
88
|
-
"""Raised when a module brought in via ``import`` contains functional specs.
|
|
89
|
-
|
|
90
|
-
This is a usage error, not a syntax error: the module is syntactically valid
|
|
91
|
-
and would be fine as a render target, but functionalities are not allowed in
|
|
92
|
-
the import role.
|
|
93
|
-
"""
|
|
94
|
-
|
|
95
|
-
pass
|
|
96
|
-
|
|
97
|
-
|
|
98
68
|
class NetworkConnectionError(Exception):
|
|
99
69
|
"""Raised when there is a network connectivity issue with the API server."""
|
|
100
70
|
|
plain2code_nodes.py
CHANGED
|
@@ -1,119 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
from typing import Mapping, Sequence, TextIO
|
|
1
|
+
"""Compatibility shim: the parser now lives in the ``plain-parser`` package."""
|
|
3
2
|
|
|
4
|
-
from
|
|
5
|
-
from liquid2.builtin import IncludeTag
|
|
6
|
-
from liquid2.builtin.tags.include_tag import IncludeNode
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
class Plain2CodeIncludeNode(IncludeNode):
|
|
10
|
-
def render_to_output(self, context: RenderContext, buffer: TextIO) -> int:
|
|
11
|
-
"""Render the node to the output buffer."""
|
|
12
|
-
name = self.name.evaluate(context)
|
|
13
|
-
whitespaces = 0
|
|
14
|
-
is_comment = False
|
|
15
|
-
i = self.token.start
|
|
16
|
-
while self.token.source[i] != "\n" and i >= 0:
|
|
17
|
-
if self.token.source[i] == " ":
|
|
18
|
-
whitespaces += 1
|
|
19
|
-
elif self.token.source[i] == ">":
|
|
20
|
-
is_comment = True
|
|
21
|
-
break
|
|
22
|
-
else:
|
|
23
|
-
whitespaces = 0
|
|
24
|
-
i -= 1
|
|
25
|
-
|
|
26
|
-
if is_comment:
|
|
27
|
-
return buffer.write(str(self))
|
|
28
|
-
|
|
29
|
-
try:
|
|
30
|
-
template = context.env.get_template(str(name), context=context, tag=self.tag, whitespaces=whitespaces)
|
|
31
|
-
except TemplateNotFoundError as err:
|
|
32
|
-
detail = str(err)
|
|
33
|
-
long_message = f"""Template not found: {detail}
|
|
34
|
-
The required template could not be found. Templates are searched in the following order (highest to lowest precedence):
|
|
35
|
-
|
|
36
|
-
1. The directory containing your .plain file
|
|
37
|
-
2. The directory specified by --template-dir (if provided)
|
|
38
|
-
3. The built-in 'standard_template_library' directory
|
|
39
|
-
|
|
40
|
-
Please ensure that the missing template exists in one of these locations, or specify the correct --template-dir if using custom templates.
|
|
41
|
-
"""
|
|
42
|
-
wrapped = TemplateNotFoundError(long_message)
|
|
43
|
-
wrapped.token = self.name.token
|
|
44
|
-
wrapped.template_name = context.template.full_name()
|
|
45
|
-
raise wrapped from err
|
|
46
|
-
|
|
47
|
-
namespace: dict[str, object] = dict(arg.evaluate(context) for arg in self.args)
|
|
48
|
-
|
|
49
|
-
character_count = 0
|
|
50
|
-
|
|
51
|
-
with context.extend(namespace, template=template):
|
|
52
|
-
if self.var:
|
|
53
|
-
val = self.var.evaluate(context)
|
|
54
|
-
key = self.alias or template.name.split(".")[0]
|
|
55
|
-
|
|
56
|
-
if isinstance(val, Sequence) and not isinstance(val, str):
|
|
57
|
-
context.raise_for_loop_limit(len(val))
|
|
58
|
-
for itm in val:
|
|
59
|
-
namespace[key] = itm
|
|
60
|
-
character_count += template.render_with_context(context, buffer, partial=True)
|
|
61
|
-
else:
|
|
62
|
-
namespace[key] = val
|
|
63
|
-
character_count = template.render_with_context(context, buffer, partial=True)
|
|
64
|
-
else:
|
|
65
|
-
|
|
66
|
-
character_count = template.render_with_context(context, buffer, partial=True)
|
|
67
|
-
|
|
68
|
-
return character_count
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
class Plain2CodeIncludeTag(IncludeTag):
|
|
72
|
-
node_class = Plain2CodeIncludeNode
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
class Plain2CodeLoaderMixin:
|
|
76
|
-
def __init__(self, *args, **kwargs):
|
|
77
|
-
if not hasattr(self, "get_source"):
|
|
78
|
-
raise NotImplementedError("Class must implement get_source")
|
|
79
|
-
super().__init__(*args, **kwargs)
|
|
80
|
-
|
|
81
|
-
def load(
|
|
82
|
-
self,
|
|
83
|
-
env: Environment,
|
|
84
|
-
name: str,
|
|
85
|
-
*,
|
|
86
|
-
globals: Mapping[str, object] | None = None,
|
|
87
|
-
context: RenderContext | None = None,
|
|
88
|
-
**kwargs: object,
|
|
89
|
-
) -> Template:
|
|
90
|
-
"""
|
|
91
|
-
Find and parse template source code.
|
|
92
|
-
|
|
93
|
-
Args:
|
|
94
|
-
env: The `Environment` attempting to load the template source text.
|
|
95
|
-
name: A name or identifier for a template's source text.
|
|
96
|
-
globals: A mapping of render context variables attached to the
|
|
97
|
-
resulting template.
|
|
98
|
-
context: An optional render context that can be used to narrow the template
|
|
99
|
-
source search space.
|
|
100
|
-
kwargs: Arbitrary arguments that can be used to narrow the template source
|
|
101
|
-
search space.
|
|
102
|
-
"""
|
|
103
|
-
source, full_name, uptodate, matter = self.get_source(env, name, context=context, **kwargs)
|
|
104
|
-
whitespaces = kwargs.get("whitespaces", 0)
|
|
105
|
-
assert isinstance(whitespaces, int)
|
|
106
|
-
source = source.rstrip().replace("\n", "\n" + " " * whitespaces)
|
|
107
|
-
|
|
108
|
-
path = Path(full_name)
|
|
109
|
-
|
|
110
|
-
template = env.from_string(
|
|
111
|
-
source,
|
|
112
|
-
name=path.name,
|
|
113
|
-
path=path,
|
|
114
|
-
globals=globals,
|
|
115
|
-
overlay_data=matter,
|
|
116
|
-
)
|
|
117
|
-
|
|
118
|
-
template.uptodate = uptodate
|
|
119
|
-
return template
|
|
3
|
+
from plain_parser.liquid_nodes import * # noqa: F401,F403
|
plain2code_state.py
CHANGED
|
@@ -8,7 +8,7 @@ from typing import Optional
|
|
|
8
8
|
class RunState:
|
|
9
9
|
"""Contains information about the identifiable state of the rendering process."""
|
|
10
10
|
|
|
11
|
-
def __init__(self, spec_filename: str, replay_with: Optional[str] = None):
|
|
11
|
+
def __init__(self, spec_filename: str, replay_with: Optional[str] = None, job_tag: Optional[str] = None):
|
|
12
12
|
self.replay: bool = replay_with is not None
|
|
13
13
|
self.render_succeeded: bool = False
|
|
14
14
|
self.render_cancelled: bool = False
|
|
@@ -19,6 +19,7 @@ class RunState:
|
|
|
19
19
|
else:
|
|
20
20
|
self.render_id: str = str(uuid.uuid4())
|
|
21
21
|
self.spec_filename: str = spec_filename
|
|
22
|
+
self.job_tag: Optional[str] = job_tag
|
|
22
23
|
self.call_count: int = 0
|
|
23
24
|
self.unittest_batch_id: int = 0
|
|
24
25
|
self.render_time_accumulated: int = 0
|
|
@@ -70,9 +71,12 @@ class RunState:
|
|
|
70
71
|
self.last_render_start_timestamp = time.monotonic()
|
|
71
72
|
|
|
72
73
|
def to_dict(self):
|
|
73
|
-
|
|
74
|
+
state = {
|
|
74
75
|
"render_id": self.render_id,
|
|
75
76
|
"call_count": self.call_count,
|
|
76
77
|
"replay": self.replay,
|
|
77
78
|
"spec_filename": self.spec_filename,
|
|
78
79
|
}
|
|
80
|
+
if self.job_tag is not None:
|
|
81
|
+
state["job_tag"] = self.job_tag
|
|
82
|
+
return state
|
plain2code_utils.py
CHANGED
|
@@ -1,19 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
from typing import Optional
|
|
3
|
-
|
|
4
|
-
#
|
|
5
|
-
MAX_BASE64_BLOB_LENGTH = 8192
|
|
6
|
-
|
|
7
|
-
# Matches a long contiguous base64 / base64url run, optionally preceded by a data: URI header.
|
|
8
|
-
_BASE64_BLOB_PATTERN = re.compile(
|
|
9
|
-
r"(?:data:[\w.+-]+/[\w.+-]+;base64,)?[A-Za-z0-9+/_-]{%d,}={0,2}" % MAX_BASE64_BLOB_LENGTH
|
|
10
|
-
)
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
def find_large_base64_blob(text: str) -> Optional[str]:
|
|
14
|
-
"""Return the first contiguous base64 blob at or above the threshold, or None."""
|
|
15
|
-
match = _BASE64_BLOB_PATTERN.search(text)
|
|
16
|
-
return match.group(0) if match else None
|
|
1
|
+
from plain_parser.loaders import MAX_BASE64_BLOB_LENGTH, find_large_base64_blob # noqa: F401
|
|
17
2
|
|
|
18
3
|
|
|
19
4
|
def format_duration_hms(total_seconds: float) -> str:
|