@@ -81,6 +81,8 @@ pub(crate) async fn run(
8181 native_tls : bool ,
8282 cache : & Cache ,
8383 printer : Printer ,
84+ env_file : Vec < PathBuf > ,
85+ no_env_file : bool ,
8486) -> anyhow:: Result < ExitStatus > {
8587 // These cases seem quite complex because (in theory) they should change the "current package".
8688 // Let's ban them entirely for now.
@@ -107,6 +109,44 @@ pub(crate) async fn run(
107109 // Initialize any shared state.
108110 let state = SharedState :: default ( ) ;
109111
112+ // Read from the `.env` file, if necessary.
113+ if !no_env_file {
114+ for env_file_path in env_file. iter ( ) . rev ( ) . map ( PathBuf :: as_path) {
115+ match dotenvy:: from_path ( env_file_path) {
116+ Err ( dotenvy:: Error :: Io ( err) ) if err. kind ( ) == std:: io:: ErrorKind :: NotFound => {
117+ bail ! (
118+ "No environment file found at: `{}`" ,
119+ env_file_path. simplified_display( )
120+ ) ;
121+ }
122+ Err ( dotenvy:: Error :: Io ( err) ) => {
123+ bail ! (
124+ "Failed to read environment file `{}`: {err}" ,
125+ env_file_path. simplified_display( )
126+ ) ;
127+ }
128+ Err ( dotenvy:: Error :: LineParse ( content, position) ) => {
129+ warn_user ! (
130+ "Failed to parse environment file `{}` at position {position}: {content}" ,
131+ env_file_path. simplified_display( ) ,
132+ ) ;
133+ }
134+ Err ( err) => {
135+ warn_user ! (
136+ "Failed to parse environment file `{}`: {err}" ,
137+ env_file_path. simplified_display( ) ,
138+ ) ;
139+ }
140+ Ok ( ( ) ) => {
141+ debug ! (
142+ "Read environment file at: `{}`" ,
143+ env_file_path. simplified_display( )
144+ ) ;
145+ }
146+ }
147+ }
148+ }
149+
110150 // Initialize any output reporters.
111151 let download_reporter = PythonDownloadReporter :: single ( printer) ;
112152
0 commit comments