File: ipython.py

package info (click to toggle)
python-dynaconf 3.2.12-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,900 kB
  • sloc: python: 21,464; sh: 9; makefile: 4
file content (18 lines) | stat: -rw-r--r-- 908 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
from __future__ import print_function
_A='store_true'
from IPython.core.magic import Magics,line_magic,magics_class
from IPython.core.magic_arguments import argument,magic_arguments,parse_argstring
from.main import find_dotenv,load_dotenv
@magics_class
class IPythonDotEnv(Magics):
	@magic_arguments()
	@argument('-o','--override',action=_A,help='Indicate to override existing variables')
	@argument('-v','--verbose',action=_A,help='Indicate function calls to be verbose')
	@argument('dotenv_path',nargs='?',type=str,default='.env',help='Search in increasingly higher folders for the `dotenv_path`')
	@line_magic
	def dotenv(self,line):
		A=parse_argstring(self.dotenv,line);B=A.dotenv_path
		try:B=find_dotenv(B,True,True)
		except IOError:print('cannot find .env file');return
		load_dotenv(B,verbose=A.verbose,override=A.override)
def load_ipython_extension(ipython):ipython.register_magics(IPythonDotEnv)