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

[Fix]: fix mim command crashes problem if requirements version conflict #144

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions mim/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,30 @@
# Copyright (c) OpenMMLab. All rights reserved.

# flake8: noqa

###### 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 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.
#
# 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
# - 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,
Expand Down