Skip to content
Open
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
22 changes: 22 additions & 0 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
name: Python tests
on: [push]

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
python: ["3.8", "3.9", "3.10", "3.11", "3.12"]
format: ["basic", "yaml", "hcl"]

steps:
- uses: actions/checkout@v4
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python }}
- name: Install tox and any other packages
run: pip install tox
- name: Run tox
run: tox -e py-${{ matrix.format }}
68 changes: 68 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
---
default_stages: [pre-commit]
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
# Attempts to load all json files to verify syntax.
- id: check-json

# Prettify JSON files
- id: pretty-format-json
args: [--autofix, --indent=4, --no-sort-keys]

# Check for files that contain merge conflict strings.
- id: check-merge-conflict

# Attempts to load all TOML files to verify syntax.
- id: check-toml

# Makes sure files end in a newline and only a newline.
- id: end-of-file-fixer
stages: [pre-commit, manual]

# Replaces or checks mixed line ending.
- id: mixed-line-ending
args: [--fix=no]

# Trims trailing whitespace.
- id: trailing-whitespace
args: [--markdown-linebreak-ext=md]
stages: [pre-commit, manual]

# Sorts entries in requirements.txt
- id: requirements-txt-fixer

# Sort imports
- repo: https://github.com/timothycrosley/isort
rev: 5.12.0
hooks:
- id: isort
args: [--profile=black]

# Fix common misspellings in source code
- repo: https://github.com/codespell-project/codespell
rev: v2.2.6
hooks:
- id: codespell
entry: codespell --write-changes

# Fast Python linter
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.1.6
hooks:
- id: ruff
args: [--target-version, "py312"]

# Shell script linter
- repo: https://github.com/shellcheck-py/shellcheck-py
rev: v0.9.0.6
hooks:
- id: shellcheck

# YAML linter
- repo: https://github.com/adrienverge/yamllint
rev: v1.33.0
hooks:
- id: yamllint
args: [--config-data, "{extends: relaxed, rules: {line-length: {max: 100}}}"]
12 changes: 0 additions & 12 deletions .travis.yml

This file was deleted.

34 changes: 30 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ confight

[![PyPI](https://img.shields.io/pypi/v/confight.svg)](https://pypi.org/project/confight/)
![PyPI - Python Version](https://img.shields.io/pypi/pyversions/confight.svg)
[![Build Status](https://travis-ci.org/Avature/confight.svg?branch=master)](https://travis-ci.org/Avature/confight)
![Build Status](https://github.com/Avature/confight/actions/workflows/tests.yaml/badge.svg)

One simple way of parsing configs

Expand Down Expand Up @@ -136,6 +136,29 @@ The list of _optional_ file formats:
In order to install confight with _optional_ formats see
[installation](#installation) with [optional features][].

## Custom Formats

Other formats can be registered by name providing a function with the loader signature
`loader(path)`.

```python
from confight import register_loader, register_extension

def load_assign(path):
"""Parse files with KEY=VALUE lines """
with open(path, 'r') as stream:
return dict(line.split('=', 1) for line in stream]

register_loader('equal', load_assign)
```

Extensions can also be associated to previously registered formats by adding them to the extension
register as alias so it automatically detects with `.eq` extension:

```python
register_extension('eq', format='equal')
```

## Parsing

Given a path to an existing configuration file, it will be loaded in memory
Expand All @@ -151,7 +174,7 @@ confight.parse('/path/to/config', format='toml')
When no format is given, it tries to guess by looking at file extensions:

```
confight.parse('/path/to/config.json') # will gess json format
confight.parse('/path/to/config.json') # will guess json format
```

You can see the list of all available extensions at `confight.FORMAT_EXTENSIONS`.
Expand Down Expand Up @@ -351,6 +374,10 @@ Install the application and run tests in development:
pip install -e .
python -m pytest

Make sure to install pre-commit before checking in any changes:

pre-commit install

Changelog
=========

Expand All @@ -371,7 +398,7 @@ Changelog
* 1.4.0 (2023-12-12)

[ Federico Fapitalle ]
* [3e618f3b] feat: adds support for HCL languaje
* [3e618f3b] feat: adds support for HCL language

[ Frank Lenormand ]
* [a9b3b9a2] fix(confight): Stick to older `ruamel.yaml` API
Expand Down Expand Up @@ -465,4 +492,3 @@ Changelog
* 0.0.1 (2018-03-27)

* Initial release.

Loading