Skip to content

Commit

Permalink
Merge pull request #1 from ajatkj/precommit_and_readme_changes
Browse files Browse the repository at this point in the history
Added pre-commit, updated readme etc.
  • Loading branch information
ajatkj authored Jan 23, 2024
2 parents 4908340 + 1f011fe commit f867ec4
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 32 deletions.
37 changes: 18 additions & 19 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,32 @@ name: Test

on:
push:
branches: [ "main" ]
branches: ["main"]
pull_request:
branches: [ "main" ]
branches: ["main"]

jobs:
build:

runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]

steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install flake8 pytest
if [ -f requirements-dev.txt ]; then pip install -r requirements-dev.txt; fi
- name: Lint
run: |
poe lint
- name: Test
run: |
poe test
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install flake8 pytest
if [ -f requirements-dev.txt ]; then pip install -r requirements-dev.txt; fi
- name: Lint
run: |
poe lint
- name: Test
run: |
poe test
22 changes: 22 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
default_language_version:
python: python3.10
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: check-added-large-files
- id: check-toml
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.1.14
hooks:
- id: ruff
args:
- --fix
- id: ruff-format
ci:
autofix_commit_msg: 🎨 [pre-commit.ci] Auto format from pre-commit.com hooks
autoupdate_commit_msg: ⬆ [pre-commit.ci] pre-commit hook autoupdate
48 changes: 35 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,44 @@
# TypedConfigparser

Typed ConfigParser is an extension of the standard configparser module with support for typed configurations using dataclasses.
<p align="center">
<img src="./assets/logo.png" alt="Description of the image">
</p>
<p align="center">
<a href="https://github.com/ajatkj/typed_configparser/actions?query=workflow%3ATest+event%3Apush+branch%3Amain" target="_blank">
<img src="https://img.shields.io/github/actions/workflow/status/ajatkj/typed_configparser/tests.yml?branch=main&event=push&style=flat-square&label=test" alt="Test">
</a>
<a href="https://pypi.org/project/fastapi" target="_blank">
<img src="https://img.shields.io/pypi/v/typed-configparser?color=%2334D058&label=pypi%20package&style=flat-square" alt="Package version">
</a>
<a href="https://pypi.org/project/fastapi" target="_blank">
<img src="https://img.shields.io/pypi/pyversions/typed-config-parser?color=%2334D058&style=flat-square" alt="Supported Python versions">
</a>
</p>

# typed-configparser

typed-configparser is an extension of the standard configparser module with support for typed configurations using dataclasses.
It leverages Python's type hints and dataclasses to provide a convenient way of parsing and validating configuration files.

## Features
- Fully typed.
- Use dataclasses to parse the configuration file.
- Support for almost all python built-in data types - `int`, `float`, `str`, `list`, `tuple`, `dict` and complex data types using `Union` and `Optional`.
- Built on top of `configparser`, hence retains all functionalities of `configparser`.
- Support for optional values (optional values are automatically set to `None` if not provided).
- Smarter defaults (see below).

✓ Fully typed.<br />
✓ Use dataclasses to parse the configuration file.<br />
✓ Support for almost all python built-in data types - `int`, `float`, `str`, `list`, `tuple`, `dict` and complex data types using `Union` and `Optional`.<br />
✓ Built on top of `configparser`, hence retains all functionalities of `configparser`.<br />
✓ Support for optional values (optional values are automatically set to `None` if not provided).<br />
✓ Smarter defaults (see below).

## Installation
You can install Typed ConfigParser using pip:

You can install `typed_configparser` using `pip`:

```sh
pip install typed-configparser
pip install typed_configparser
```

## Usage

`basic_example.py`

```py3
import dataclasses
from typed_configparser import ConfigParser
Expand All @@ -41,6 +61,7 @@ print(f"Debug Mode: {app_config.debug}")
```

`conf.ini`

```ini
[AppSection]
host = localhost
Expand All @@ -65,13 +86,14 @@ config_parser = ConfigParser()
app_config = config_parser.parse_section(AppConfig, section_name='AppSection')

```

Check `example` directory for more examples.

## Defaults

- `configparser` includes sensible defaults options which allows you to declare a `[DEFAULT]` section in the config file for fallback values.
- `typed_configparser` goes a step further and allows you to set a final level of defaults at dataclass level.


# License

[MIT License](./LICENSE)
[MIT License](./LICENSE)
Binary file added assets/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ dynamic = ["version"]
[tool.setuptools.packages.find]
exclude = ["typed_configparser.tests*", "types_configparser.examples"]

[tool.setuptools_scm]

[tool.mypy]
strict = true

Expand Down
4 changes: 4 additions & 0 deletions typed_configparser/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
"""Fully typed configparser"""

from .parser import ConfigParser

__version__ = "1.0.0"

__all__ = ["ConfigParser"]

0 comments on commit f867ec4

Please sign in to comment.