Coverage for src / check_datapackage / cli.py: 94%

16 statements  

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

1"""Functions for the exposed CLI.""" 

2 

3from typing import Annotated, Any 

4 

5from cyclopts import Parameter 

6from seedcase_soil import ( 

7 Address, 

8 parse_source, 

9 pretty_print, 

10 read_properties, 

11 run_without_tracebacks, 

12 setup_cli, 

13) 

14 

15from check_datapackage.check import check 

16from check_datapackage.config import Config 

17from check_datapackage.exclusion import Exclusion 

18 

19app = setup_cli( 

20 name="check-datapackage", 

21 help=( 

22 "check-datapackage checks if metadata is compliant with the Data Package" 

23 "standard" 

24 ), 

25 config_name=".cdp.toml", 

26) 

27 

28 

29@app.command(name="check") 

30def check_cmd( 

31 source: str = "datapackage.json", 

32 /, # End of positional-only args 

33 *, # Start of keyword-only params 

34 strict: bool = False, 

35 exclusions: Annotated[list[Exclusion], Parameter(show=False)] = [], 

36) -> None: 

37 """Check a Data Package's metadata against the Data Package standard. 

38 

39 Outputs a human-readable explanation of any issues found. 

40 

41 Args: 

42 source: The location of a `datapackage.json`, defaults to a file or folder 

43 path. Can also be an `https:` source to a remote `datapackage.json` or a 

44 `github:` / `gh:` pointing to a repo with a `datapackage.json` 

45 in the repo root (in the format `gh:org/repo`, which can also include 

46 reference to a tag or branch, such as `gh:org/repo@main` or 

47 `gh:org/repo@1.0.1`). 

48 strict: If True, check "SHOULD" properties in addition to "MUST" 

49 properties from the Data Package standard. 

50 exclusions: A hidden CLI/config parameter for excluding issues by JSONPath 

51 and/or issue type. 

52 """ 

53 address: Address = parse_source(source) 

54 properties: dict[str, Any] = read_properties(address) 

55 config = Config(strict=strict, exclusions=exclusions) 

56 check(properties, config=config, error=True) 

57 pretty_print("[green]All checks passed![/green]") 

58 

59 

60def main() -> None: 

61 """Create an entry point to run the cli without tracebacks.""" 

62 run_without_tracebacks(app)