iterative / mlem

🐶 A tool to package, serve, and deploy any ML model on any platform. Archived to be resurrected one day🤞
https://mlem.ai
Apache License 2.0
717 stars 44 forks source link

Fixing version collection #688

Open aguschin opened 1 year ago

aguschin commented 1 year ago

I kept running with issues with the automatic 3rd party dependencies (inferring the wrong version, or missing packages). The version issue is due to some python packages having a mismatch between MODULE.__version__ and the version required for pip:

Reported in discord.

omesser commented 1 year ago

@aguschin have you tried to see if importlib.metadata ? They cover packages and distributions. I believe this should work as of python 3.10 (before that we may need to patch or copy packages_distributions() helper but that's it:

>>> packages = importlib.metadata.packages_distributions()
>>> packages
{'pip': ['pip'], 'cv2': ['opencv-python-headless'], '_distutils_hack': ['setuptools'], 'pkg_resources': ['setuptools'], 'setuptools': ['setuptools'], 'regex': ['regex'], 'wheel': ['wheel'], 'numpy': ['numpy']}
>>> importlib.metadata.distribution(packages['cv2'][0]).version
'4.8.0.74'

works for regex as well:

>>> importlib.metadata.distribution(packages['regex'][0]).version
'2023.6.3'
omesser commented 1 year ago

@aguschin issued a patch in https://github.com/iterative/mlem/pull/694