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

support -iv edge cases? #58

Open
jGaboardi opened this issue Dec 25, 2019 · 1 comment
Open

support -iv edge cases? #58

jGaboardi opened this issue Dec 25, 2019 · 1 comment

Comments

@jGaboardi
Copy link
Contributor

I am wondering if there is an efficient way to support fetching the versions of Python packages that don't follow the __version__ convention, gurobi's Python API for example?

In [1]: %load_ext watermark                                                                                                      

In [2]: %watermark -w                                                                                                            
watermark 2.0.2

In [3]: import gurobi                                                                                                            

In [4]: import gurobipy                                                                                                          

In [5]: %watermark -iv                                                                                                           


In [6]: gurobi.gurobi.version()                                                                                                  
Out[6]: (9, 0, 0)

In [7]: gurobipy.gurobi.version()                                                                                                
Out[7]: (9, 0, 0)

In [8]: %watermark                                                                                                               
2019-12-25T17:55:30-05:00

CPython 3.7.3
IPython 7.10.2

compiler   : Clang 9.0.0 (tags/RELEASE_900/final)
system     : Darwin
release    : 19.2.0
machine    : x86_64
processor  : i386
CPU cores  : 4
interpreter: 64bit

Or would this have to be (1) a brute-force search through the entire directory; or (2) a manual print() for the version.

@rasbt
Copy link
Owner

rasbt commented Dec 26, 2019

Good question. In most cases, I think that

pkg_resources.get_distribution(p).version

(https://github.com/rasbt/watermark/blob/master/watermark/watermark.py#L157)

should take care of it. But if pkg_resources can find the version, we have the manual brute-force approach in the lines below. I guess there is not really a better way than brute-forcing these.

The cleanest way, I believe, would be through the metadata package (from the stdlib), but it's Python 3.8-only (#56) so that it's not that useful, yet.

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

No branches or pull requests

2 participants