fix: replace deprecated distutils.version.StrictVersion for python 3 - #14795
Open
tchbla wants to merge 5 commits into
Open
fix: replace deprecated distutils.version.StrictVersion for python 3#14795tchbla wants to merge 5 commits into
tchbla wants to merge 5 commits into
Conversation
…13 compat distutils was removed in Python 3.13, causing an ImportError on import. replace with a local _parse_version() helper using tuple comparison.
Replace hardcoded `/usr/local/bin/python3` shebang with the portable `#!/usr/bin/env python3` form. The hardcoded path assumes a specific Python installation location, which breaks on systems where Python is installed elsewhere (e.g. via pyenv, conda, or OS package managers). Using `env` resolves `python3` from `$PATH`, correctly handling virtual environments and cross-platform installations.
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Updates the Syslog AMA troubleshooting script to avoid distutils (removed in Python 3.13+) by replacing StrictVersion comparisons with a local tuple-based version parser and bumping the script version.
Changes:
- Replace
distutils.version.StrictVersionwith a local_parse_version()helper. - Update version comparisons to use tuple comparison.
- Update shebang and bump inline
SCRIPT_VERSIONto 2.52.
Pad to three components so "1.2" == "1.2.0" as StrictVersion did. Also add two blank lines before the function definition (PEP 8 E302).
Inline equivalent _strtobool helper preserving original behavior including ValueError on unrecognized values.
Author
|
@microsoft-github-policy-service agree |
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.
Change(s):
Updated
Sentinel_AMA_troubleshoot.pydistutils.version import StrictVersionwith a local_parse_version()helper that converts dotted-version strings to comparable integer tuples. The helper pads shorter tuples to three components (e.g.1.2->(1, 2, 0)) to preserve StrictVersion's equality semantics._parse_versionperPEP 8 E302.Updated
Solutions/ESET Inspect/Data Connectors/InspectGetDetections/__init__.pyfrom distutils.util import strtoboolwith an inline_strtobool()helper that matches the original behavior, including raisingValueErroron unrecognized values.Reason for Change(s):
distutilswas fully removed in Python 3.13, causing anImportErroron any machine running Python 3.13+.No third-party dependencies are introduced, the behaviour is identical.
The tuple comparison follows the same ordering as
StrictVersionfor the dotted-integer version strings used in this script, and_strtoboolis a faithful reimplementation ofdistutils.util.strtobool.Version Updated:
Updated inline Script Version to 2.52
Sentinel_AMA_troubleshoot.pyTesting Completed:
Yes, manually verified both call sites (
is_agent_version_updatedandverify_selinux_state) produce correct results with the tuple-based comparison; script imports cleanly on Python 3.13.Verified
_strtoboolhandles all truthy/falsy values and raises on invalid input.Checked that the validations are passing and have addressed any issues that are present:
Python syntax is valid, no KQL or YAML templates are modified.