/
schemata.py
139 lines (111 loc) · 3.99 KB
/
schemata.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# -*- coding: utf-8 -*-
"""Contain schemata required by cenv-tool."""
from marshmallow import fields
from marshmallow import Schema
from marshmallow import validate
class SNPackage(Schema):
"""Contain the ``package``-section inside a ``meta.yaml``."""
name = fields.String(strict=True, required=True)
version = fields.String(strict=True, required=True)
class SNSource(Schema):
"""Contain the ``source``-section inside a ``meta.yaml``."""
path = fields.String(strict=True, required=True)
class SNBuild(Schema):
"""Contain the ``build``-section inside a ``meta.yaml``.
The ``build``-section requires to define the build-number, if the egg-dir
should be preserved, the script to run on installation and if any
entrypoints are defined for the package.
"""
build = fields.String(strict=True, required=True)
preserve_egg_dir = fields.String(
strict=True,
required=True,
validate=validate.OneOf(['True', 'False']),
)
script = fields.String(strict=True, required=True)
entry_points = fields.List(
fields.String(strict=True, required=False),
strict=True,
required=False,
)
class SNRequirements(Schema):
"""Contain ``requirements``-section inside a ``meta.yaml``.
The underlying ``build``- and ``run``-sections have to be valid!
"""
build = fields.List(
fields.String(strict=True, required=True),
strict=True,
required=True,
)
run = fields.List(
fields.String(
strict=True,
required=True,
validate=lambda x: '=' in x if 'python' not in x else True,
error_messages=dict(validator_failed='Version must be specified'),
),
strict=True,
required=True,
)
run_constrained = fields.List(
fields.String(
strict=True,
required=False,
validate=lambda x: '=' in x,
error_messages=dict(validator_failed='Version must be specified'),
),
strict=True,
required=False,
)
class SNTest(Schema):
"""Contain ``tests``-section inside a ``meta.yaml``."""
imports = fields.List(
fields.String(strict=True, required=False),
strict=True,
required=False,
)
commands = fields.List(
fields.String(strict=True, required=False),
strict=True,
required=False,
)
class SNCenv(Schema):
env_name = fields.String(
strict=True,
required=True,
validate=lambda x: ' ' not in x,
)
python = fields.String(
strict=True,
required=True
)
dev_requirements = fields.List(
fields.String(
strict=True,
required=True,
validate=lambda x: '=' in x,
error_messages=dict(validator_failed='Version must be specified'),
),
strict=True,
required=False,
)
class SNExtra(Schema):
"""Contain the ``extra``-section inside a ``meta.yaml``.
The ``extra``-section has to contains the information where to find the
conda-folder, the name of the conda environment to use for the current
project and the cenv-version used when the ``meta.yaml`` file was created.
"""
cenv = fields.Nested(SNCenv, strict=True, required=True)
class SMetaYaml(Schema):
"""Contain the representable of a complete ``meta.yaml`` file.
Schema for a ``meta.yaml`` file to be used for cenv.
Ensure the meta.yaml to load contains the relevant information about
the ``package``, ``source``, ``build``, ``requirements`` and ``extra``.
The ``test``-section is optional.
"""
package = fields.Nested(SNPackage, strict=True, required=True)
source = fields.Nested(SNSource, strict=True, required=True)
build = fields.Nested(SNBuild, strict=True, required=True)
requirements = fields.Nested(SNRequirements, strict=True, required=True)
test = fields.Nested(SNTest, strict=True, required=False)
extra = fields.Nested(SNExtra, strict=True, required=True)