Skip to content

Replaced print with warn/stderrs in NCBIXML.py#5030

Open
head-ease08 wants to merge 11 commits intobiopython:masterfrom
head-ease08:master
Open

Replaced print with warn/stderrs in NCBIXML.py#5030
head-ease08 wants to merge 11 commits intobiopython:masterfrom
head-ease08:master

Conversation

@head-ease08
Copy link

  • I hereby agree to dual licence this and any previous contributions under both
    the Biopython License Agreement AND the BSD 3-Clause License.

  • I have read the CONTRIBUTING.rst file, have run pre-commit
    locally, and understand that continuous integration checks will be used to
    confirm the Biopython unit tests and style checks pass with these changes.

  • I have added my name to the alphabetical contributors listings in the files
    NEWS.rst and CONTRIB.rst as part of this pull request, am listed
    already, or do not wish to be listed. (This acknowledgement is optional.)

Closes #4262 Replaced print statements with warnings.warn or sys.stderr.write in NCBIXML.py for better logging and error handling

Replacing print with warn/stderrs
@peterjc
Copy link
Member

peterjc commented Jul 18, 2025

The warnings ought to have a class like BiopythonParserWarning to make it easy to filter on that. Also, are any of these triggered in the test suite? If so, the test should explicitly confirm that (and not just let it print to the terminal).

If the current tests do not hit these warnings, then ideally we'd need another test added...

@head-ease08
Copy link
Author

Sure, I will check it out and hopefully finish next week. Will look into Biopython-specified warnings.

Also, are any of these triggered in the test suite? If so, the test should explicitly confirm that (and not just let it print to the terminal).

Need more elaboration, please.

@peterjc
Copy link
Member

peterjc commented Jul 20, 2025

If you run the test suite, do the new warnings appear in the terminal output? Note the online BLAST test is troublesome - I think there is an open issue on that.

@codecov
Copy link

codecov bot commented Jul 21, 2025

Codecov Report

Attention: Patch coverage is 25.00000% with 6 lines in your changes missing coverage. Please review.

Project coverage is 86.31%. Comparing base (66ad0a0) to head (de6d507).

Files with missing lines Patch % Lines
Bio/Blast/NCBIXML.py 25.00% 6 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5030      +/-   ##
==========================================
+ Coverage   85.45%   86.31%   +0.86%     
==========================================
  Files         286      286              
  Lines       59851    59853       +2     
==========================================
+ Hits        51144    51665     +521     
+ Misses       8707     8188     -519     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Replaced regular warnings with BiopythonParserWarning
@head-ease08
Copy link
Author

the test suite
Just to clarify: where do I add test? Should i create new .xml in /Tests/Blast? Also is this correct that unittest is used rather than pytest?

@peterjc
Copy link
Member

peterjc commented Jul 24, 2025

Yes, unittest based - see https://biopython.org/docs/latest/Tutorial/chapter_testing.html

@peterjc
Copy link
Member

peterjc commented Jul 28, 2025

Nearly there - an indentation issue and a duplication:

Tests/test_NCBIXML.py:4319:9: SyntaxError: Expected an indented block after `with` statement
     |
4317 |         datafile = os.path.join("Blast", filename)
4318 |         with open(datafile) as handle:
4319 |         with self.assertWarns(BiopythonParserWarning) as cm:
     |         ^
4320 |             record = next(NCBIXML.parse(handle))
4321 |             self.assertRaises(StopIteration, next, NCBIXML.parse(handle))
     |

@head-ease08
Copy link
Author

head-ease08 commented Aug 3, 2025

XML parser probably stops iteration when encounters unsupported tag, hence XML file appears to be empty for parser. Will look into it.

@head-ease08
Copy link
Author

Unfortunately I dont have time recently for working on this issue, hopefully will return later.

@harisj739
Copy link

harisj739 commented Dec 9, 2025

Hey @head-ease08 and @peterjc, anything I can do to help?

@head-ease08
Copy link
Author

@harisj739 Hey! You might look into the issue, afaik there is some underlying problem with XML parser

print("NCBIXML: Added Blast record to results")
warnings.warn(
"Added Blast record to results", BiopythonParserWarning, stacklevel=2
)
Copy link
Member

Choose a reason for hiding this comment

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

This isn't a bad thing to be shown as a warning, but a progress message to show on stderr.

@peterjc
Copy link
Member

peterjc commented Dec 10, 2025

I guess that by adding this test, @head-ease08 found that the parser doesn't handle unepected tags nicely. It gives a warning (good), but then breaks?

If that is correct, then the simplest course of action is to raise an exception on the unexpected tag, and halt. And that should be an improvement on the current unclear failure.

@harisj739
Copy link

@peterjc I can add that functionality building upon @head-ease08's code. If I do, should I create a sub-PR within this PR or an entirely separate PR?

@peterjc
Copy link
Member

peterjc commented Dec 15, 2025

I would suggest a new PR, using a new branch starting from and including (and thus crediting) Mark's initial work.

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.

Replace print statements by warnings or stderr in NCBIXML

3 participants