mirror of
				https://github.com/ets-labs/python-dependency-injector.git
				synced 2025-11-04 01:47:36 +03:00 
			
		
		
		
	Add example for os.environ.setdefault() and envs interpolation
This commit is contained in:
		
							parent
							
								
									f77c8b13e9
								
							
						
					
					
						commit
						e91f35fd52
					
				
							
								
								
									
										2
									
								
								examples/providers/configuration/config-with-env-var.yml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								examples/providers/configuration/config-with-env-var.yml
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,2 @@
 | 
			
		|||
section:
 | 
			
		||||
  option: ${ENV_VAR}
 | 
			
		||||
| 
						 | 
				
			
			@ -0,0 +1,19 @@
 | 
			
		|||
"""`Configuration` provider values loading example."""
 | 
			
		||||
 | 
			
		||||
import os
 | 
			
		||||
 | 
			
		||||
from dependency_injector import containers, providers
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class Container(containers.DeclarativeContainer):
 | 
			
		||||
 | 
			
		||||
    config = providers.Configuration()
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
if __name__ == '__main__':
 | 
			
		||||
    os.environ.setdefault('ENV_VAR', 'default value')
 | 
			
		||||
 | 
			
		||||
    container = Container()
 | 
			
		||||
    container.config.from_yaml('config-with-env-var.yml')
 | 
			
		||||
 | 
			
		||||
    assert container.config.section.option() == 'default value'
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user