Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
12 changes: 6 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ repos:
language: python
types: [python]

# - id: mypy
# name: mypy
# entry: mypy
# language: system
# types: [python]
# args: [--strict, --ignore-missing-imports, --exclude=tests]
- id: mypy
name: mypy
entry: mypy
language: system
types: [python]
args: [--strict, --ignore-missing-imports, --exclude=tests]
24 changes: 17 additions & 7 deletions docs/stylesheets/extra.css
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
html {
font-size: 16px;
}
font-size: 18px;
}



h1 {
font-weight: 600 !important;
color: #333 !important;
font-weight: 600 !important;
color: #333 !important;
}

[data-md-color-scheme="slate"] h1 {
font-weight: 600 !important;
color: #d7d7d7 !important;
}

h2 {
font-weight: 600 !important;
color: #333 !important;
font-weight: 600 !important;
color: #333 !important;
}

[data-md-color-scheme="slate"] h2 {
font-weight: 600 !important;
color: #d7d7d7 !important;
}
21 changes: 21 additions & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,27 @@
site_name: Batista Template Docs
repo_url: https://github.com/batistagroup/python-template
repo_name: batistagroup/python-template
copyright: CC-BY 4.0 © 2025 Batista Group
theme:
name: material
features:
- content.code.copy
- navigation.footer
palette:
# Palette toggle for light mode
- media: "(prefers-color-scheme: light)"
scheme: default
toggle:
icon: material/brightness-7
name: Switch to dark mode

# Palette toggle for dark mode
- media: "(prefers-color-scheme: dark)"
scheme: slate
toggle:
icon: material/brightness-4
name: Switch to light mode


extra_css:
- stylesheets/extra.css
Expand All @@ -22,3 +41,5 @@ markdown_extensions:
- def_list
- pymdownx.tasklist:
custom_checkbox: true
- admonition
- pymdownx.details
23 changes: 0 additions & 23 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ readme = "README.md"
requires-python = ">=3.12"
dependencies = [
"numpy>=2.2.3",
"tomli>=2.2.1",
"tqdm>=4.67.1",
]
authors = [{ name = "Anton Morgunov", email = "anton@ischemist.com" }]
Expand All @@ -18,7 +17,6 @@ Issues = "https://github.com/batistagroup/batistatemplate/issues"


[tool.setuptools]
packages = ["batistatemplate"]
package-dir = { "" = "src" }


Expand Down Expand Up @@ -57,24 +55,3 @@ lint.select = [
"SIM", # flake8-simplify
"I", # isort
]


# Section below is pretty standard logger configuration

[tool.logging]
version = 1
disable_existing_loggers = false

[tool.logging.formatters.standard]
format = "%(asctime)s [%(levelname)s] %(name)s (%(module)s:%(lineno)d): %(message)s"
datefmt = "%Y-%m-%d %H:%M:%S"

[tool.logging.handlers.console]
class = "logging.StreamHandler"
formatter = "standard"
stream = "ext://sys.stdout"

[tool.logging.loggers.batistatemplate]
handlers = ["console"]
propagate = false
level = "INFO"
90 changes: 41 additions & 49 deletions src/batistatemplate/utils/logging_config.py
Original file line number Diff line number Diff line change
@@ -1,60 +1,52 @@
import logging
import logging.config
import os
from pathlib import Path

import tomli
from typing import Any

# --- Hardcoded Configuration ---
LOGGING_CONFIG: dict[str, Any] = {
"version": 1,
"disable_existing_loggers": False,
"formatters": {
"standard": {
"format": "%(asctime)s [%(levelname)s] %(name)s: %(message)s",
"datefmt": "%Y-%m-%d %H:%M:%S",
}
},
"handlers": {
"console": {
"class": "logging.StreamHandler",
"formatter": "standard",
"stream": "ext://sys.stdout",
}
},
"loggers": {
"batistatemplate": {
"handlers": ["console"],
"propagate": False,
"level": "INFO", # Default level
}
},
}
# --- End Hardcoded Configuration ---


def setup_logging() -> None:
"""Configures logging for the application.

Reads the logging configuration from the 'pyproject.toml' file
and applies it using `logging.config.dictConfig`.

The log level can be overridden by setting the
'BATISTATEMPLATE_LOG_LEVEL' environment variable. If the environment
variable is not set or set to an invalid level, it defaults to 'INFO'.

Raises:
FileNotFoundError: If 'pyproject.toml' is not found.
tomli.TOMLDecodeError: If 'pyproject.toml' is not a valid TOML file.
KeyError: If the 'tool.logging' section is missing in 'pyproject.toml'.
"""
# Construct the path to pyproject.toml, assuming it's 3 levels up from this file.
pyproject_path = Path(__file__).parents[3] / "pyproject.toml"

try:
with open(pyproject_path, "rb") as f:
config = tomli.load(f)
except FileNotFoundError as e:
raise FileNotFoundError(f"pyproject.toml not found at {pyproject_path}: {e}") from e
except tomli.TOMLDecodeError as e:
raise tomli.TOMLDecodeError(f"Failed to decode pyproject.toml: {e}") from e

# Determine the log level:
# 1. Check for BATISTATEMPLATE_LOG_LEVEL environment variable.
# 2. Default to 'INFO' if not set or invalid.
log_level_env = os.getenv("BATISTATEMPLATE_LOG_LEVEL", "INFO").upper()
"""Setup logging configuration from hardcoded dict with environment variable override"""

# Get log level from environment variable, default to INFO if not set
log_level = os.getenv("BATISTATEMPLATE_LOG_LEVEL", "INFO").upper()

# Validate the log level
valid_levels = {"DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"}
if log_level_env not in valid_levels:
print(f"Invalid log level '{log_level_env}' from environment, defaulting to INFO")
log_level = "INFO"
else:
log_level = log_level_env

try:
# Extract logging configuration from pyproject.toml
logging_config = config["tool"]["logging"]
except KeyError as e:
raise KeyError(f"'tool.logging' section not found in pyproject.toml: {e}") from e

# Override the log level specified in pyproject.toml with the determined log level.
logging_config["loggers"]["batistatemplate"]["level"] = log_level

# Configure logging using the dictionary configuration.
logging.config.dictConfig(logging_config)
if log_level not in valid_levels:
print(f"Invalid log level {log_level}, defaulting to INFO")
log_level = "INFO" # Make sure to reset if invalid

# Override the log level in the copied config
LOGGING_CONFIG["loggers"]["batistatemplate"]["level"] = log_level

logging.config.dictConfig(LOGGING_CONFIG)


# Get the logger for the 'batistatemplate' application.
Expand Down
31 changes: 0 additions & 31 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading