On Thu, Apr 15, 2021 at 9:36 AM David Mertz <me...@gnosis.cx> wrote: > On Thu, Apr 15, 2021 at 4:55 PM Christopher Barker <python...@gmail.com> > wrote: > >> Presumably that's why importlib.metadata exists in the stdlib. >> > > I was so hopeful about this, but in the end... not really. I have not > used this capability before. Here are a few different situations I know of: > > >>> import re, statistics, pandas, vaex, bs4 > >>> for mod in [re, statistics, pandas, vaex, bs4]: > ... try: > ... print(mod.__name__, end=" ") > ... print(mod.__version__) > ... except: > ... print("__version__ not present") > ... > re 2.2.1 > statistics __version__ not present > pandas 1.2.4 > vaex {'vaex': '4.1.0', 'vaex-core': '4.1.0', 'vaex-viz': '0.5.0', > 'vaex-hdf5': '0.7.0', 'vaex-server': '0.4.0', 'vaex-astro': '0.8.0', > 'vaex-jupyter': '0.6.0', 'vaex-ml': '0.11.1'} > bs4 4.9.3 > > >>> for mod in [re, statistics, pandas, vaex, bs4]: > ... try: > ... print(mod.__name__, version(mod.__name__)) > ... except Exception as err: > ... print(mod.__name__, repr(err)) > ... > re PackageNotFoundError('re') > statistics PackageNotFoundError('statistics') > pandas 1.2.4 > vaex 4.1.0 > bs4 PackageNotFoundError('bs4') > > It seems like (somehow or another) importlib.metadata is doing something > perhaps more useful for vaex. But it is doing distinctly worse for re, > statistics, and bs4. >
I don't see how importlib.metadata plays into your code sample since you didn't import it to use it? > > Version is arguably useful from the package user side. As I believe Victor >> mentioned, there are two uses for version information: display to the user >> -- for which version strings are fine, or programmatic comparison -- for >> which something like the Version object is very helpful. Do we only need to >> use version information programmatically when we are creating (or >> installing) packages? I don't think so -- I know I have code that (poorly) >> does version checking programmatically. >> > And is installing a dependency that much of a burden for that code? > > I think the key thing that Chris and I are pointing to is that there is a > definite use for versions that is NOT for package maintainers/creators. > Interactive use is definitely one such case, and eyeballing something, even > if it is the oddball use that Vaex has, can help with figuring out an > issue. But in actual code, I relatively often do something like this. Or > rather, the below is what I would find really nice to be able to do. > > ver = robust_version(module) > if ver >= (5, 2, 1): > doit_modern_style() > elif ver < (5, 2, 1): > doit_old_style > else: > doit_unversioned_style() > > I'd like code like that to ALWAYS succeed. No exceptions raised. And it > would *usually* use reasonable heuristics to figure out some sort of > structured version info as well as is possible. I.e. probably look in > several places and return some custom object that represents a "best > effort." That object might be like NaN in being neither less than nor more > than other things, in the fallback case. > All doable with importlib.metadata and 'packaging'. -Brett > > -- > The dead increasingly dominate and strangle both the living and the > not-yet born. Vampiric capital and undead corporate persons abuse > the lives and control the thoughts of homo faber. Ideas, once born, > become abortifacients against new conceptions. > _______________________________________________ > Python-Dev mailing list -- python-dev@python.org > To unsubscribe send an email to python-dev-le...@python.org > https://mail.python.org/mailman3/lists/python-dev.python.org/ > Message archived at > https://mail.python.org/archives/list/python-dev@python.org/message/4575HZHNN45FNOTKH5DSD6NKNRUJGXFU/ > Code of Conduct: http://python.org/psf/codeofconduct/ >
_______________________________________________ Python-Dev mailing list -- python-dev@python.org To unsubscribe send an email to python-dev-le...@python.org https://mail.python.org/mailman3/lists/python-dev.python.org/ Message archived at https://mail.python.org/archives/list/python-dev@python.org/message/UTTUEIUVQHAIYJSIT3SSS4PBVZX22V7I/ Code of Conduct: http://python.org/psf/codeofconduct/