Skip to content

Commit

Permalink
Fix build against Python 3.12
Browse files Browse the repository at this point in the history
Ever since Python 3.2, configparser.SafeConfigParser has been deprecated
in favor of configparser.ConfigParser. An alias existed for backward
compatibility but the alias was dropped from Python 3.12.

Let us now use ConfigParser explicitly, and use .read_file() instead of
.readfp() which was dropped too.

The imp module has also been dropped, but a similar behavior can be achieved
using importlib.

Signed-off-by: Olivier Gayot <[email protected]>
  • Loading branch information
ogayot committed Nov 26, 2023
1 parent fb65d21 commit d71d576
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
5 changes: 3 additions & 2 deletions tests/test_sandbox_scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
from io import StringIO
import traceback
import glob
import imp
import importlib

import pytest

Expand Down Expand Up @@ -77,7 +77,8 @@ def _sandbox_scripts():
@pytest.mark.parametrize("filename", _sandbox_scripts())
def test_import_succeeds(filename, tmpdir, capsys):
try:
mod = imp.load_source('__zzz', filename)
loader = importlib.machinery.SourceFileLoader('__zzz', filename)
mod = loader.load_module()
except:
print(traceback.format_exc())
raise AssertionError("%s cannot be imported" % (filename,))
Expand Down
4 changes: 2 additions & 2 deletions versioneer.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,9 +339,9 @@ def get_config_from_root(root):
# configparser.NoOptionError (if it lacks "VCS="). See the docstring at
# the top of versioneer.py for instructions on writing your setup.cfg .
setup_cfg = os.path.join(root, "setup.cfg")
parser = configparser.SafeConfigParser()
parser = configparser.ConfigParser()
with open(setup_cfg, "r") as f:
parser.readfp(f)
parser.read_file(f)
VCS = parser.get("versioneer", "VCS") # mandatory

def get(parser, name):
Expand Down

0 comments on commit d71d576

Please sign in to comment.