Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

printversion #698

Merged
merged 13 commits into from
Jun 28, 2018
Merged

printversion #698

merged 13 commits into from
Jun 28, 2018

Conversation

prisae
Copy link
Member

@prisae prisae commented Jun 7, 2018

I first go at versions. Fixes #697 .

Please have a look, feedback welcome!

selection_001

selection_002

@prisae
Copy link
Member Author

prisae commented Jun 7, 2018

There are more options. You can get the html-table as plain text with SimPEG.versions('html') (html lower case instead of upper case). You can have that printed nicely by print(SimPEG.versions('html')).

How many columns are used can be set with SimPEG.versions('html', ncol=5), for instance.

Additional packages can be provided via SimPEG.versions('HTML', add_pckg=[simpegEM1D, geoana]). They have to be imported in the script beforehand. It only works for packages which use the __version__ feature though, it is not more sophisticated.

@prisae
Copy link
Member Author

prisae commented Jun 7, 2018

Example of the add_pckg and ncol arguments:

selection_003

@codecov
Copy link

codecov bot commented Jun 7, 2018

Codecov Report

Merging #698 into master will increase coverage by 0.11%.
The diff coverage is 89.16%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #698      +/-   ##
==========================================
+ Coverage   72.88%   72.99%   +0.11%     
==========================================
  Files         110      111       +1     
  Lines       16667    16787     +120     
==========================================
+ Hits        12147    12254     +107     
- Misses       4520     4533      +13
Impacted Files Coverage Δ
SimPEG/Fields.py 95.26% <ø> (ø) ⬆️
SimPEG/Utils/printinfo.py 89.16% <89.16%> (ø)

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 9429510...543921c. Read the comment docs.

Copy link
Member

@rowanc1 rowanc1 left a comment

Choose a reason for hiding this comment

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

Looks really cool! This will be really helpful for reproducibility.

__all__ = ['versions', 'versions_html', 'versions_text']


def versions(mode='print', add_pckg=None, ncol=4):
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if changing the default here depending on if you are in IPython or not?

def versions(mode='html' if IPython else 'print', add_pckg=None, ncol=4):
    ...

Copy link
Member Author

Choose a reason for hiding this comment

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

I guess you mean mode='HTML', which returns the rendered table (mode='html' returns the actual html-code).

You can, but I think is better not to. You would have to make sure you are in an Jupyter Notebook, because otherwise you could also be in an IPython console, and the mode='HTML' cannot render.

Also, what speaks for having mode='print' is that this looks OK in a notebook too, it would just print it as in the console. So this is the only mode that always works nicely. If there is a nice and easy trick though to ensure if you are in a Jupyter notebook then it could be a good idea, indeed.

Copy link
Member Author

Choose a reason for hiding this comment

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

I actually wanted to do this by default, return HTML if in Notebook, and not otherwise. But I could not figure out a good, foolproof way of distinguishing if you are in an Jupyter Notebook, in an IPython console, or in a Qt console. If you know a good way let me know!

Copy link
Member

Choose a reason for hiding this comment

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

hmm, yeah it doesn't seem to be trivial to check if you are in a notebook or not

Copy link
Member Author

Choose a reason for hiding this comment

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

I had another look at this, and I could not find a good way. You could distinguish between an IPython Console and a Jupyter Notebook, but not between a Qt Console and a Jupyter Notebook. But the Qt Console cannot render the HTML mode either. So I think sticking with mode='print' as default is the safest option in whatever environment someone is using SimPEG.

@lheagy lheagy mentioned this pull request Jun 27, 2018
@lheagy lheagy mentioned this pull request Jun 27, 2018
lheagy
lheagy previously approved these changes Jun 28, 2018
Copy link
Member

@lheagy lheagy left a comment

Choose a reason for hiding this comment

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

Thanks @prisae! I will wait until the recent round of tests finishes and we can bring this in 🎉

(Jupyter notebook, IPython console, Python console, QT console), either as
html-table (notebook) or as plain text (anywhere).

This script is an adapted version of ``empymod.printversions``, which itself
Copy link
Member

Choose a reason for hiding this comment

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

would you like to include a like to the empymod docs here?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point, as I put links as well for ipynbtools.py and watermar.py. I'll add https://empymod.github.io.

__all__ = ['versions', 'versions_html', 'versions_text']


def versions(mode='print', add_pckg=None, ncol=4):
Copy link
Member

Choose a reason for hiding this comment

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

hmm, yeah it doesn't seem to be trivial to check if you are in a notebook or not

>>> versions('plain', pytest) # Provide additional package
>>> versions('HTML', [pytest, dateutil], ncol=5) # HTML

"""
Copy link
Member

Choose a reason for hiding this comment

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

Thanks for all of the docs!!

As I had done for `ipynbtools.py` and `watermark.py`.
@lheagy lheagy merged commit ac6b684 into master Jun 28, 2018
@lheagy lheagy deleted the printversion branch June 28, 2018 23:28
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