[code sync] Merge code from sonic-net/sonic-platform-common:202605 to 202607#121
Merged
Merged
Conversation
mssonicbld
commented
Jul 24, 2026
Collaborator
…mmon.py (#725) #### Description Updated regex patterns `p1` and `p2` in `PcieUtil.get_pcie_device()` to use raw string literals (`r"..."`) instead of plain string literals. #### Motivation and Context On SONiC `20251110.35` (Debian 13 / Python 3.13), `SyntaxWarning` was emitted to stderr on every CLI invocation (`show ver`, `show ip bgp sum`, etc.) on Arista `7060X6-16PE-384C-B` devices. **Root cause:** - `__pycache__/pcie_common.cpython-313.pyc` was created by a root process with a restrictive umask, resulting in `0600` permissions. - Non-root `admin` users cannot read the `0600` `.pyc` -> Python falls back to parsing `pcie_common.py` from source on every CLI invocation. - `pcie_common.py` contains invalid escape sequences (`\w`, `\s`) in plain string regex patterns -> Python 3.13 emits `SyntaxWarning` on every parse. Python 3.12+ warns on invalid escape sequences in plain strings; Python 3.13 raises `SyntaxWarning`; Python 3.14 will raise `SyntaxError`. Raw strings (`r"..."`) are the correct and idiomatic way to write regex patterns and eliminate the warning regardless of `.pyc` cache state or permissions. #### How Has This Been Tested? - Existing test suite passes: `pytest tests/pcie_common_test.py -v` - No `DeprecationWarning` or `SyntaxWarning` emitted under Python 3.12/3.13 - No behavioral change - regex patterns are identical #### Tested branch - [x] 202511 - [x] 202605 #### Test result - 202511: Verified on Python 3.13 file compiles cleanly with no `SyntaxWarning`: `$ python -W error::SyntaxWarning -m py_compile sonic_platform_base/sonic_pcie/pcie_common.py && echo "PASS: no SyntaxWarning" PASS: no SyntaxWarning` - 202605: Verified on Python 3.13 file compiles cleanly with no `SyntaxWarning`: `$ python -W error::SyntaxWarning -m py_compile sonic_platform_base/sonic_pcie/pcie_common.py && echo "PASS: no SyntaxWarning" PASS: no SyntaxWarning` Signed-off-by: Sonic Build Admin <sonicbld@microsoft.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.