Commit e8a39e6e authored by Christoph Groth's avatar Christoph Groth
Browse files

setup.py: restore compatibility with Python 2 ConfigParser module

parent 69433493
Pipeline #1816 passed with stage
in 49 seconds
...@@ -15,7 +15,6 @@ import subprocess ...@@ -15,7 +15,6 @@ import subprocess
import os import os
import sys import sys
import collections import collections
import configparser
from setuptools import setup, Extension, Command from setuptools import setup, Extension, Command
from sysconfig import get_platform from sysconfig import get_platform
from distutils.errors import DistutilsError, DistutilsModuleError from distutils.errors import DistutilsError, DistutilsModuleError
...@@ -23,6 +22,11 @@ from setuptools.command.build_ext import build_ext as build_ext_orig ...@@ -23,6 +22,11 @@ from setuptools.command.build_ext import build_ext as build_ext_orig
from setuptools.command.sdist import sdist as sdist_orig from setuptools.command.sdist import sdist as sdist_orig
from setuptools.command.test import test as test_orig from setuptools.command.test import test as test_orig
try:
import configparser
except ImportError:
import ConfigParser as configparser
try: try:
from os.path import samefile from os.path import samefile
except ImportError: except ImportError:
...@@ -74,7 +78,7 @@ def configure_extensions(exts, aliases=(), build_summary=None): ...@@ -74,7 +78,7 @@ def configure_extensions(exts, aliases=(), build_summary=None):
configs = configparser.ConfigParser() configs = configparser.ConfigParser()
try: try:
with open(config_file) as f: with open(config_file) as f:
configs.read_file(f) configs.readfp(f)
except IOError: except IOError:
config_file_present = False config_file_present = False
else: else:
...@@ -93,9 +97,14 @@ def configure_extensions(exts, aliases=(), build_summary=None): ...@@ -93,9 +97,14 @@ def configure_extensions(exts, aliases=(), build_summary=None):
#### Apply config from file. Use [DEFAULT] section for missing sections. #### Apply config from file. Use [DEFAULT] section for missing sections.
defaultconfig = configs.defaults() defaultconfig = configs.defaults()
for name, kwargs in exts.items(): for name, kwargs in exts.items():
config = configs[name] if name in configs else defaultconfig try:
for key, value in config.items(): items = configs.items(name)
except configparser.NoSectionError:
items = defaultconfig.items()
else:
configs.remove_section(name)
for key, value in items:
# Most, but not all, keys are lists of strings # Most, but not all, keys are lists of strings
if key == 'language': if key == 'language':
pass pass
...@@ -117,8 +126,6 @@ def configure_extensions(exts, aliases=(), build_summary=None): ...@@ -117,8 +126,6 @@ def configure_extensions(exts, aliases=(), build_summary=None):
kwargs[key] = value kwargs[key] = value
kwargs.setdefault('depends', []).append(config_file) kwargs.setdefault('depends', []).append(config_file)
if config is not defaultconfig:
del configs[name]
unknown_sections = configs.sections() unknown_sections = configs.sections()
if unknown_sections: if unknown_sections:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment