pyconfs/configuration.py
def update_from_env(
        self,
        env_paths: Dict[str, Sequence[str]],
        converters: Optional[Dict[str, str]] = None,
        prefix: str = "",
    ) -> None:
        """Update the configuration from environment variables"""
        converters = {} if converters is None else converters

        # Apply prefix
        env_paths = {f"{prefix}{k}": v for k, v in env_paths.items()}
        converters = {f"{prefix}{k}": v for k, v in converters.items()}

        # Loop through the variables defined in the environment
        for var in set(os.environ) & set(env_paths):
            value = os.environ[var]

            # Convert type of value
            if var in converters:
                converter = converters[var]
                try:
                    if callable(converter):
                        value = converter(value)
                    else:
                        value = _converters.convert(f"to_{converter}", value=value)
                except ValueError:
                    warnings.warn(
                        RuntimeWarning(
                            f"Could not convert {var}={value!r} using {converter}"
                        ),
                        stacklevel=2,
                    )
                    break

            # Walk down tree for given entry
            entry = entry_tree = {}
            *entry_path, entry_key = env_paths[var]
            for key in entry_path:
                entry = entry.setdefault(key, {})
            entry[entry_key] = value

            # Update configuration with new entry
            self.update_from_dict(entry_tree, source=f"{var} (environment variable)")
Update the configuration from environment variables
Update the configuration from environment variables
Update the configuration from environment variables
def update_from_env(
        self,
        env_paths: Dict[str, Sequence[str]],
        converters: Optional[Dict[str, str]] = None,
        prefix: str = "",
    ) -> None:
        converters = {} if converters is None else converters
        env_paths = {f"{prefix}{k}": v for k, v in env_paths.items()}
        converters = {f"{prefix}{k}": v for k, v in converters.items()}
        for var in set(os.environ) & set(env_paths):
            value = os.environ[var]
            if var in converters:
                converter = converters[var]
                try:
                    if callable(converter):
                        value = converter(value)
                    else:
                        value = _converters.convert(f"to_{converter}", value=value)
                except ValueError:
                    warnings.warn(
                        RuntimeWarning(
                            f"Could not convert {var}={value!r} using {converter}"
                        ),
                        stacklevel=2,
                    )
                    break
            entry = entry_tree = {}
            *entry_path, entry_key = env_paths[var]
            for key in entry_path:
                entry = entry.setdefault(key, {})
            entry[entry_key] = value
            self.update_from_dict(entry_tree, source=f"{var} (environment variable)")
def update_from_env ( self , env_paths : Dict [ str , Sequence [ str ] ] , converters : Optional [ Dict [ str , str ] ] = None , prefix : str = "" , ) -> None : converters = { } if converters is None else converters env_paths = { f"{prefix}{k}" : v for k , v in env_paths . items ( ) } converters = { f"{prefix}{k}" : v for k , v in converters . items ( ) } for var in set ( os . environ ) & set ( env_paths ) : value = os . environ [ var ] if var in converters : converter = converters [ var ] try : if callable ( converter ) : value = converter ( value ) else : value = _converters . convert ( f"to_{converter}" , value = value ) except ValueError : warnings . warn ( RuntimeWarning ( f"Could not convert {var}={value!r} using {converter}" ) , stacklevel = 2 , ) break entry = entry_tree = { } * entry_path , entry_key = env_paths [ var ] for key in entry_path : entry = entry . setdefault ( key , { } ) entry [ entry_key ] = value self . update_from_dict ( entry_tree , source = f"{var} (environment variable)" )
Update the configuration from environment variables
Update the configuration from environment variables
"""Update the configuration from environment variables""" # Apply prefix # Loop through the variables defined in the environment # Convert type of value # Walk down tree for given entry # Update configuration with new entry
self
env_paths
Dict[str, Sequence[str]]
converters
Optional[Dict[str, str]]
prefix
str