Closed stefanseefeld closed 3 years ago
You may want to think about changing
def check_python(self, cmd):
return subprocess.check_output([self.command, '-c', cmd]).decode().strip()
def check_sysconfig(self, cmd):
r = self.check_python('import distutils.sysconfig as c; print(c.{})'.format(cmd))
return r if r != 'None' else ''
check_output(... , universal_newlines=True)
to get strings as output directly with no decode neededimport sysconfig
rather than import distutils.sysconfig
since it should be cheaper and more future-proof (import distutils can trigger an import of setuptools)f'import ... print(c.{cmd})'
since they are all the rage and all the cool kids use them (but not on the EOL python3.5)Thanks for the suggestions. As to the difference between sysconfig
and distutils.sysconfig
, there are unfortunately a few crucial additions in the latter that I need. E.g. `https://github.com/python/cpython/blob/master/Lib/distutils/sysconfig.py#L87-L124)
(Python's packaging and distribution support is a big mess !)
The other two suggestions are fine. I'm a fan of f-strings, too, and as I just recently decided to no longer support Python 2.7, will happily clean up the code incrementally.
E.g. `https://github.com/python/cpython/blob/master/Lib/distutils/sysconfig.py#L87-L124)
sysconfig.get_config_var('INCLUDEPY')
?
Merged manually.
I just noticed that the sysconfig.get_config_var("EXT_SUFFIX")
trick works on Python3, but not Python2 (where it returns None
. @mattip any idea what I may have to substitute it with there ?
On CPython2 you can do
import imp # python2 only, will emit deprecation warning on python3
[x[0] for x in imp.get_suffixes() if x[2] == imp.C_EXTENSION]
which returns
['.x86_64-linux-gnu.so', '.so', 'module.so']
for me, so take ret[0]
. I think PyPy2 does export sysconfig.get_config_var("EXT_SUFFIX")
, so you might want to do some if None
kind of check.
Codecov Report
76.40% <61.11%> (-4.16%)
100.00% <100.00%> (ø)
Continue to review full report at Codecov.