Skip to content

Commit 66c99a3

Browse files
committed
log python env in analysis files
1 parent 86feacf commit 66c99a3

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

src/spyglass/common/common_nwbfile.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import os
22
import random
33
import string
4+
import subprocess
45
from pathlib import Path
56
from time import time
67
from uuid import uuid4
@@ -217,7 +218,7 @@ def create(self, nwb_file_name: str, restrict_permission=False) -> str:
217218
nwb_object.pop(module)
218219
# add the version of spyglass that created this file
219220
if nwbf.source_script is None:
220-
nwbf.source_script = f"spyglass={sg_version}"
221+
nwbf.source_script = self._logged_env_info()
221222
else:
222223
alter_source_script = True
223224

@@ -247,11 +248,22 @@ def create(self, nwb_file_name: str, restrict_permission=False) -> str:
247248

248249
return analysis_file_name
249250

250-
@staticmethod
251-
def _alter_spyglass_version(nwb_file_path: str) -> None:
251+
@classmethod
252+
def _alter_spyglass_version(cls, nwb_file_path: str) -> None:
252253
"""Change the source script to the current version of spyglass"""
253254
with h5py.File(nwb_file_path, "a") as f:
254-
f["/general/source_script"][()] = f"spyglass={sg_version}"
255+
f["/general/source_script"][()] = cls._logged_env_info()
256+
257+
@staticmethod
258+
def _logged_env_info():
259+
"""Get the environment information for logging."""
260+
env_info = "spyglass={sg_version} \n\n"
261+
env_info += "Python Environment:\n"
262+
python_env = subprocess.check_output(
263+
["conda", "env", "export"], text=True
264+
)
265+
env_info += python_env
266+
return env_info
255267

256268
@classmethod
257269
def __get_new_file_name(cls, nwb_file_name: str) -> str:

0 commit comments

Comments
 (0)