|
1 | 1 | import os |
2 | 2 | import random |
3 | 3 | import string |
| 4 | +import subprocess |
4 | 5 | from pathlib import Path |
5 | 6 | from time import time |
6 | 7 | from uuid import uuid4 |
@@ -217,7 +218,7 @@ def create(self, nwb_file_name: str, restrict_permission=False) -> str: |
217 | 218 | nwb_object.pop(module) |
218 | 219 | # add the version of spyglass that created this file |
219 | 220 | if nwbf.source_script is None: |
220 | | - nwbf.source_script = f"spyglass={sg_version}" |
| 221 | + nwbf.source_script = self._logged_env_info() |
221 | 222 | else: |
222 | 223 | alter_source_script = True |
223 | 224 |
|
@@ -247,11 +248,22 @@ def create(self, nwb_file_name: str, restrict_permission=False) -> str: |
247 | 248 |
|
248 | 249 | return analysis_file_name |
249 | 250 |
|
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: |
252 | 253 | """Change the source script to the current version of spyglass""" |
253 | 254 | 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 |
255 | 267 |
|
256 | 268 | @classmethod |
257 | 269 | def __get_new_file_name(cls, nwb_file_name: str) -> str: |
|
0 commit comments