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] config ignore imported modules and functions #1802

Merged
merged 2 commits into from
Mar 22, 2022

Conversation

SuTanTank
Copy link
Contributor

@SuTanTank SuTanTank commented Mar 15, 2022

Motivation

When use import like import os.path as osp in config. The parsed config's _cfg_dict contains an entry which looks like osp: <module .....

Then when calling pretty_text(), this dict is converted back to string, which is different from the original config., Then this string is formatted by yapf and error occurs.

# config: pretty_text()
        cfg_dict = self._cfg_dict.to_dict()
        text = _format_dict(cfg_dict, outest_level=True)
        # copied from setup.cfg
        yapf_style = dict(
            based_on_style='pep8',
            blank_line_before_nested_class_or_def=True,
            split_before_expression_after_opening_paren=True)
        text, _ = FormatCode(text, style_config=yapf_style, verify=True)

Modification

When parsing a config file to dict, modules and functions are ignored.

BC-breaking (Optional)

No

Use cases (Optional)

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.

@mm-assistant mm-assistant bot added the size/XS label Mar 15, 2022
@SuTanTank SuTanTank changed the title [fix] resume on Windows path [fix] resume on Windows Mar 15, 2022
@SuTanTank SuTanTank changed the title [fix] resume on Windows [fix] config ignore imported modules and functions Mar 16, 2022
Copy link
Collaborator

@HAOCHENYE HAOCHENYE left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@ZwwWayne
Copy link
Collaborator

Hi @SuTanTank ,
Thanks for the kind PR. Would you like to also update the unit tests to test the updated code?

@SuTanTank
Copy link
Contributor Author

What function should I test? There is no new API introduced.

@HAOCHENYE HAOCHENYE requested a review from ZwwWayne March 21, 2022 02:25
@ZwwWayne ZwwWayne merged commit ac52bb3 into open-mmlab:master Mar 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants