@@ -128,19 +128,14 @@ pub fn get_conda_installation_used_to_create_conda_env(env_path: &Path) -> Optio
128128
129129 // First look for the conda-meta/history file in the environment folder.
130130 // This could be a conda envirment (not root) but has `conda` installed in it.
131- let conda_meta_history = env_path. join ( "conda-meta" ) . join ( "history" ) ;
132- if let Ok ( reader) = std:: fs:: read_to_string ( conda_meta_history. clone ( ) ) {
133- if let Some ( line) = reader. lines ( ) . map ( |l| l. trim ( ) ) . find ( |l| {
134- l. to_lowercase ( ) . starts_with ( "# cmd:" ) && l. to_lowercase ( ) . contains ( " create -" )
135- } ) {
136- // Sample lines
137- // # cmd: <conda install directory>\Scripts\conda-script.py create -n samlpe1
138- // # cmd: <conda install directory>\Scripts\conda-script.py create -p <full path>
139- // # cmd: /Users/donjayamanne/miniconda3/bin/conda create -n conda1
140- if let Some ( conda_dir) = get_conda_dir_from_cmd ( line. into ( ) ) {
141- if is_conda_install ( & conda_dir) {
142- return Some ( conda_dir) ;
143- }
131+ if let Some ( line) = get_conda_creation_line_from_history ( env_path) {
132+ // Sample lines
133+ // # cmd: <conda install directory>\Scripts\conda-script.py create -n samlpe1
134+ // # cmd: <conda install directory>\Scripts\conda-script.py create -p <full path>
135+ // # cmd: /Users/donjayamanne/miniconda3/bin/conda create -n conda1
136+ if let Some ( conda_dir) = get_conda_dir_from_cmd ( line) {
137+ if is_conda_install ( & conda_dir) {
138+ return Some ( conda_dir) ;
144139 }
145140 }
146141 }
@@ -153,6 +148,24 @@ pub fn get_conda_installation_used_to_create_conda_env(env_path: &Path) -> Optio
153148 }
154149}
155150
151+ pub fn get_conda_creation_line_from_history ( env_path : & Path ) -> Option < String > {
152+ let conda_meta_history = env_path. join ( "conda-meta" ) . join ( "history" ) ;
153+ if let Ok ( reader) = std:: fs:: read_to_string ( conda_meta_history. clone ( ) ) {
154+ if let Some ( line) = reader. lines ( ) . map ( |l| l. trim ( ) ) . find ( |l| {
155+ l. to_lowercase ( ) . starts_with ( "# cmd:" ) && l. to_lowercase ( ) . contains ( " create -" )
156+ } ) {
157+ trace ! (
158+ "Conda creation line for {:?} is from history file is {:?}" ,
159+ env_path,
160+ line
161+ ) ;
162+ return Some ( line. into ( ) ) ;
163+ }
164+ }
165+
166+ None
167+ }
168+
156169fn get_conda_env_name (
157170 env_path : & Path ,
158171 prefix : & Path ,
@@ -191,20 +204,13 @@ fn get_conda_env_name_from_history_file(env_path: &Path, prefix: &Path) -> Optio
191204 . map ( |name| name. to_str ( ) . unwrap_or_default ( ) . to_string ( ) ) ;
192205
193206 if let Some ( name) = name {
194- // First look for the conda-meta/history file in the environment folder.
195- // This could be a conda envirment (not root) but has `conda` installed in it.
196- let conda_meta_history = env_path. join ( "conda-meta" ) . join ( "history" ) ;
197- if let Ok ( reader) = std:: fs:: read_to_string ( conda_meta_history. clone ( ) ) {
198- if let Some ( line) = reader. lines ( ) . map ( |l| l. trim ( ) ) . find ( |l| {
199- l. to_lowercase ( ) . starts_with ( "# cmd:" ) && l. to_lowercase ( ) . contains ( " create -" )
200- } ) {
201- // Sample lines
202- // # cmd: <conda install directory>\Scripts\conda-script.py create -n samlpe1
203- // # cmd: <conda install directory>\Scripts\conda-script.py create -p <full path>
204- // # cmd: /Users/donjayamanne/miniconda3/bin/conda create -n conda1
205- if is_conda_env_name_in_cmd ( line. into ( ) , & name) {
206- return Some ( name) ;
207- }
207+ if let Some ( line) = get_conda_creation_line_from_history ( env_path) {
208+ // Sample lines
209+ // # cmd: <conda install directory>\Scripts\conda-script.py create -n samlpe1
210+ // # cmd: <conda install directory>\Scripts\conda-script.py create -p <full path>
211+ // # cmd: /Users/donjayamanne/miniconda3/bin/conda create -n conda1
212+ if is_conda_env_name_in_cmd ( line. into ( ) , & name) {
213+ return Some ( name) ;
208214 }
209215 }
210216 }
0 commit comments