libretime/shared
github-actions[bot] f50e10625d
chore(stable): release 3.2.1 (#2828)
🤖 I have created a release *beep* *boop*
---


## [3.2.1](https://github.com/libretime/libretime/compare/3.2.0...3.2.1)
(2023-12-22)


### Bug Fixes

* add parent function name in setValue exception
([#2777](https://github.com/libretime/libretime/issues/2777))
([c764a5a](c764a5a648))
* **api:** enum schema description
([#2803](https://github.com/libretime/libretime/issues/2803))
([976b70e](976b70ed32))
* **legacy:** allow uploading opus files
([#2804](https://github.com/libretime/libretime/issues/2804))
([1206252](1206252faa))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: jo <ljonas@riseup.net>
2023-12-22 21:19:04 +01:00
..
libretime_shared feat: add mobile devices stream config field (#2744) 2023-10-14 08:13:04 +01:00
tests docs: be consistent with example domain (#2568) 2023-05-26 14:00:34 +01:00
Makefile chore: split test and coverage tasks 2023-01-16 08:42:23 +02:00
README.md feat: replace loguru with logging 2023-02-26 19:09:51 +02:00
packages.ini chore: list distribution releases by release date 2022-10-10 20:11:33 +02:00
pyproject.toml test: re-enable pylint logging-fstring-interpolation 2023-02-26 19:09:51 +02:00
requirements.txt feat: replace loguru with logging 2023-02-26 19:09:51 +02:00
setup.py chore(stable): release 3.2.1 (#2828) 2023-12-22 21:19:04 +01:00

README.md

Shared

The libretime_shared package contains reusable functions and classes for the LibreTime project.

Usage

This library assumes that:

  • You will use Click to build a CLI for your app.
  • You will use Pydantic to validate objects in your app.

Configuration

First define a schema for your configuration in order to validate it. A schema is a class that inherit from pydantic.BaseModel. Some existing schemas can be reused such as libretime_shared.config.RabbitMQ or libretime_shared.config.Database.

Load your configuration using a subclass of libretime_shared.config.BaseConfig.

from pydantic import BaseModel

from libretime_shared.config import RabbitMQConfig, BaseConfig

class AnalyzerConfig(BaseModel):
    bpm_enabled: bool = False
    bpm_track_max_length: int

class Config(BaseConfig):
    rabbitmq: RabbitMQConfig
    analyzer: AnalyzerConfig

config = Config("/etc/libretime/config.yml")

Don't instantiate a sub model if it has a required field, otherwise the Config class import will raise a ValidationError.

CLI

Decorate your CLI commands with the shared decorators to add extra flags.

import click
from libretime_shared.cli import cli_logging_options, cli_config_options

from .app import App

@click.group()
def cli():
    pass

@cli.command()
@cli_config_options()
@cli_logging_options()
def run(**kwargs):
    app = App(**kwargs)
    return app.run()