Skip to content

Commit

Permalink
Merge pull request #12 from jordantshaw/rc-0.2.2
Browse files Browse the repository at this point in the history
Fixing bug with optional dependencies
  • Loading branch information
jordantshaw authored Jul 19, 2023
2 parents 3485db7 + 63e8252 commit 12cb5cf
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ build-backend = "setuptools.build_meta"
[project]
name = "pydantic-config"
description = "Support for Pydantic settings configuration file loading"
version = "0.2.1"
version = "0.2.2"
authors = [{name="Jordan Shaw"}]
readme = "README.md"
requires-python = ">=3.7"
Expand Down
16 changes: 14 additions & 2 deletions src/pydantic_config/readers.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import configparser
import json
import toml
import yaml


def json_file_reader(file: str, encoding: str = None):
Expand All @@ -19,11 +17,25 @@ def ini_file_reader(file: str, encoding: str = None):

def toml_file_reader(file: str, encoding: str = None):
""" .toml file type reader """
try:
import toml
except ModuleNotFoundError as exc:
raise ModuleNotFoundError(
"No module named 'toml'. The 'toml' package is required when loading `.toml` config files."
)

return toml.load(file)


def yaml_file_reader(file: str, encoding: str = None):
""" .yaml file type reader """
try:
import yaml
except ModuleNotFoundError as exc:
raise ModuleNotFoundError(
"No module named 'yaml'. The 'pyyaml' package is required when loading `.yaml/yml` config files."
)

with open(file, 'r', encoding=encoding) as file:
return yaml.safe_load(file)

Expand Down

0 comments on commit 12cb5cf

Please sign in to comment.