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

[WIP] 3482 Add detection for circular macro replacement #4029

Open
wants to merge 7 commits into
base: dev
Choose a base branch
from

Conversation

Nic-Ma
Copy link
Contributor

@Nic-Ma Nic-Ma commented Mar 31, 2022

part of #3482

Description

Thanks for Gigon's suggestion, this PR added support to detect circular macro replacement in a config file.
And it also fixed a bug that missing the id arg in recursive operation, and now we don't do recursive logic for the case that macro text is in another config file.
Added many unit tests to cover the cases.

Status

Working in progress

Types of changes

  • Non-breaking change (fix or new feature that would not break existing functionality).
  • Breaking change (fix or new feature that would cause existing functionality to change).
  • New tests added to cover the changes.
  • Integration tests passed locally by running ./runtests.sh -f -u --net --coverage.
  • Quick tests passed locally by running ./runtests.sh --quick --unittests --disttests.
  • In-line docstrings updated.
  • Documentation updated, tested make html command in the docs/ folder.

@Nic-Ma
Copy link
Contributor Author

Nic-Ma commented Mar 31, 2022

/black

@Nic-Ma
Copy link
Contributor Author

Nic-Ma commented Mar 31, 2022

/build

1 similar comment
@Nic-Ma
Copy link
Contributor Author

Nic-Ma commented Mar 31, 2022

/build

Signed-off-by: Nic Ma <nma@nvidia.com>
@Nic-Ma
Copy link
Contributor Author

Nic-Ma commented Mar 31, 2022

/build

@Nic-Ma Nic-Ma requested review from ericspod, rijobro and wyli March 31, 2022 06:10
@Nic-Ma Nic-Ma changed the title 3482 Add detection for circular macro replacement 3482 [WIP] Add detection for circular macro replacement Mar 31, 2022
@Nic-Ma Nic-Ma changed the title 3482 [WIP] Add detection for circular macro replacement [WIP] 3482 Add detection for circular macro replacement Mar 31, 2022

"""
if waiting_list is None:
waiting_list = set()
Copy link
Member

Choose a reason for hiding this comment

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

If waiting_list is actually a list we could look at the previous item in the exception to help the user trace what's happened.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's an interesting idea, I think the previous implementation in ReferenceResolver is a list and @wyli simplified it to set later. @wyli What do you think about it?

Thanks.

Copy link
Contributor

Choose a reason for hiding this comment

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

i think set is more suitable/efficient for in checks here...not sure if the previous item is very intuitive when the circular ref is formed by multiple reference a->b->...->c->a

if not path:
# if the target id is in the waiting list, that's circular references
if ids in waiting_list:
raise ValueError(f"detected circular references in macro replacement '{ids}' for id='{id}'.")
Copy link
Member

Choose a reason for hiding this comment

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

So this would be raise ValueError(f"Detected circular references in macro replacement '{ids}' for id='{id}'. (previous id='{waiting_list[-2]}'") or something like that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants