@@ -149,10 +149,6 @@ <h1 class="title">Module <code>logrun.internals</code></h1>
149
149
150
150
uuid: str
151
151
""" The experiment's ID. """
152
- rootpath: str
153
- """ Path where the experiment will be written to.
154
-
155
- This is acquired via the `MICRLOG_ROOT` environment variable. """
156
152
157
153
has_content: bool
158
154
""" A member variable that tracks whether there is anything to log. """
@@ -168,9 +164,6 @@ <h1 class="title">Module <code>logrun.internals</code></h1>
168
164
169
165
def __init__(self):
170
166
self.uuid = str(uuid.uuid4())
171
- self.rootpath = os.environ.get('LOGRUN_ROOT')
172
- if self.rootpath is None:
173
- raise OSError("Environment variable 'LOGRUN_ROOT' is not defined!")
174
167
175
168
self.has_content = False
176
169
self.output_files = []
@@ -238,7 +231,7 @@ <h1 class="title">Module <code>logrun.internals</code></h1>
238
231
239
232
def save_experiment(self) -> None:
240
233
"""
241
- Save the experiment.
234
+ Save the experiment to the path given by the `$LOGRUN_ROOT` environment variable .
242
235
"""
243
236
244
237
from logrun import __version__
@@ -247,22 +240,31 @@ <h1 class="title">Module <code>logrun.internals</code></h1>
247
240
self._cleanup()
248
241
return
249
242
243
+ rootpath = os.environ.get('LOGRUN_ROOT')
244
+ if rootpath is None:
245
+ raise OSError("Environment variable 'LOGRUN_ROOT' is not defined! Cannot save experiment.")
246
+
250
247
print("[Saving experiment: %s]" % self.uuid)
251
248
252
249
experiment_path = \
253
- ensure_dir_exists(os.path.join(self. rootpath, 'all_experiments', self.uuid))
250
+ ensure_dir_exists(os.path.join(rootpath, 'all_experiments', self.uuid))
254
251
experiment_path_targz = experiment_path + '.tar.gz'
255
252
experiment_by_outfile_path = \
256
- ensure_dir_exists(os.path.join(self. rootpath, 'experiments_by_output_file'))
253
+ ensure_dir_exists(os.path.join(rootpath, 'experiments_by_output_file'))
257
254
experiment_by_infile_path = \
258
- ensure_dir_exists(os.path.join(self. rootpath, 'experiments_by_input_file'))
255
+ ensure_dir_exists(os.path.join(rootpath, 'experiments_by_input_file'))
259
256
experiment_source_directory = ensure_dir_exists(os.path.join(experiment_path, 'source'))
260
257
261
258
for module in sys.modules.values():
262
259
if not module.__name__.startswith('src.'):
263
260
continue
264
261
265
- source_file = inspect.getsourcefile(module)
262
+ try:
263
+ source_file = inspect.getsourcefile(module)
264
+ except TypeError:
265
+ # If we are here then this module doesn't have a corresponding source file
266
+ # (or it's compiled).
267
+ continue
266
268
267
269
if os.path.getmtime(source_file) > start_timestamp:
268
270
print("Warning: source file [%s] modified since start of program execution!")
@@ -482,10 +484,6 @@ <h3>Methods</h3>
482
484
483
485
uuid: str
484
486
""" The experiment's ID. """
485
- rootpath: str
486
- """ Path where the experiment will be written to.
487
-
488
- This is acquired via the `MICRLOG_ROOT` environment variable. """
489
487
490
488
has_content: bool
491
489
""" A member variable that tracks whether there is anything to log. """
@@ -501,9 +499,6 @@ <h3>Methods</h3>
501
499
502
500
def __init__(self):
503
501
self.uuid = str(uuid.uuid4())
504
- self.rootpath = os.environ.get('LOGRUN_ROOT')
505
- if self.rootpath is None:
506
- raise OSError("Environment variable 'LOGRUN_ROOT' is not defined!")
507
502
508
503
self.has_content = False
509
504
self.output_files = []
@@ -571,7 +566,7 @@ <h3>Methods</h3>
571
566
572
567
def save_experiment(self) -> None:
573
568
"""
574
- Save the experiment.
569
+ Save the experiment to the path given by the `$LOGRUN_ROOT` environment variable .
575
570
"""
576
571
577
572
from logrun import __version__
@@ -580,22 +575,31 @@ <h3>Methods</h3>
580
575
self._cleanup()
581
576
return
582
577
578
+ rootpath = os.environ.get('LOGRUN_ROOT')
579
+ if rootpath is None:
580
+ raise OSError("Environment variable 'LOGRUN_ROOT' is not defined! Cannot save experiment.")
581
+
583
582
print("[Saving experiment: %s]" % self.uuid)
584
583
585
584
experiment_path = \
586
- ensure_dir_exists(os.path.join(self. rootpath, 'all_experiments', self.uuid))
585
+ ensure_dir_exists(os.path.join(rootpath, 'all_experiments', self.uuid))
587
586
experiment_path_targz = experiment_path + '.tar.gz'
588
587
experiment_by_outfile_path = \
589
- ensure_dir_exists(os.path.join(self. rootpath, 'experiments_by_output_file'))
588
+ ensure_dir_exists(os.path.join(rootpath, 'experiments_by_output_file'))
590
589
experiment_by_infile_path = \
591
- ensure_dir_exists(os.path.join(self. rootpath, 'experiments_by_input_file'))
590
+ ensure_dir_exists(os.path.join(rootpath, 'experiments_by_input_file'))
592
591
experiment_source_directory = ensure_dir_exists(os.path.join(experiment_path, 'source'))
593
592
594
593
for module in sys.modules.values():
595
594
if not module.__name__.startswith('src.'):
596
595
continue
597
596
598
- source_file = inspect.getsourcefile(module)
597
+ try:
598
+ source_file = inspect.getsourcefile(module)
599
+ except TypeError:
600
+ # If we are here then this module doesn't have a corresponding source file
601
+ # (or it's compiled).
602
+ continue
599
603
600
604
if os.path.getmtime(source_file) > start_timestamp:
601
605
print("Warning: source file [%s] modified since start of program execution!")
@@ -706,11 +710,6 @@ <h3>Class variables</h3>
706
710
< dd >
707
711
< div class ="desc "> < p > A list of files that the running script has produced as output.</ p > </ div >
708
712
</ dd >
709
- < dt id ="logrun.internals.Experiment.rootpath "> < code class ="name "> var < span class ="ident "> rootpath</ span > : str</ code > </ dt >
710
- < dd >
711
- < div class ="desc "> < p > Path where the experiment will be written to.</ p >
712
- < p > This is acquired via the < code > MICRLOG_ROOT</ code > environment variable.</ p > </ div >
713
- </ dd >
714
713
< dt id ="logrun.internals.Experiment.uuid "> < code class ="name "> var < span class ="ident "> uuid</ span > : str</ code > </ dt >
715
714
< dd >
716
715
< div class ="desc "> < p > The experiment's ID.</ p > </ div >
@@ -796,14 +795,14 @@ <h3>Methods</h3>
796
795
< span > def < span class ="ident "> save_experiment</ span > </ span > (< span > self) ‑> NoneType</ span >
797
796
</ code > </ dt >
798
797
< dd >
799
- < div class ="desc "> < p > Save the experiment.</ p > </ div >
798
+ < div class ="desc "> < p > Save the experiment to the path given by the < code > $LOGRUN_ROOT </ code > environment variable .</ p > </ div >
800
799
< details class ="source ">
801
800
< summary >
802
801
< span > Expand source code</ span >
803
802
</ summary >
804
803
< pre > < code class ="python "> def save_experiment(self) -> None:
805
804
"""
806
- Save the experiment.
805
+ Save the experiment to the path given by the `$LOGRUN_ROOT` environment variable .
807
806
"""
808
807
809
808
from logrun import __version__
@@ -812,22 +811,31 @@ <h3>Methods</h3>
812
811
self._cleanup()
813
812
return
814
813
814
+ rootpath = os.environ.get('LOGRUN_ROOT')
815
+ if rootpath is None:
816
+ raise OSError("Environment variable 'LOGRUN_ROOT' is not defined! Cannot save experiment.")
817
+
815
818
print("[Saving experiment: %s]" % self.uuid)
816
819
817
820
experiment_path = \
818
- ensure_dir_exists(os.path.join(self. rootpath, 'all_experiments', self.uuid))
821
+ ensure_dir_exists(os.path.join(rootpath, 'all_experiments', self.uuid))
819
822
experiment_path_targz = experiment_path + '.tar.gz'
820
823
experiment_by_outfile_path = \
821
- ensure_dir_exists(os.path.join(self. rootpath, 'experiments_by_output_file'))
824
+ ensure_dir_exists(os.path.join(rootpath, 'experiments_by_output_file'))
822
825
experiment_by_infile_path = \
823
- ensure_dir_exists(os.path.join(self. rootpath, 'experiments_by_input_file'))
826
+ ensure_dir_exists(os.path.join(rootpath, 'experiments_by_input_file'))
824
827
experiment_source_directory = ensure_dir_exists(os.path.join(experiment_path, 'source'))
825
828
826
829
for module in sys.modules.values():
827
830
if not module.__name__.startswith('src.'):
828
831
continue
829
832
830
- source_file = inspect.getsourcefile(module)
833
+ try:
834
+ source_file = inspect.getsourcefile(module)
835
+ except TypeError:
836
+ # If we are here then this module doesn't have a corresponding source file
837
+ # (or it's compiled).
838
+ continue
831
839
832
840
if os.path.getmtime(source_file) > start_timestamp:
833
841
print("Warning: source file [%s] modified since start of program execution!")
@@ -957,7 +965,6 @@ <h4><code><a title="logrun.internals.Experiment" href="#logrun.internals.Experim
957
965
< li > < code > < a title ="logrun.internals.Experiment.input_files " href ="#logrun.internals.Experiment.input_files "> input_files</ a > </ code > </ li >
958
966
< li > < code > < a title ="logrun.internals.Experiment.multiple " href ="#logrun.internals.Experiment.multiple "> multiple</ a > </ code > </ li >
959
967
< li > < code > < a title ="logrun.internals.Experiment.output_files " href ="#logrun.internals.Experiment.output_files "> output_files</ a > </ code > </ li >
960
- < li > < code > < a title ="logrun.internals.Experiment.rootpath " href ="#logrun.internals.Experiment.rootpath "> rootpath</ a > </ code > </ li >
961
968
< li > < code > < a title ="logrun.internals.Experiment.save_experiment " href ="#logrun.internals.Experiment.save_experiment "> save_experiment</ a > </ code > </ li >
962
969
< li > < code > < a title ="logrun.internals.Experiment.uuid " href ="#logrun.internals.Experiment.uuid "> uuid</ a > </ code > </ li >
963
970
</ ul >
0 commit comments