From 7eed0820821d701ac67a0083c71a5bf595d28bdf Mon Sep 17 00:00:00 2001 From: ice-tong Date: Sat, 25 Jun 2022 22:44:28 +0800 Subject: [PATCH 1/2] fix(mim/__init__.py): fix the mim command crashes due to requirements version conflict --- mim/__init__.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/mim/__init__.py b/mim/__init__.py index a854bbe..618eb3b 100644 --- a/mim/__init__.py +++ b/mim/__init__.py @@ -1,4 +1,30 @@ # Copyright (c) OpenMMLab. All rights reserved. + +# flake8: noqa + +####### Fix the mim command crashes due to requirements version conflict. ###### +# `pkg_resources` checks for a `__requires__` attribute in the `__main__` module +# when initializing the default working set, and uses this to ensure a suitable +# version of each affected distribution is activated. +# +# The entry point scripts create by `setuptools` use the `__requires__` feature +# for compatibility with `easy_install` but may cause mim crash when version +# conflict exists. +# +# Hence, we here remove the `__requires__` declare in mim entry point script before +# importing pkg_resources to handle this situation. This workaround works fine so +# far, but not sure if it would cause other unknown problems or not. +# +# Related Links: +# - https://github.com/open-mmlab/mim/issues/143 +# - https://setuptools.pypa.io/en/latest/pkg_resources.html?highlight=__requires__ +# - https://github.com/pypa/setuptools/issues/2198 + +import sys + +sys.modules['__main__'].__requires__ = '' # type: ignore +################################# The end! ##################################### + from .commands import ( download, get_model_info, From c8703b78cd7b94fd8401bb2e389c5c49f33d54e7 Mon Sep 17 00:00:00 2001 From: ice-tong Date: Sat, 25 Jun 2022 23:54:33 +0800 Subject: [PATCH 2/2] refine(mim/__init__.py): refine the comments --- mim/__init__.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/mim/__init__.py b/mim/__init__.py index 618eb3b..b1df4d2 100644 --- a/mim/__init__.py +++ b/mim/__init__.py @@ -2,18 +2,18 @@ # flake8: noqa -####### Fix the mim command crashes due to requirements version conflict. ###### +###### Fix mim command crashes problem if requirements version conflict. ####### # `pkg_resources` checks for a `__requires__` attribute in the `__main__` module -# when initializing the default working set, and uses this to ensure a suitable -# version of each affected distribution is activated. +# when initializing the default working set, and resolves its dependency to +# ensure a suitable version of each affected distribution is activated. # # The entry point scripts create by `setuptools` use the `__requires__` feature # for compatibility with `easy_install` but may cause mim crash when version # conflict exists. # -# Hence, we here remove the `__requires__` declare in mim entry point script before -# importing pkg_resources to handle this situation. This workaround works fine so -# far, but not sure if it would cause other unknown problems or not. +# To handle this situation, we set the `__requires__` declared in mim entry point +# script from 'openmim' to '' before importing pkg_resources. This workaround works +# fine so far, but not sure if it would cause other unknown problems or not. # # Related Links: # - https://github.com/open-mmlab/mim/issues/143