Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/check_datapackage/check.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
import re
import sys
from dataclasses import dataclass, field
Expand All @@ -6,6 +7,7 @@
from typing import Any, Callable, Iterator, Optional

from jsonschema import Draft7Validator, FormatChecker, ValidationError
from rich import print as rprint

from check_datapackage.config import Config
from check_datapackage.constants import (
Expand Down Expand Up @@ -130,6 +132,11 @@ class for more details, especially about the default values.
issues = exclude(issues, config.exclusions, properties)
issues = sorted(set(issues))

if os.getenv("CDP_DEBUG"):
rprint("", properties)
rprint(*issues)
rprint(explain(issues))

Comment on lines +135 to +139
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To activate, you can run a script like this:

CDP_DEBUG=true uv run joel_checking.py 

I tried fancier solutions with the rich logging module, but it was impossible for me to find a way that pytest would pipe through the colors of the output from rich when using the logging handler. With printing it "just works" (tm).

There is also no built-in way to pass a debug level flag to Python's logging module, so we would en up reading an env variable or making our script accept a command line parameter, which both seemed like unnecessary code.


As an example of output, let's run this command:

CDP_DEBUG=true uv run python -c 'import check_datapackage as cdp; cdp.check({"resources": [{"title": "Title"}]})'

which gives us:

Image

It is easy to inspect the two error message from explain this way. In this case, the first one seems to make sense whereas the second doesn't make it clear what went wrong (it seems like we passed something to name so why is it telling us it didn't). Follow up on @martonvago 's comment in #208 (comment)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I put a comment on the issue about this too 😅

if error and issues:
raise DataPackageError(issues)

Expand Down