Skip to content

Several small improvements#38

Merged
gertjanvanzwieten merged 9 commits into
mainfrom
next
Mar 3, 2026
Merged

Several small improvements#38
gertjanvanzwieten merged 9 commits into
mainfrom
next

Conversation

@gertjanvanzwieten
Copy link
Copy Markdown
Contributor

No description provided.

Gertjan van Zwieten added 3 commits February 27, 2026 12:05
This patch removes unused legacy attributes of which it is unclear why
they were preserved in the first place.
This patch introduces a helper function _path.non_existent to
deduplicate code found in both the html logger and the data logger.
Comment thread treelog/_path.py Outdated
except FileExistsError:
if not exist_ok:
raise
except FileNotFoundError:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FDPath(dir_fd, '').mkdir(parents=True) recurses indefinitely, because os.mkdir('', mode, dir_fd=dir_fd) raises FileNotFoundError. I think we should stop the recursion when self.path is empty.

Comment thread treelog/_path.py Outdated
return path
dir_fd = os.open(path, flags=os.O_RDONLY)
return _FDDirPath(dir_fd)
return FDPath(dir_fd, '')
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like we're now leaking the fd. _FDDirPath called os.close() in the destructor.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. I pulled the commit because this change was anyhow not relevant for this PR (I just thought let's merge what we can already from #37).

Gertjan van Zwieten added 6 commits February 27, 2026 15:38
This patch adds a file parameter to the StdoutLog, defaulting to
sys.stdout, and removes the StderrLog in favour of a StdoutLog with
file=sys.stderr. The expectation is the StderrLog is never used and that
it can be removed without warning.

The unit tests are changed because the capture function relied on
contextlib.redirect_stdout and contextlib.redirect_stderr, which no
longer has effect if the logger has a handle to the file object. The new
strategy is to create a StdoutLog with a StringIO argument and read out
the value afterward. This has the important advantage of of leaving
sys.stdout intact so that error messages can be read if a test fails.
This patch removes the Log base class and instead derives test cases
directly from unittest.TestCase to make their workings less obscure.
Most tests defer work to a check_output method with the aim that they
can also be called externally by RecordLog and TeeLog.
This patch simplifies the StdoutLog, LoggingLog and RichOutputLog
classes by incorporating the pushcontext, popcontext and recontext
methods from the ContextLog base class. The ContextLog is removed for no
longer serving a purpose.
This patch changes the StdoutLog writer to indent multi-line messages as
follows:

some > context > this is a message that
               > spans two lines
This patch changes the RichtOutputLog writer to indent multi-line
messages as follows:

some > context > this is a message that
               > spans two lines
@gertjanvanzwieten gertjanvanzwieten merged commit 68e20a5 into main Mar 3, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants