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
6 changes: 3 additions & 3 deletions .github/actions/setup-poetry-env/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ inputs:
python-version:
required: false
description: "The python version to use"
default: "3.11"
default: "3.10"

runs:
using: "composite"
steps:
- name: Set up python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ inputs.python-version }}

Expand All @@ -22,7 +22,7 @@ runs:

- name: Load cached venv
id: cached-poetry-dependencies
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: .venv
key: venv-${{ runner.os }}-${{ inputs.python-version }}-${{ hashFiles('poetry.lock') }}
Expand Down
36 changes: 18 additions & 18 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,52 +5,50 @@ on:
branches:
- main
pull_request:
types: [opened, synchronize, reopened]
branches:
- main
workflow_dispatch: # For on demand runs
schedule:
- cron: 0 0 * * * # Scheduled run every day at midnight

jobs:
quality:
runs-on: ubuntu-latest
steps:
- name: Check out
uses: actions/checkout@v3
uses: actions/checkout@v4

- uses: actions/cache@v3
- uses: actions/cache@v4
with:
path: ~/.cache/pre-commit
key: pre-commit-${{ hashFiles('.pre-commit-config.yaml') }}

- name: Set up the environment
uses: ./.github/actions/setup-poetry-env

- name: Run pre-commit
run: poetry run pre-commit run -a --show-diff-on-failure

- name: Inspect dependencies
run: poetry run deptry .

- name: Check Poetry lock file consistency
run: poetry lock --check
- name: Run checks
run: make check

tox:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.10', '3.11']
python-version: ['3.10']
fail-fast: false
steps:
- name: Check out
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Set up python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- name: Install Poetry
uses: snok/install-poetry@v1

- name: Load cached venv
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: .tox
key: venv-${{ runner.os }}-${{ matrix.python-version }}-${{ hashFiles('poetry.lock') }}
Expand All @@ -61,8 +59,10 @@ jobs:
python -m pip install tox tox-gh-actions

- name: Test with tox
env:
SWXSOC_MISSION: padre
run: tox

- name: Upload coverage reports to Codecov with GitHub Action on Python 3.11
uses: codecov/codecov-action@v3
if: ${{ matrix.python-version == '3.11' }}
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v4
if: ${{ matrix.python-version == '3.10' }}
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
repos:

- repo: https://github.com/psf/black
rev: "22.8.0"
rev: "24.10.0"
hooks:
- id: black
args: ["--line-length=120"]
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ run: ## Install the poetry environment and install the pre-commit hooks
.PHONY: check
check: ## Run code quality tools.
@echo "🚀 Checking Poetry lock file consistency with 'pyproject.toml': Running poetry lock --check"
@poetry lock --check
@poetry check
@echo "🚀 Linting code: Running pre-commit"
@poetry run pre-commit run -a
@echo "🚀 Static type checking: Running mypy"
Expand Down
79 changes: 62 additions & 17 deletions metatracker/__init__.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,79 @@
# Set up logging
import logging
from pathlib import Path
from typing import Any, Optional

from swxsoc import log as swxsoc_log # type: ignore

from metatracker.config import load_config
from metatracker.config.config import MetaTrackerConfiguration

# Set up basic config for logging
logging.basicConfig(level=logging.INFO)
log = logging.getLogger(__name__)
# Set up Logging based on SWxSOC Logging
log = swxsoc_log

# Format Logging
color_formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")
CONFIGURATION = load_config()

# Set Up Console Logging
console_handler = logging.StreamHandler()
console_handler.setFormatter(color_formatter)
log.addHandler(console_handler)
_package_directory = Path(__file__).parent
_test_files_directory = _package_directory / "tests" / "test_files"


CONFIGURATION = load_config()
def get_config() -> MetaTrackerConfiguration:
"""
Retrieve the current global MetaTracker configuration.

Returns the module-level ``CONFIGURATION`` singleton that holds
database connection details, mission name, instrument definitions,
file levels, and file types used throughout the package.

def get_config():
"""
Get config
Returns
-------
MetaTrackerConfiguration
The active configuration instance for the MetaTracker package.

See Also
--------
set_config : Update or reload the global configuration.

Examples
--------
>>> from metatracker import get_config
>>> cfg = get_config()
>>> cfg.mission_name # doctest: +SKIP
'padre'
"""
return CONFIGURATION


def set_config(config: dict) -> None:
def set_config(config: Optional[dict[str, Any]] = None) -> None:
"""
Set config
Set or reload the global MetaTracker configuration.

Replaces the module-level ``CONFIGURATION`` singleton with a new
`MetaTrackerConfiguration` built from *config*. When called with no
arguments (or ``None``), the configuration is reloaded from the
current ``swxsoc`` config, which is driven by the ``SWXSOC_MISSION``
environment variable.

Parameters
----------
config : dict, optional
A dictionary of configuration values to apply. Keys may include
``"mission_name"``, ``"instruments"``, ``"file_levels"``,
``"file_types"``, ``"db_host"``, among others. If ``None``
(the default), the configuration is reloaded from ``swxsoc``.

See Also
--------
get_config : Retrieve the current global configuration.

Examples
--------
Reload configuration from the ``swxsoc`` defaults:

>>> from metatracker import set_config
>>> set_config() # doctest: +SKIP

Apply a custom configuration dictionary:

>>> set_config({"mission_name": "hermes", "db_host": "sqlite:///"}) # doctest: +SKIP
"""
global CONFIGURATION

Expand Down
4 changes: 3 additions & 1 deletion metatracker/config/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from typing import Any, Optional

from . import config


def load_config(new_config=None) -> config.MetaTrackerConfiguration:
def load_config(new_config: Optional[dict[str, Any]] = None) -> config.MetaTrackerConfiguration:
"""
Load configuration

Expand Down
Loading