Coverage for src / check_datapackage / config.py: 100%

9 statements  

« prev     ^ index     » next       coverage.py v7.13.5, created at 2026-04-02 14:17 +0000

1from typing import Literal 

2 

3from pydantic import BaseModel 

4 

5from check_datapackage.exclusion import Exclusion 

6from check_datapackage.extensions import Extensions 

7 

8 

9class Config(BaseModel, frozen=True): 

10 """Configuration for checking a Data Package's properties. 

11 

12 Attributes: 

13 exclusions (list[Exclusion]): Any issues matching any of Exclusion objects will 

14 be excluded (i.e., removed from the output of the check function). 

15 extensions (Extensions): Additional checks (called extensions) 

16 that supplement those specified by the Data Package standard. 

17 strict (bool): Whether to include "SHOULD" checks in addition to "MUST" checks 

18 from the Data Package standard. If True, "SHOULD" checks will also be 

19 included. Defaults to False. 

20 version (str): The version of the Data Package standard to check against. 

21 Defaults to "v2". 

22 

23 Examples: 

24 ```{python} 

25 import check_datapackage as cdp 

26 

27 exclusion_required = cdp.Exclusion(type="required") 

28 license_check = cdp.CustomCheck( 

29 type="only-mit", 

30 jsonpath="$.licenses[*].name", 

31 message="Data Packages may only be licensed under MIT.", 

32 check=lambda license_name: license_name == "mit", 

33 ) 

34 required_title_check = cdp.RequiredCheck( 

35 jsonpath="$.title", 

36 message="A title is required.", 

37 ) 

38 config = cdp.Config( 

39 exclusions=[exclusion_required], 

40 extensions=cdp.Extensions( 

41 custom_checks=[license_check], 

42 required_checks=[required_title_check] 

43 ) 

44 ) 

45 

46 # check(properties, config=config) 

47 ``` 

48 """ 

49 

50 exclusions: list[Exclusion] = [] 

51 extensions: Extensions = Extensions() 

52 strict: bool = False 

53 version: Literal["v1", "v2"] = "v2"