Skip to main content

Bibliothèque pour se faciliter le scripting !

Project description

Automathèque

Code de base pour automatheque.

Installation

mais il est peu probable que vous ayez besoin de l'installer, c'est avant tout une dépendance.

pip install automatheque

Dépendances

  • voir pyproject.toml

Install en mode dev

pip install -e .[dev,docs] ou monas install depuis la racine.

Usage : Utilitaire pour script

from automatheque.script import script  # alias court de script_automatheque

@script(__doc__, __version__)
def main(_script):
    print(_script.config)

if __name__ == '__main__':
    main()

L'API a été promue de automatheque.util.script vers automatheque.script (#41). L'ancien chemin reste importable (shim) mais émet un DeprecationWarning : migrez vers from automatheque.script import script.

Le décorateur câble automatiquement, si le script les déclare dans son usage : --dry-run (via _script.dry_run), la verbosité -v/-q (niveau de log), une sortie propre sur Ctrl-C (code 130), et la durée d'exécution.

Sous-commandes (via commandopt)

On déclare des fonctions-commandes avec @commande([...]) (alias de commandopt.commandopt) et on aiguille avec _script.execute_commande(). Les options internes d'automatheque (--config, --dry-run, -v/-q) sont exclues de la sélection, mais restent transmises à la commande.

"""Mon script

Usage:
  mon_script.py (--ajouter | --supprimer) [--config=<f>] [-v]
"""
from automatheque.script import script, commande

@commande(["--ajouter"])
def ajouter(arguments):
    ...

@commande(["--supprimer"])
def supprimer(arguments):
    ...

@script(__doc__, __version__)
def main(_script):
    return _script.execute_commande()

if __name__ == '__main__':
    main()

Configuration du logging

Automathèque ne configure rien à l'import (une bibliothèque ne doit pas toucher au logging global). C'est l'application qui configure : un script décoré par @script_automatheque appelle configure_logging_defaut() (sortie console) puis applique la section [log] de sa configuration.

Un script étant une application, sa configuration de log vise la racine : logging.getLogger(__name__) dans le script et les loggers des dépendances en héritent.

Forme simple (inline dans le .ini)

Dans le config.ini du script (~/.config/<mon_script>/config.ini) :

[log]
niveau = INFO
fichier = mon_script.log          ; optionnel (sinon console)
format  = %%(asctime)s [%%(levelname)s] %%(name)s: %%(message)s
; niveaux par logger (nom seul = niveau global) :
names   = automatheque:WARNING, mon_script:DEBUG, requests:ERROR

Dans un .ini, les % se doublent en %% (convention ConfigParser) ; un % non échappé lève une erreur explicite.

Un seul handler/destination est partagé ; names n'ajuste que des niveaux.

Forme complète (dictConfig externe)

Pour router des loggers vers des destinations différentes (erreurs du script dans un fichier, automatheque ailleurs…), pointer vers un dictConfig complet (JSON ou YAML, détecté au contenu) :

[log]
fichier_config = log.yaml

Voir l'exemple canonique log.yaml.dist.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

automatheque-0.14.2.tar.gz (38.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

automatheque-0.14.2-py3-none-any.whl (39.5 kB view details)

Uploaded Python 3

File details

Details for the file automatheque-0.14.2.tar.gz.

File metadata

  • Download URL: automatheque-0.14.2.tar.gz
  • Upload date:
  • Size: 38.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for automatheque-0.14.2.tar.gz
Algorithm Hash digest
SHA256 c610a4993754e1c93d610eb6b248cea0d3d7b7766d37f632f60330381aa95994
MD5 0061289ac1ee890f9fa7262d9a55442b
BLAKE2b-256 bf04c389fbdc56441c0d1d81b2fd782e20fe05977b183980053a62545fc70346

See more details on using hashes here.

Provenance

The following attestation bundles were made for automatheque-0.14.2.tar.gz:

Publisher: release.yml on jaegerbobomb/automatheque

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file automatheque-0.14.2-py3-none-any.whl.

File metadata

  • Download URL: automatheque-0.14.2-py3-none-any.whl
  • Upload date:
  • Size: 39.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for automatheque-0.14.2-py3-none-any.whl
Algorithm Hash digest
SHA256 2b2b1207aff389443b8c066126ad272df3b0bccae613174d40b4269138feab4f
MD5 e4b42eb7dbb6d7ef56d186279474360e
BLAKE2b-256 a7348dedcbe9e44290b76045c7a69f1c56fa0f13d0ef444661a88c20ce6b1848

See more details on using hashes here.

Provenance

The following attestation bundles were made for automatheque-0.14.2-py3-none-any.whl:

Publisher: release.yml on jaegerbobomb/automatheque

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page