The only solution I have found is to override the build_ext command:
from setuptools.command.build_ext import build_ext as _build_ext
if sys.version_info[0] == 2:
class build_ext(_build_ext):
def swig_sources(self, sources, extension):
new_sources = _build_ext.swig_sources(self, sources, extension)
for src in sources:
py_src = os.path.splitext(src)[0].replace("-", "_") + ".py"
if os.path.exists(py_src):
with open(py_src) as infile:
content = infile.read()
with open(py_src, "w") as outfile:
outfile.write("# -*- coding: utf-8 -*-\n")
outfile.write(content)
return new_sources
else:
build_ext = _build_ext
...
setup(
cmdclass={"build_ext": build_ext},
...
)
.ifile is utf-8 and contains lots of é, è, à, ... And I also need to maintain py2 code.