bidsschematools.utils

Utility functions for the bids-specification schema.

Functions

bidsschematools.utils.configure_logger(lgr)

Configuring formatting and stream handler for the logger.

Should not be used when bidsschematools is used as a library.

Parameters:

lgr (logging.Logger)

bidsschematools.utils.get_bundled_schema_path()

Get the path to the schema directory.

Returns:

Absolute path to the directory containing schema-related files.

Return type:

str

bidsschematools.utils.get_logger(name=None, level=None)

Return a logger to use.

Parameters:
  • name (None or str, optional) – Name of the logger. Defaults to None.

  • level (None or int, optional) – Level to set for the logger. Defaults to None. BIDS_SCHEMA_LOG_LEVEL environment variable can be used to set the level and will overwrite this value.

Returns:

logger object.

Return type:

logging.Logger

bidsschematools.utils.jsonschema_validator(schema: dict[str, Any], *, check_format: bool, default_cls: type[Validator] | None = None) Validator

Create a jsonschema validator appropriate for validating instances against a given JSON schema

Parameters:
  • schema (dict[str, Any]) – The JSON schema to validate against

  • check_format (bool) – Indicates whether to check the format against format specifications in the schema

  • default_cls (type[JsonschemaValidator] or None, optional) – The default JSON schema validator class to use to create the validator should the appropriate validator class cannot be determined based on the schema (by assessing the $schema property). If None, the class representing the latest JSON schema draft supported by the jsonschema package

Returns:

The JSON schema validator

Return type:

JsonschemaValidator

Raises:

jsonschema.exceptions.SchemaError – If the JSON schema is invalid

bidsschematools.utils.set_logger_level(lgr, level)

Set the logger level.

Parameters:
  • lgr (logging.Logger) – logger object for which to change the level.

  • level (int or str) – The desired level for the logger.