File tree Expand file tree Collapse file tree 4 files changed +25
-2
lines changed
Expand file tree Collapse file tree 4 files changed +25
-2
lines changed Original file line number Diff line number Diff line change @@ -171,6 +171,21 @@ pub trait System: Debug {
171171 PatternError ,
172172 > ;
173173
174+ /// Fetches the environment variable `key` from the current process.
175+ ///
176+ /// # Errors
177+ ///
178+ /// Returns [`std::env::VarError::NotPresent`] if:
179+ /// - The variable is not set.
180+ /// - The variable's name contains an equal sign or NUL (`'='` or `'\0'`).
181+ ///
182+ /// Returns [`std::env::VarError::NotUnicode`] if the variable's value is not valid
183+ /// Unicode.
184+ fn env_var ( & self , name : & str ) -> std:: result:: Result < String , std:: env:: VarError > {
185+ let _ = name;
186+ Err ( std:: env:: VarError :: NotPresent )
187+ }
188+
174189 fn as_any ( & self ) -> & dyn std:: any:: Any ;
175190
176191 fn as_any_mut ( & mut self ) -> & mut dyn std:: any:: Any ;
Original file line number Diff line number Diff line change @@ -214,6 +214,10 @@ impl System for OsSystem {
214214 } )
215215 } ) ) )
216216 }
217+
218+ fn env_var ( & self , name : & str ) -> std:: result:: Result < String , std:: env:: VarError > {
219+ std:: env:: var ( name)
220+ }
217221}
218222
219223impl OsSystem {
Original file line number Diff line number Diff line change @@ -192,12 +192,12 @@ impl Options {
192192 PythonPath :: sys_prefix ( python_path. absolute ( project_root, system) , origin)
193193 } )
194194 . or_else ( || {
195- std :: env :: var ( "VIRTUAL_ENV" ) . ok ( ) . map ( |virtual_env| {
195+ system . env_var ( "VIRTUAL_ENV" ) . ok ( ) . map ( |virtual_env| {
196196 PythonPath :: sys_prefix ( virtual_env, SysPrefixPathOrigin :: VirtualEnvVar )
197197 } )
198198 } )
199199 . or_else ( || {
200- std :: env :: var ( "CONDA_PREFIX" ) . ok ( ) . map ( |path| {
200+ system . env_var ( "CONDA_PREFIX" ) . ok ( ) . map ( |path| {
201201 PythonPath :: sys_prefix ( path, SysPrefixPathOrigin :: CondaPrefixVar )
202202 } )
203203 } )
Original file line number Diff line number Diff line change @@ -247,6 +247,10 @@ impl System for LSPSystem {
247247 fn case_sensitivity ( & self ) -> CaseSensitivity {
248248 self . os_system . case_sensitivity ( )
249249 }
250+
251+ fn env_var ( & self , name : & str ) -> std:: result:: Result < String , std:: env:: VarError > {
252+ self . os_system . env_var ( name)
253+ }
250254}
251255
252256fn not_a_text_document ( path : impl Display ) -> std:: io:: Error {
You can’t perform that action at this time.
0 commit comments