11import os
22import sys
33from subprocess import Popen
4+ from typing import Any , Dict , List
45
56try :
67 import click
910 'Run pip install "python-dotenv[cli]" to fix this.' )
1011 sys .exit (1 )
1112
12- from .compat import IS_TYPE_CHECKING , to_env
1313from .main import dotenv_values , get_key , set_key , unset_key
1414from .version import __version__
1515
16- if IS_TYPE_CHECKING :
17- from typing import Any , List , Dict
18-
1916
2017@click .group ()
2118@click .option ('-f' , '--file' , default = os .path .join (os .getcwd (), '.env' ),
2926 help = "Whether to write the dot file as an executable bash script." )
3027@click .version_option (version = __version__ )
3128@click .pass_context
32- def cli (ctx , file , quote , export ):
33- # type: (click.Context, Any, Any, Any) -> None
29+ def cli (ctx : click .Context , file : Any , quote : Any , export : Any ) -> None :
3430 '''This script is used to set, get or unset values from a .env file.'''
3531 ctx .obj = {}
3632 ctx .obj ['QUOTE' ] = quote
@@ -40,8 +36,7 @@ def cli(ctx, file, quote, export):
4036
4137@cli .command ()
4238@click .pass_context
43- def list (ctx ):
44- # type: (click.Context) -> None
39+ def list (ctx : click .Context ) -> None :
4540 '''Display all the stored key/value.'''
4641 file = ctx .obj ['FILE' ]
4742 if not os .path .isfile (file ):
@@ -58,8 +53,7 @@ def list(ctx):
5853@click .pass_context
5954@click .argument ('key' , required = True )
6055@click .argument ('value' , required = True )
61- def set (ctx , key , value ):
62- # type: (click.Context, Any, Any) -> None
56+ def set (ctx : click .Context , key : Any , value : Any ) -> None :
6357 '''Store the given key/value.'''
6458 file = ctx .obj ['FILE' ]
6559 quote = ctx .obj ['QUOTE' ]
@@ -74,8 +68,7 @@ def set(ctx, key, value):
7468@cli .command ()
7569@click .pass_context
7670@click .argument ('key' , required = True )
77- def get (ctx , key ):
78- # type: (click.Context, Any) -> None
71+ def get (ctx : click .Context , key : Any ) -> None :
7972 '''Retrieve the value for the given key.'''
8073 file = ctx .obj ['FILE' ]
8174 if not os .path .isfile (file ):
@@ -93,8 +86,7 @@ def get(ctx, key):
9386@cli .command ()
9487@click .pass_context
9588@click .argument ('key' , required = True )
96- def unset (ctx , key ):
97- # type: (click.Context, Any) -> None
89+ def unset (ctx : click .Context , key : Any ) -> None :
9890 '''Removes the given key.'''
9991 file = ctx .obj ['FILE' ]
10092 quote = ctx .obj ['QUOTE' ]
@@ -113,8 +105,7 @@ def unset(ctx, key):
113105 help = "Override variables from the environment file with those from the .env file." ,
114106)
115107@click .argument ('commandline' , nargs = - 1 , type = click .UNPROCESSED )
116- def run (ctx , override , commandline ):
117- # type: (click.Context, bool, List[str]) -> None
108+ def run (ctx : click .Context , override : bool , commandline : List [str ]) -> None :
118109 """Run command with environment variables present."""
119110 file = ctx .obj ['FILE' ]
120111 if not os .path .isfile (file ):
@@ -123,9 +114,9 @@ def run(ctx, override, commandline):
123114 ctx = ctx
124115 )
125116 dotenv_as_dict = {
126- to_env ( k ): to_env ( v )
117+ k : v
127118 for (k , v ) in dotenv_values (file ).items ()
128- if v is not None and (override or to_env ( k ) not in os .environ )
119+ if v is not None and (override or k not in os .environ )
129120 }
130121
131122 if not commandline :
@@ -135,8 +126,7 @@ def run(ctx, override, commandline):
135126 exit (ret )
136127
137128
138- def run_command (command , env ):
139- # type: (List[str], Dict[str, str]) -> int
129+ def run_command (command : List [str ], env : Dict [str , str ]) -> int :
140130 """Run command in sub process.
141131
142132 Runs the command in a sub process with the variables from `env`
0 commit comments