Skip to content

Commit d85ddf6

Browse files
Alex Jinksclaude
authored andcommitted
fix: replace distutils.version.LooseVersion for Python 3.12+ compatibility
distutils was deprecated in Python 3.10 and removed entirely in Python 3.12, causing an immediate ModuleNotFoundError on any import of panos. Fixes #580. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent a3cb530 commit d85ddf6

1 file changed

Lines changed: 23 additions & 2 deletions

File tree

panos/__init__.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
import logging
3333
import sys
3434
import xml.etree.ElementTree as ET
35-
from distutils.version import LooseVersion # Used by PanOSVersion class
35+
import re
3636

3737
# Warn if running on end-of-life python
3838
if sys.version_info < (3, 6):
@@ -127,7 +127,28 @@ def isstring(arg):
127127
pan.DEBUG3 = pan.DEBUG2 - 1
128128

129129

130-
class PanOSVersion(LooseVersion):
130+
class _LooseVersion:
131+
"""Minimal LooseVersion replacement; distutils was removed in Python 3.12."""
132+
133+
_component_re = re.compile(r"(\d+|[a-z]+|\.)")
134+
135+
def __init__(self, vstring=None):
136+
if vstring:
137+
self.parse(vstring)
138+
139+
def parse(self, vstring):
140+
self.vstring = vstring
141+
parts = [x for x in self._component_re.split(vstring) if x and x != "."]
142+
self.version = [int(x) if x.isdigit() else x for x in parts]
143+
144+
def __str__(self):
145+
return self.vstring
146+
147+
def __repr__(self):
148+
return "LooseVersion ('%s')" % str(self)
149+
150+
151+
class PanOSVersion(_LooseVersion):
131152
"""LooseVersion with convenience properties to access version components"""
132153

133154
@property

0 commit comments

Comments
 (0)