New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

setconfig

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

setconfig - pypi Package Compare versions

Comparing version
1.4.0
to
1.4.1
+17
-4
PKG-INFO
Metadata-Version: 2.1
Name: setconfig
Version: 1.4.0
Version: 1.4.1
Summary: Multi-structure YAML config loader 🐍🔌

@@ -46,2 +46,3 @@ Home-page: https://github.com/abionics/setconfig

- [x] Value overriding
- [x] Tuple-friendly

@@ -118,2 +119,3 @@

#### Loading from string/StringIO/etc
```python

@@ -126,5 +128,7 @@ from setconfig import load_config_stream

#### Multiple config files, full sample [here](examples/example_multi.py)
```python
config = load_config('config.base.yaml', 'config.dev.yaml', 'config.feature-x.yaml', into=Config)
```
Configs are processed in the order they are passed to `load_config` (from left to right), where

@@ -134,13 +138,22 @@ last overrides the previous ones

#### Value overriding, full sample [here](examples/example_override.py)
```python
config = load_config('example.yaml', into=Config, override={'timeout': 10})
config = load_config('config.yaml', into=Config, override={'timeout': 10})
```
#### Extra parsing params
```python
# `check_types` is a dacite flag, see https://github.com/konradhalas/dacite#type-checking
config = load_config('example.yaml', into=Config, check_types=False)
config = load_config('config.yaml', into=Config, check_types=False)
```
Where `check_types` is a dacite flag, see https://github.com/konradhalas/dacite#type-checking
#### Tuple-friendly
There is [known issue](https://github.com/konradhalas/dacite/issues/227) in `dacite` that raises type error
when loading list into tuple. [Pull request with fix is ready](https://github.com/konradhalas/dacite/pull/228)
since May 2023, but not merged yet... That's why `setconfig` has its own fix
## FAQ

@@ -147,0 +160,0 @@

@@ -19,2 +19,3 @@ # setconfig 🔌

- [x] Value overriding
- [x] Tuple-friendly

@@ -91,2 +92,3 @@

#### Loading from string/StringIO/etc
```python

@@ -99,5 +101,7 @@ from setconfig import load_config_stream

#### Multiple config files, full sample [here](examples/example_multi.py)
```python
config = load_config('config.base.yaml', 'config.dev.yaml', 'config.feature-x.yaml', into=Config)
```
Configs are processed in the order they are passed to `load_config` (from left to right), where

@@ -107,13 +111,22 @@ last overrides the previous ones

#### Value overriding, full sample [here](examples/example_override.py)
```python
config = load_config('example.yaml', into=Config, override={'timeout': 10})
config = load_config('config.yaml', into=Config, override={'timeout': 10})
```
#### Extra parsing params
```python
# `check_types` is a dacite flag, see https://github.com/konradhalas/dacite#type-checking
config = load_config('example.yaml', into=Config, check_types=False)
config = load_config('config.yaml', into=Config, check_types=False)
```
Where `check_types` is a dacite flag, see https://github.com/konradhalas/dacite#type-checking
#### Tuple-friendly
There is [known issue](https://github.com/konradhalas/dacite/issues/227) in `dacite` that raises type error
when loading list into tuple. [Pull request with fix is ready](https://github.com/konradhalas/dacite/pull/228)
since May 2023, but not merged yet... That's why `setconfig` has its own fix
## FAQ

@@ -120,0 +133,0 @@

Metadata-Version: 2.1
Name: setconfig
Version: 1.4.0
Version: 1.4.1
Summary: Multi-structure YAML config loader 🐍🔌

@@ -46,2 +46,3 @@ Home-page: https://github.com/abionics/setconfig

- [x] Value overriding
- [x] Tuple-friendly

@@ -118,2 +119,3 @@

#### Loading from string/StringIO/etc
```python

@@ -126,5 +128,7 @@ from setconfig import load_config_stream

#### Multiple config files, full sample [here](examples/example_multi.py)
```python
config = load_config('config.base.yaml', 'config.dev.yaml', 'config.feature-x.yaml', into=Config)
```
Configs are processed in the order they are passed to `load_config` (from left to right), where

@@ -134,13 +138,22 @@ last overrides the previous ones

#### Value overriding, full sample [here](examples/example_override.py)
```python
config = load_config('example.yaml', into=Config, override={'timeout': 10})
config = load_config('config.yaml', into=Config, override={'timeout': 10})
```
#### Extra parsing params
```python
# `check_types` is a dacite flag, see https://github.com/konradhalas/dacite#type-checking
config = load_config('example.yaml', into=Config, check_types=False)
config = load_config('config.yaml', into=Config, check_types=False)
```
Where `check_types` is a dacite flag, see https://github.com/konradhalas/dacite#type-checking
#### Tuple-friendly
There is [known issue](https://github.com/konradhalas/dacite/issues/227) in `dacite` that raises type error
when loading list into tuple. [Pull request with fix is ready](https://github.com/konradhalas/dacite/pull/228)
since May 2023, but not merged yet... That's why `setconfig` has its own fix
## FAQ

@@ -147,0 +160,0 @@

@@ -7,14 +7,18 @@ """

__version__ = '1.4.0'
__version__ = '1.4.1'
from dataclasses import is_dataclass
from functools import lru_cache
from pathlib import Path
from types import SimpleNamespace
from typing import TypeVar, Type, Any
from typing import TypeVar, Any, Callable, get_origin
import yaml
from dacite import from_dict, Config
from dacite.generics import get_concrete_type_hints
from dacite.types import extract_generic
from pydantic import BaseModel
DEFAULT_CONFIG_PATH = 'config.yaml'
HOOKS_CACHE_SIZE = 256

@@ -26,3 +30,3 @@ T = TypeVar('T')

*paths: Path | str,
into: Type[T] | None = None,
into: type[T] | None = None,
override: dict | None = None,

@@ -37,3 +41,2 @@ **kwargs,

])
print(data)
return load_config_dict(data, into, override, **kwargs)

@@ -44,3 +47,3 @@

stream: Any,
into: Type[T] | None = None,
into: type[T] | None = None,
override: dict | None = None,

@@ -55,3 +58,3 @@ **kwargs,

data: dict,
into: Type[T] | None = None,
into: type[T] | None = None,
override: dict | None = None,

@@ -65,3 +68,5 @@ **kwargs,

if is_dataclass(into):
config = Config(**kwargs)
hooks = _create_hooks(into)
strict = kwargs.pop('strict', True)
config = Config(hooks, strict=strict, **kwargs, )
return from_dict(into, data, config) # type: ignore

@@ -107,1 +112,20 @@ if issubclass(into, BaseModel):

base[key] = value
@lru_cache(maxsize=HOOKS_CACHE_SIZE)
def _create_hooks(dataclass: type[T]) -> dict[type, Callable[[Any], Any]]:
hooks = dict()
hints = get_concrete_type_hints(dataclass)
for type_full in hints.values():
type_origin = get_origin(type_full) or type_full
if type_origin is tuple:
hooks[type_full] = lambda x: tuple(x)
elif is_dataclass(type_full):
field_hooks = _create_hooks(type_full)
hooks.update(field_hooks)
else:
for sub_type in extract_generic(type_full):
if is_dataclass(sub_type):
sub_hooks = _create_hooks(sub_type)
hooks.update(sub_hooks)
return hooks