Skip to content

Commit c328343

Browse files
lwjohnst86signekbmartonvago
authored
docs: 🏗️ add interface for an umbrella extensions class (#156)
# Description Related to some discussions like in #120 and #122 about how we handle custom checks/extensions to the checks against the Data Package standard. Closes #152 Needs an in-depth review. ## Checklist - [x] Formatted Markdown - [x] Ran `just run-all` --------- Co-authored-by: Signe Kirk Brødbæk <[email protected]> Co-authored-by: martonvago <[email protected]>
1 parent 0008ff5 commit c328343

File tree

1 file changed

+106
-4
lines changed

1 file changed

+106
-4
lines changed

docs/design/interface.qmd

Lines changed: 106 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,10 +145,71 @@ Package standard that are not relevant to your use case.
145145

146146
See the help documentation with `help(Exclusion)` for more details.
147147

148-
#### {{< var done >}} `CustomCheck`
148+
#### {{< var wip >}} `Extensions`
149+
150+
This sub-item of `Config` defines extensions, i.e., additional checks
151+
that supplement those specified by the Data Package standard. It
152+
contains subitems that store additional checks, such as `RequiredCheck`
153+
and `CustomCheck`. This `Extensions` class might be expanded to include
154+
more types of extensions.
155+
156+
```` python
157+
@dataclass(frozen=True)
158+
class Extensions:
159+
"""Extensions to the standard checks.
160+
161+
This contains additional checks to be made alongside the standard
162+
Data Package checks.
163+
164+
Attributes:
165+
required_checks: A list of `RequiredCheck` objects defining properties to set as required.
166+
custom_checks: A list of `CustomCheck` objects defining extra, custom checks to run alongside the standard
167+
checks.
168+
169+
Examples:
170+
171+
```{python}
172+
import check_datapackage as cdp
173+
174+
extensions = cdp.Extensions(
175+
required_checks=[
176+
cdp.RequiredCheck(
177+
jsonpath="$.description",
178+
message="Data Packages must include a description."
179+
),
180+
cdp.RequiredCheck(
181+
jsonpath="$.contributors[*].email",
182+
message="All contributors must have an email address."
183+
)
184+
],
185+
custom_checks=[cdp.CustomCheck(
186+
type="only-mit",
187+
jsonpath="$.licenses[*].name",
188+
message="Data Packages may only be licensed under MIT.",
189+
check=lambda license_name: license_name == "mit",
190+
)]
191+
)
192+
# check(descriptor, config=cdp.Config(extensions=extensions))
193+
```
194+
"""
195+
required_checks : list[RequiredCheck] = field(default_factory=list)
196+
custom_checks : list[CustomCheck] = field(default_factory=list)
197+
````
198+
199+
Each extension class must implement its own `apply()` method that takes
200+
the `datapackage.json` properties `dict` as input and outputs an `Issue`
201+
list that contains the issues found by that extension.
202+
203+
#### {{< var wip >}} `RequiredCheck`
149204

150-
A sub-item of `Config`. Expresses a custom check.
205+
A sub-item of `Extensions` that allows users to set specific properties
206+
as required that are not required by the Data Package standard. See the
207+
help documentation with `help(RequiredCheck)` for more details.
151208

209+
#### {{< var done >}} `CustomCheck`
210+
211+
A sub-item of `Extensions` that allows users to add an additional, custom
212+
check that `check-datapackage` will run alongside the standard checks.
152213
See the help documentation with `help(CustomCheck)` for more details.
153214

154215
### {{< var done >}} `Issue`
@@ -159,20 +220,61 @@ Package.
159220
See the help documentation with
160221
[`help(Issue)`](/docs/reference/Issue.qmd) for more details.
161222

223+
## {{< var planned >}} Configuration file
224+
225+
When we develop the CLI, we'll use a config file to store the settings
226+
contained within the `Config` class. This file will be named `.cdp.toml`
227+
and will be located in the same directory as the `datapackage.json`
228+
file. This is an example of what that file could look like:
229+
230+
``` toml
231+
# The Data Package standard version to check against.
232+
version = "v2"
233+
234+
# Whether to check properties that must *and should* be included.
235+
strict = true
236+
237+
# Exclude all issues related to the "resources" property.
238+
[[exclusions]]
239+
jsonpath = "$.resources"
240+
241+
# Exclude all issues related to the "format" type in the schema.
242+
[[exclusions]]
243+
type = "format"
244+
245+
# Exclude issues that are both a "pattern" type and found in
246+
# the "path" property of the "contributors" field.
247+
[[exclusions]]
248+
jsonpath = "$.contributors[*].path"
249+
type = "pattern"
250+
251+
# Require that the "description" property is included in the Data Package.
252+
[[extensions.required_checks]]
253+
jsonpath = "$.description"
254+
message = "This Data Package needs to include a 'description' property."
255+
256+
# A custom check to ensure that all resource names are lowercase.
257+
[[extensions.custom_checks]]
258+
jsonpath = "$.resources[*].name"
259+
type = "name-lowercase"
260+
message = "The value in the 'name' property of the 'resources' must be lowercase."
261+
check = "lambda name: name.islower()"
262+
```
263+
162264
## Flow
163265

164266
This is the potential flow of using `check-datapackage`:
165267

166268
```{mermaid}
167269
%%| label: fig-interface-flow
168270
%%| fig-cap: "Flow of functions and classes when using `check-datapackage`."
169-
%%| fig-alt: "A flowchart showing the flow of using `check-datapackage`, starting with reading the datapackage.json and .cdp.yaml files, then checking the descriptor with the config, and finally explaining any issues found."
271+
%%| fig-alt: "A flowchart showing the flow of using `check-datapackage`, starting with reading the `datapackage.json` and `.cdp.toml` files, then checking the descriptor with the config, and finally explaining any issues found."
170272
flowchart TD
171273
descriptor_file[(datapackage.json)]
172274
read_json["read_json()"]
173275
descriptor[/"Descriptor<br>(dict)"/]
174276
175-
config_file[(.cdp.yaml)]
277+
config_file[(.cdp.toml)]
176278
read_config["read_config()"]
177279
178280
config[/Config/]

0 commit comments

Comments
 (0)