Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@littlewu2508
Copy link

Running rocm_agent_enumerator in python 3.12 gives the following syntax warning:

/usr/bin/rocm_agent_enumerator:95: SyntaxWarning: invalid escape sequence '\w'                                                                                                                          
  @staticVars(search_name=re.compile("gfx[0-9a-fA-F]+(:[-+:\w]+)?"))                                                                                                                                               
/usr/bin/rocm_agent_enumerator:152: SyntaxWarning: invalid escape sequence '\A'                                                                                                                         
  line_search_term = re.compile("\A\s+Name:\s+(amdgcn-amd-amdhsa--gfx\d+)")                                                                                                                                        
/usr/bin/rocm_agent_enumerator:154: SyntaxWarning: invalid escape sequence '\A'                                                                                                                         
  line_search_term = re.compile("\A\s+Name:\s+(gfx\d+)")                                                                                                                                                           
/usr/bin/rocm_agent_enumerator:175: SyntaxWarning: invalid escape sequence '\w'                                                                                                                         
  target_search_term = re.compile("1002:\w+")                                                                                                                                                                      

The fix is to use raw strings for regular expression

Reference: https://docs.python.org/dev/whatsnew/3.12.html#other-language-changes

@dayatsin-amd dayatsin-amd self-requested a review January 2, 2024 19:14
Copy link
Contributor

@shwetagkhatri shwetagkhatri left a comment

Choose a reason for hiding this comment

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

Rest of the changes are valid and correct.

return deco

@staticVars(search_term=re.compile("gfx[0-9a-fA-F]+"))
@staticVars(search_term=re.compile(r"gfx[0-9a-fA-F]+"))
Copy link
Contributor

Choose a reason for hiding this comment

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

There is no practical difference between using a raw string and a non-raw string, as there are no backslash escape characters involved here.

term1 = re.compile("Cannot allocate memory")
term2 = re.compile("HSA_STATUS_ERROR_OUT_OF_RESOURCES")
term1 = re.compile(r"Cannot allocate memory")
term2 = re.compile(r"HSA_STATUS_ERROR_OUT_OF_RESOURCES")
Copy link
Contributor

Choose a reason for hiding this comment

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

There is no practical difference between using a raw string and a non-raw string, as there are no backslash escape characters involved here.

prop_path = node_path + '/properties'
if os.path.isfile(prop_path) and os.access(prop_path, os.R_OK):
target_search_term = re.compile("gfx_target_version.+")
target_search_term = re.compile(r"gfx_target_version.+")
Copy link
Contributor

Choose a reason for hiding this comment

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

There is no practical difference between using a raw string and a non-raw string, as there are no backslash escape characters involved here.

Copy link
Author

Choose a reason for hiding this comment

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

Thank you for reviewing. Yes, both normal string and raw string can be used here to achieve similar result.

What's your opinion? I think making all re.compile use raw strings prevents making mistakes in the future (if regular expressions is needed here). While reverting these 3 lines makes this commit minimal.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sure. I agree that using raw string will prevent future mistakes incase escape characters are added here. Please go ahead with the commit.

@shwetagkhatri
Copy link
Contributor

Hi @littlewu2508,
I just realized that part of your patch, has already been taken care of by - #55, which is submitted internally.
So we will have to apply the remaining part of your patch and that will be part of ROCm 6.1.

Use raw strings for regular expression.

This is nearly same with ROCm#55 which
is pulled internally earlier

Reference: https://docs.python.org/dev/whatsnew/3.12.html#other-language-changes
Signed-off-by: Selene <[email protected]>
@littlewu2508
Copy link
Author

Hi @littlewu2508, I just realized that part of your patch, has already been taken care of by - #55, which is submitted internally. So we will have to apply the remaining part of your patch and that will be part of ROCm 6.1.

I see. I have updated the commit message to mention that PR.

You can close this PR once you've apply it properly (although I wonder why that PR is not merged to master publicly, so I don't have to fix this independently)

dayatsin-amd pushed a commit that referenced this pull request Jun 3, 2024
Makes all re.compile function calls use raw string to prevent Syntax warning in future, if backslash escape characters are used in regular expressions

https: //github.com//pull/66
Suggested-by: Author: Yiyang Wu <[email protected]

Change-Id: I6c7aaf016c588bb2ae5a0f979da7d423a78d6ec3
jayhawk-commits pushed a commit to ROCm/rocm-systems that referenced this pull request Aug 11, 2025
Makes all re.compile function calls use raw string to prevent Syntax warning in future, if backslash escape characters are used in regular expressions

https: //github.com/ROCm/rocminfo/pull/66
Suggested-by: Author: Yiyang Wu <[email protected]

Change-Id: I6c7aaf016c588bb2ae5a0f979da7d423a78d6ec3


[ROCm/rocminfo commit: e171664]
ammallya pushed a commit that referenced this pull request Oct 28, 2025
Makes all re.compile function calls use raw string to prevent Syntax warning in future, if backslash escape characters are used in regular expressions

https: //github.com//pull/66
Suggested-by: Author: Yiyang Wu <[email protected]

Change-Id: I6c7aaf016c588bb2ae5a0f979da7d423a78d6ec3


[ROCm/rocminfo commit: e171664]
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.

2 participants