Repository navigation
Conversation
Documentation build overview
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #5546 +/- ##
========================================
Coverage 93.93% 93.93%
========================================
Files 184 184
Lines 22680 22686 +6
Branches 3228 3230 +2
========================================
+ Hits 21304 21311 +7
+ Misses 916 915 -1
Partials 460 460 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
please have a look at this ive completed the fix and added a regression test covering early iterator closure when ProgressBar is disabled. |
|
I'll let @hejamu have a look and comment. Please ping me once this is done and I'll use the review report. |
|
@Srikar025 thanks for looking into this! The fix looks fine to me, this basically reintroduces the old behaviour since tqdm 4.70 changed its One thing I would suggest is to think about the bigger picture here. Maybe |
| actual = err.strip().split("\r")[-1] | ||
| assert actual == expected | ||
|
|
||
| def test_trajectory_remains_open_when_disabled(self, monkeypatch): |
There was a problem hiding this comment.
This test is fine but it is a bit synthetic. In MAICoS we also tested an Analysis workflow that breaks. https://github.com/atomistic-lab/maicos/pull/614/changes
There was a problem hiding this comment.
Yes, something like your test_aborted_run_keeps_trajectory_open would be good.
| tqdm_class = ProgressBar.__mro__[1] | ||
| monkeypatch.setattr(tqdm_class, "__iter__", iter_with_yield_from) |
There was a problem hiding this comment.
Does this work?
| tqdm_class = ProgressBar.__mro__[1] | |
| monkeypatch.setattr(tqdm_class, "__iter__", iter_with_yield_from) | |
| import tqdm.std | |
| monkeypatch.setattr(tqdm.std.tqdm, "__iter__", iter_with_yield_from) |
Separate issue would be good for discussion! |
| def test_trajectory_remains_open_when_disabled(self, monkeypatch): | ||
| """Ensure early iterator closure leaves the trajectory accessible.""" | ||
| import MDAnalysis as mda | ||
| from MDAnalysis.tests.datafiles import PSF, DCD |
There was a problem hiding this comment.
It is pretty common for LLMs to scope imports in (test) functions when that isn't necessary. Do we really need to scope these imports locally like this?
There was a problem hiding this comment.
Just made a similar comment — we collect imports at the top unless there's a very good reason to do something else.
| super(ProgressBar, self).__init__(*args, **kwargs) | ||
|
|
||
| def __iter__(self): | ||
| """Iterate without closing the underlying iterable when disabled.""" |
There was a problem hiding this comment.
add a comment referencing issue and PR and state briefly that we're working around a change in tqdm (and mention the version of the change). When looking at this code, readers should understand why it's necessary.
| import MDAnalysis as mda | ||
| from MDAnalysis.tests.datafiles import PSF, DCD |
| tqdm_class = ProgressBar.__mro__[1] | ||
| monkeypatch.setattr(tqdm_class, "__iter__", iter_with_yield_from) | ||
|
|
||
| u = mda.Universe(PSF, DCD) |
There was a problem hiding this comment.
Make the universe a fixture so that you can re-use it for a test_aborted_run_keeps_trajectory_open, too.
| actual = err.strip().split("\r")[-1] | ||
| assert actual == expected | ||
|
|
||
| def test_trajectory_remains_open_when_disabled(self, monkeypatch): |
There was a problem hiding this comment.
Yes, something like your test_aborted_run_keeps_trajectory_open would be good.
Fixes #5540
Changes made in this Pull Request
ProgressBar.__iter__()now uses a regularforloop instead ofyield fromwhen the progress display is disabled.yield fromforwardsgenerator closure to the wrapped iterator, which closed the
TrajectoryReader when iteration was interrupted (tqdm >= 4.70).
after a disabled
ProgressBarloop is exited early.package/CHANGELOGentry under Fixes and added myself topackage/AUTHORS.Testing
python -m pytest testsuite/MDAnalysisTests/lib/test_log.py -q: 4 passedpython -m pytest testsuite/MDAnalysisTests/lib -q: 9950 passed, 3 skippedLLM / AI generated code disclosure
I used AI to help investigate the bug and understand its root cause, and to
help draft this PR description.
PR Checklist
package/CHANGELOGfile updated?package/AUTHORS? (If it is not, add it!)Developers Certificate of Origin
I certify that I can submit this code contribution as described in the Developer Certificate of Origin, under the MDAnalysis LICENSE.