Skip to content

Commit f51b91d

Browse files
committed
chore: fix compatibility with python3.12+
configparser.SafeConfigParser is deprecated since Python3.2 (python/cpython#89336). Compatibility with older version is kept using try/catch.
1 parent 098a856 commit f51b91d

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

versioneer.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -339,9 +339,14 @@ def get_config_from_root(root):
339339
# configparser.NoOptionError (if it lacks "VCS="). See the docstring at
340340
# the top of versioneer.py for instructions on writing your setup.cfg .
341341
setup_cfg = os.path.join(root, "setup.cfg")
342-
parser = configparser.SafeConfigParser()
343-
with open(setup_cfg, "r") as f:
344-
parser.readfp(f)
342+
try:
343+
parser = configparser.SafeConfigParser()
344+
with open(setup_cfg, "r") as f:
345+
parser.readfp(f)
346+
except AttributeError:
347+
parser = configparser.ConfigParser()
348+
with open(setup_cfg, "r") as f:
349+
parser.read_file(f)
345350
VCS = parser.get("versioneer", "VCS") # mandatory
346351

347352
def get(parser, name):

0 commit comments

Comments
 (0)