Skip to content

Nexus: Move all log() functions to nxs_print() for future use of logging library - #6209

Open
brockdyer03 wants to merge 3 commits into
QMCPACK:developfrom
brockdyer03:rework-nexus-log
Open

Nexus: Move all log() functions to nxs_print() for future use of logging library#6209
brockdyer03 wants to merge 3 commits into
QMCPACK:developfrom
brockdyer03:rework-nexus-log

Conversation

@brockdyer03

@brockdyer03 brockdyer03 commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

Proposed changes

This PR renames the log() function in generic.py to nxs_print(), renames DevBaseNexus.log() to DevBaseNexus.nxs_print(), and renames NexusCore.log() to NexusCore.nxs_print(). It also removes generic_settings.devlog (and generic_settings as a whole since devlog was the last thing in it), and replaces any mention of it with sys.stdout.

Additionally, I fixed a long-standing issue with the progress_tty setting in Nexus, which attempted to overwrite the previous line that was written for polling prints so that the polls would not all be on their own line. The previous method used a fixed amount of whitespace before the carriage return to try and ensure that the entire previous line was cleared before the next line was printed, but would leave dangling text if the next line was significantly shorter and did not cover enough space to overwrite the previous line. I used the ANSI sequence for line up ("\033[1A") and "\033[2K" to clear the whole line. This is a much more robust way to ensure that the previous line is cleared. (see NexusCore.nxs_print())

As a side note, when testing the fix to progress_tty mode, I found the output it produced to be significantly nicer than the regular output of Nexus, and I think that we should probably switch the default behavior to be that of progress_tty.

Motivation

The Nexus "log" function has long behaved just like a custom print function and has not really been a true logger. In the hopes of eventually using Python's logging library, I have decided to move all of that framework to the name nxs_print, which is more in line with what it actually is for.

Additionally, I removed generic_settings.devlog for a few reasons. Number one is that it was never particularly clear if/when it should change from being sys.stdout, and number two is that it further simplifies the relationship between parts of Nexus.

Testing changes

In removing generic_settings.devlog, I also removed the method by which Nexus's test system captured any writes to sys.stdout, which was through the FakeLog class in nexus/tests/__init__.py. This was replaced by the Pytest fixture capsys, which captures stdout and stderr, then clears the buffers, essentially performing the same task as FakeLog, except using the standard method that the broader Python/Pytest community uses (which I know @prckent will appreciate).

What type(s) of changes does this code introduce?

  • Bugfix
  • Refactoring (no functional changes, no api changes)
  • Testing changes (e.g. new unit/integration/performance tests)

Does this introduce a breaking change?

  • Maybe

What systems has this change been tested on?

Laptop, Fedora Linux 44 (KDE Plasma Desktop Edition)
AMD Ryzen 7 PRO 7840U (8 cores, 16 logical processors)

Python        3.14.6
uv            0.12.5
cif2cell      2.1.0
coverage      7.15.4
h5py          3.16.0
matplotlib    3.11.1
numpy         2.5.2
pycifrw       4.4.6
pydot         4.0.1
pytest        9.1.1
pytest-cov    7.1.0
pytest-order  1.5.0
scipy         1.18.0
seekpath      2.2.1
spglib        2.7.0
sphinx        9.1.0

Checklist

    • I have read the pull request guidance and develop docs
    • This PR is up to date with the current state of 'develop'
    • Code added or changed in the PR has been clang-formatted
    • This PR adds tests to cover any new code, or to catch a bug that is being fixed
    • Documentation has been added (if appropriate)

@brockdyer03
brockdyer03 requested a review from jtkrogel September 5, 2026 16:26
@github-actions github-actions Bot added nexus python Pull requests that update python code labels Sep 5, 2026
@prckent

prckent commented Sep 6, 2026

Copy link
Copy Markdown
Contributor

Please add a description of the long standing issue that you fixed in progress_tty. This actually worked for me, so I am wondering what the issue was.

@brockdyer03

Copy link
Copy Markdown
Contributor Author

Please add a description of the long standing issue that you fixed in progress_tty. This actually worked for me, so I am wondering what the issue was.

I've updated the main post with a description of the fix.

@jtkrogel jtkrogel left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Need time to look

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

nexus python Pull requests that update python code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants