`info_log_file=True` should create output directory before opening log file
Closed this issue · 4 comments
With info_log_file=True
, on a new run (non-restart), the log file is opened for writing before the output directory is created, resulting in an error.
I can't seem to reproduce this using one of the simple example scripts (examples/many_strands_no_common_domains.py).
Do you have a stack trace so I can see where the error is occurring exactly?
Here's a stack trace:
Traceback (most recent call last):
File "/home/const/projects/algorithmic-shapes/sequences/adjusted/design-sequences.py", line 245, in <module>
main()
File "/home/const/.local/lib/python3.10/site-packages/click/core.py", line 1130, in __call__
return self.main(*args, **kwargs)
File "/home/const/.local/lib/python3.10/site-packages/click/core.py", line 1055, in main
rv = self.invoke(ctx)
File "/home/const/.local/lib/python3.10/site-packages/click/core.py", line 1404, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/home/const/.local/lib/python3.10/site-packages/click/core.py", line 760, in invoke
return __callback(*args, **kwargs)
File "/home/const/projects/algorithmic-shapes/sequences/adjusted/design-sequences.py", line 203, in main
ns.search_for_dna_sequences(des, sp)
File "/home/const/.local/lib/python3.10/site-packages/nuad/search.py", line 948, in search_for_dna_sequences
directories = _setup_directories(params)
File "/home/const/.local/lib/python3.10/site-packages/nuad/search.py", line 1111, in _setup_directories
directories = _Directories(out=out_directory, debug=params.debug_log_file,
File "/home/const/.local/lib/python3.10/site-packages/nuad/search.py", line 640, in __init__
self.info_file_handler = logging.FileHandler(os.path.join(self.out, 'log_info.log'))
File "/usr/lib/python3.10/logging/__init__.py", line 1169, in __init__
StreamHandler.__init__(self, self._open())
File "/usr/lib/python3.10/logging/__init__.py", line 1201, in _open
return open_func(self.baseFilename, self.mode,
FileNotFoundError: [Errno 2] No such file or directory: '/home/const/projects/algorithmic-shapes/sequences/adjusted/adjusted-out/log_info.log'
By itself, logging.FileHandler
will throw an exception if the directory path doesn't already exist at that point in time. It looks like _setup_directories
doesn't call os.makedirs
until after initializing a _Directories
instance, and that instance's __init__
calls FileHandler
.
I couldn't reproduce this, but I think this issue should be fixed now. Re-open the issue if it's still a problem.
Thank you: the change fixed the problem for me. It may be that this was a system/python/etc-dependent problem.