mmcv icon indicating copy to clipboard operation
mmcv copied to clipboard

🎨 Delay the YAPF import until it's actually needed.

Open coderanger opened this issue 3 years ago • 3 comments
trafficstars

Motivation

This avoids a hard dependency on lib2to3 which is not included in most minimal Python distributions such as in a container environment.

Modification

The import is moved inside the function so yapf is only needed if the pretty-print functionality is actually in use.

BC-breaking (Optional)

No compat effect.

Use cases (Optional)

N/A other than making it easier to use MMCV in minimal environment.

Checklist

Before PR:

  • [ ] I have read and followed the workflow indicated in the CONTRIBUTING.md to create this PR.
  • [ ] Pre-commit or linting tools indicated in CONTRIBUTING.md are used to fix the potential lint issues.
  • [ ] Bug fixes are covered by unit tests, the case that causes the bug should be added in the unit tests.
  • [ ] New functionalities are covered by complete unit tests. If not, please add more unit test to ensure the correctness.
  • [ ] The documentation has been modified accordingly, including docstring or example tutorials.

After PR:

  • [ ] If the modification has potential influence on downstream or other related projects, this PR should be tested with some of those projects, like MMDet or MMCls.
  • [ ] CLA has been signed and all committers have signed the CLA in this PR.

coderanger avatar Jul 28 '22 00:07 coderanger

CLA assistant check
All committers have signed the CLA.

CLAassistant avatar Jul 28 '22 00:07 CLAassistant

Since FormatCode is optional, maybe we can import it by try... except and throw a not formatted string warning.

Also an option, but having features that vary based on which libraries are installed can lead to unexpected deployment woes. If going that route, I would probably add a format=True/False parameter to the method so the user can request the desired behavior.

coderanger avatar Aug 02 '22 22:08 coderanger

Since FormatCode is optional, maybe we can import it by try... except and throw a not formatted string warning.

Also an option, but having features that vary based on which libraries are installed can lead to unexpected deployment woes. If going that route, I would probably add a format=True/False parameter to the method so the user can request the desired behavior.

Sorry for my late reply, If format=True/False is a parameter of the method, what's the default behavior of pretty_text, BTW, it is a property actually. In my opinion, the default behavior of xxx.pretty_text should not raise an ImportError whether yapf is installed or not. Consider the case user export the config by cfg.pretty_text at the end of training, the ImportError could break the saving process.

HAOCHENYE avatar Aug 16 '22 09:08 HAOCHENYE

Hi @coderanger !We are grateful for your efforts in helping improve mmcv open-source project during your personal time.

Welcome to join OpenMMLab Special Interest Group (SIG) private channel on Discord, where you can share your experiences, ideas, and build connections with like-minded peers. To join the SIG channel, simply message moderator— OpenMMLab on Discord or briefly share your open-source contributions in the #introductions channel and we will assist you. Look forward to seeing you there! Join us :https://discord.gg/UjgXkPWNqA If you have a WeChat account,welcome to join our community on WeChat. You can add our assistant :openmmlabwx. Please add "mmsig + Github ID" as a remark when adding friends:)

Thank you again for your contribution❤

OpenMMLab-Assistant-004 avatar Apr 13 '23 01:04 OpenMMLab-Assistant-004