Skip to content

Adding parameter to return print_that output instead of printing it - #1039

Merged
peterjc merged 4 commits into
biopython:masterfrom
Serulab:master
Mar 12, 2017
Merged

peterjc merged 4 commits into
biopython:masterfrom
Serulab:master

Conversation

@sbassi

@sbassi sbassi commented Jan 19, 2017 •

Copy link
Copy Markdown
Contributor

This change allows to return the output of print_that instead of sending to stdout. This is usefull when you need this output for a template system.

@codecov-io

codecov-io commented Jan 19, 2017 •

Copy link
Copy Markdown

Codecov Report

Merging #1039 into master will increase coverage by 0.07%.

@@            Coverage Diff             @@
##           master    #1039      +/-   ##
==========================================
+ Coverage   80.47%   80.55%   +0.07%     
==========================================
  Files         320      320              
  Lines       49045    48993      -52     
==========================================
- Hits        39468    39465       -3     
+ Misses       9577     9528      -49
Impacted Files Coverage Δ
Bio/Restriction/Restriction.py 52.33% <50%> (+0.05%) ✅
Bio/Restriction/PrintFormat.py 55.17% <50%> (-0.07%) ❌
Bio/Graphics/Comparative.py 97.33% <ø> (-2.67%) ❌
Bio/SeqIO/UniprotIO.py 92.21% <ø> (+0.29%) ✅
Bio/Seq.py 98.18% <ø> (+0.53%) ✅
Bio/Entrez/init.py 48.14% <ø> (+0.66%) ✅
Bio/SeqUtils/MeltingTemp.py 80.79% <ø> (+0.79%) ✅
Bio/NeuralNetwork/Gene/Schema.py 71.9% <ø> (+0.82%) ✅
Bio/PDB/Selection.py 40% <ø> (+1.53%) ✅
Bio/GenBank/init.py 92% <ø> (+2.09%) ✅
... and 2 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2290ca8...4d40054. Read the comment docs.

@peterjc

peterjc commented Jan 19, 2017

Copy link
Copy Markdown
Member

I don't understand the use-case here versus just doing print(example.print_that(...)) - could you explain what you meant about a template system in this context?

Rather than a new boolean argument, would an optional handle make more sense (e.g. sys.stdout or sys.stderr or a text mode file to write to)? (This might be irrelevant but I don't yet understand your use case.)

@sbassi

sbassi commented Jan 19, 2017

Copy link
Copy Markdown
Contributor Author

With template system I refer to jinja2 and similar.
To render the template I need to pass a dictionary with all values to render, but example.print_that() returns None (instead of returning something, it prints to stdout), so I can't grab the output of example.print_that().
In order to make the print_that() method to return something instead of printing it out, I added a new parameter. With the default value so the user can keep using is as it was before and have the same result.

@peterjc

peterjc commented Jan 19, 2017

Copy link
Copy Markdown
Member

OK - I see what you mean. Frankly I am not keen on methods which directly print, rather than the more flexible option of returning a string.

How about we introduce a new method like .format(...) (or similar name) returning the string? And then define .print_that(...) to just do print(self.format(...)), and ideally deprecate .print_that(...) as well?

Its a bit more hassle, but leaves us with a cleaner API (although separately I'd like to retire the entire restriction module in favour of a re-write, see eg #268).

@sbassi

sbassi commented Jan 19, 2017

Copy link
Copy Markdown
Contributor Author

I agree, that is the way to go. Will work on that.

@sbassi

sbassi commented Jan 20, 2017

Copy link
Copy Markdown
Contributor Author

I called the new method .format_output() since format() was taken in that namespace.

@sbassi

sbassi commented Jan 22, 2017

Copy link
Copy Markdown
Contributor Author

@peterjc The code is ready for review

@peterjc

peterjc commented Jan 23, 2017

Copy link
Copy Markdown
Member

While Bio/Restriction/Restriction.py looks great, Bio/Restriction/PrintFormat.py needs updating to the new API style. Perhaps you forgot to commit changes to that file?

@sbassi

sbassi commented Jan 23, 2017

Copy link
Copy Markdown
Contributor Author

I thought it was not need because print_that inside PrintFormat is mean to be called from print_that in Restriction. But will modify it anyway.

@peterjc

peterjc commented Jan 24, 2017

Copy link
Copy Markdown
Member

Probably almost no one would be using that method, but it would be consistent to do both. Thanks.

@peterjc

peterjc commented Jan 28, 2017

Copy link
Copy Markdown
Member

Looks good, thank you - finally two administrative questions:

Are you happy to dual licence your Biopython contributions (including re-licensing your past contributions) under both the Biopython License Agreement AND the BSD 3-Clause License? See #898.

Also, are you happy to be thanked by name in the NEWS file for the next release (you are already listed in the CONTRIB file)?

@sbassi

sbassi commented Mar 11, 2017

Copy link
Copy Markdown
Contributor Author

Sorry I didn't answer. My answer is yes for both questions.

@peterjc
peterjc merged commit 31bb12a into biopython:master Mar 12, 2017
peterjc added a commit that referenced this pull request Mar 12, 2017
See preceeding commit from pull request #1039.
@peterjc

peterjc commented Mar 12, 2017

Copy link
Copy Markdown
Member

Thank you 👍

MarkusPiotrowski pushed a commit to MarkusPiotrowski/biopython that referenced this pull request Oct 31, 2017
Squashed commit of pull request biopython#1039, allowing use of the pretty-print functionality as strings which is more flexible that printing.
MarkusPiotrowski pushed a commit to MarkusPiotrowski/biopython that referenced this pull request Oct 31, 2017
See preceeding commit from pull request biopython#1039.
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.

3 participants