Skip to content

Commit bf39c06

Browse files
inducertotaam
andcommitted
Update to latest aksetup
Includes changes equivalent to #423 Co-authored-by: Antoine Martin <antoine@xpra.org>
1 parent 939675a commit bf39c06

1 file changed

Lines changed: 88 additions & 74 deletions

File tree

aksetup_helper.py

Lines changed: 88 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
1-
import setuptools # noqa
2-
from setuptools import Extension
1+
import os
32
import sys
4-
from setuptools.command.build_ext import ( # noqa: N812
5-
build_ext as BaseBuildExtCommand)
3+
try:
4+
from setuptools import Extension
5+
from setuptools.command.build_ext import ( # noqa: N812
6+
build_ext as BaseBuildExtCommand)
7+
8+
except ImportError:
9+
class Extension:
10+
pass
11+
12+
class BaseBuildExtCommand:
13+
pass
614

715

816
def count_down_delay(delay):
@@ -35,10 +43,13 @@ def setup(*args, **kwargs):
3543

3644

3745
def get_numpy_incpath():
38-
from imp import find_module
39-
# avoid actually importing numpy, it screws up distutils
40-
file, pathname, descr = find_module("numpy")
41-
from os.path import join
46+
from os.path import join, basename
47+
from importlib.util import find_spec
48+
origin = find_spec("numpy").origin
49+
if origin is None:
50+
raise RuntimeError("origin of numpy package not found")
51+
52+
pathname = basename(origin)
4253
return join(pathname, "core", "include")
4354

4455

@@ -163,7 +174,7 @@ def remove_prefixes(optlist, bad_prefixes):
163174

164175
cvars = sysconfig.get_config_vars()
165176

166-
bad_prefixes = ['-g', '-O', '-Wstrict-prototypes', '-DNDEBUG']
177+
bad_prefixes = ["-g", "-O", "-Wstrict-prototypes", "-DNDEBUG"]
167178

168179
cflags = cvars.get("OPT")
169180
if cflags:
@@ -177,12 +188,12 @@ def remove_prefixes(optlist, bad_prefixes):
177188
cflags.append("-O%s" % what_opt)
178189
cflags.append("-DNDEBUG")
179190

180-
cvars["OPT"] = str.join(' ', cflags)
191+
cvars["OPT"] = str.join(" ", cflags)
181192

182193
cflags = cvars.get("CONFIGURE_CFLAGS")
183194
if cflags:
184195
cflags = remove_prefixes(cflags.split(), bad_prefixes)
185-
cvars["CONFIGURE_CFLAGS"] = str.join(' ', cflags)
196+
cvars["CONFIGURE_CFLAGS"] = str.join(" ", cflags)
186197

187198
if "BASECFLAGS" in cvars:
188199
cvars["CFLAGS"] = cvars["BASECFLAGS"] + " " + cvars.get("OPT", "")
@@ -194,8 +205,8 @@ def remove_prefixes(optlist, bad_prefixes):
194205
ldsharedflags = cvars.get(varname)
195206
if ldsharedflags:
196207
ldsharedflags = remove_prefixes(ldsharedflags.split(),
197-
['-Wl,-O'])
198-
cvars[varname] = str.join(' ', ldsharedflags)
208+
["-Wl,-O"])
209+
cvars[varname] = str.join(" ", ldsharedflags)
199210

200211
# }}}
201212

@@ -249,7 +260,7 @@ def expand_options(options):
249260

250261

251262
class ConfigSchema:
252-
def __init__(self, options, conf_file="siteconf.py", conf_dir="."):
263+
def __init__(self, options, conf_file="siteconf.py", conf_dir=os.path.dirname(__file__)):
253264
self.optdict = dict((opt.name, opt) for opt in options)
254265
self.options = options
255266
self.conf_dir = conf_dir
@@ -629,7 +640,7 @@ def set_up_shipped_boost_if_requested(project_name, conf, source_path=None,
629640

630641
"BOOST_MULTI_INDEX_DISABLE_SERIALIZATION": 1,
631642
"BOOST_PYTHON_SOURCE": 1,
632-
"boost": '%sboost' % project_name,
643+
"boost": "%sboost" % project_name,
633644
}
634645

635646
if boost_chrono is False:
@@ -785,7 +796,7 @@ def _run_git_command(cmd):
785796
if stdout:
786797
return stdout.decode("utf-8"), git_error
787798
else:
788-
return '', "(subprocess call to git did not succeed)"
799+
return "", "(subprocess call to git did not succeed)"
789800

790801

791802
def check_git_submodules():
@@ -804,12 +815,12 @@ def check_git_submodules():
804815
pkg_warnings = []
805816

806817
lines = stdout.split("\n")
807-
for l in lines:
808-
if not l.strip():
818+
for ln in lines:
819+
if not ln.strip():
809820
continue
810821

811-
status = l[0]
812-
sha, package = l[1:].split(" ", 1)
822+
status = ln[0]
823+
sha, package = ln[1:].split(" ", 1)
813824

814825
if package == "bpl-subset" or (
815826
package.startswith("boost") and package.endswith("subset")):
@@ -829,39 +840,39 @@ def check_git_submodules():
829840
% package)
830841

831842
if pkg_warnings:
832-
print(DASH_SEPARATOR)
833-
print("git submodules are not up-to-date or in odd state")
834-
print(DASH_SEPARATOR)
835-
print("If this makes no sense, you probably want to say")
836-
print("")
837-
print(" $ git submodule update --init")
838-
print("")
839-
print("to fetch what you are presently missing and "
840-
"move on with your life.")
841-
print("If you got this from a distributed package on the "
842-
"net, that package is")
843-
print("broken and should be fixed. Please inform whoever "
844-
"gave you this package.")
845-
print("")
846-
print("These issues were found:")
847-
for w in pkg_warnings:
848-
print(" %s" % w)
849-
print("")
850-
print("I will try to initialize the submodules for you "
851-
"after a short wait.")
852-
print(DASH_SEPARATOR)
853-
print("Hit Ctrl-C now if you'd like to think about the situation.")
854-
print(DASH_SEPARATOR)
843+
print(DASH_SEPARATOR)
844+
print("git submodules are not up-to-date or in odd state")
845+
print(DASH_SEPARATOR)
846+
print("If this makes no sense, you probably want to say")
847+
print("")
848+
print(" $ git submodule update --init")
849+
print("")
850+
print("to fetch what you are presently missing and "
851+
"move on with your life.")
852+
print("If you got this from a distributed package on the "
853+
"net, that package is")
854+
print("broken and should be fixed. Please inform whoever "
855+
"gave you this package.")
856+
print("")
857+
print("These issues were found:")
858+
for w in pkg_warnings:
859+
print(" %s" % w)
860+
print("")
861+
print("I will try to initialize the submodules for you "
862+
"after a short wait.")
863+
print(DASH_SEPARATOR)
864+
print("Hit Ctrl-C now if you'd like to think about the situation.")
865+
print(DASH_SEPARATOR)
855866

856-
from os.path import exists
857-
if not exists(".dirty-git-ok"):
858-
count_down_delay(delay=10)
859-
stdout, git_error = _run_git_command(
860-
["submodule", "update", "--init"])
861-
if git_error is None:
862-
print(DASH_SEPARATOR)
863-
print("git submodules initialized successfully")
864-
print(DASH_SEPARATOR)
867+
from os.path import exists
868+
if not exists(".dirty-git-ok"):
869+
count_down_delay(delay=10)
870+
stdout, git_error = _run_git_command(
871+
["submodule", "update", "--init"])
872+
if git_error is None:
873+
print(DASH_SEPARATOR)
874+
print("git submodules initialized successfully")
875+
print(DASH_SEPARATOR)
865876

866877
# }}}
867878

@@ -913,9 +924,12 @@ def has_flag(compiler, flagname):
913924
the specified compiler.
914925
"""
915926
import tempfile
916-
with tempfile.NamedTemporaryFile('w', suffix='.cpp', delete=False) as f:
917-
f.write('int main (int argc, char **argv) { return 0; }')
927+
with tempfile.NamedTemporaryFile("w", suffix=".cpp", delete=False) as f:
928+
f.write("int main (int argc, char **argv) { return 0; }")
918929
fname = f.name
930+
931+
import setuptools
932+
919933
try:
920934
compiler.compile([fname], extra_postargs=[flagname])
921935
except setuptools.distutils.errors.CompileError:
@@ -926,42 +940,42 @@ def has_flag(compiler, flagname):
926940
def cpp_flag(compiler):
927941
"""Return the -std=c++[11/14] compiler flag.
928942
929-
The c++14 is preferred over c++11 (when it is available).
943+
C++14 is preferred over C++11 (when it is available).
930944
"""
931-
if has_flag(compiler, '-std=gnu++14'):
932-
return '-std=gnu++14'
933-
elif has_flag(compiler, '-std=c++14'):
934-
return '-std=c++14'
935-
elif has_flag(compiler, '-std=c++11'):
936-
return '-std=c++11'
945+
if has_flag(compiler, "-std=gnu++14"):
946+
return "-std=gnu++14"
947+
elif has_flag(compiler, "-std=c++14"):
948+
return "-std=c++14"
949+
elif has_flag(compiler, "-std=c++11"):
950+
return "-std=c++11"
937951
else:
938-
raise RuntimeError('Unsupported compiler -- at least C++11 support '
939-
'is needed!')
952+
raise RuntimeError("Unsupported compiler -- at least C++11 support "
953+
"is needed!")
940954

941955

942956
class PybindBuildExtCommand(NumpyBuildExtCommand):
943957
"""A custom build extension for adding compiler-specific options."""
944958
c_opts = {
945-
'msvc': ['/EHsc'],
946-
'unix': [],
959+
"msvc": ["/EHsc"],
960+
"unix": [],
947961
}
948962

949963
def build_extensions(self):
950964
ct = self.compiler.compiler_type
951965
opts = self.c_opts.get(ct, [])
952966
cxx_opts = []
953967

954-
if ct in ['unix', 'mingw32']:
968+
if ct in ["unix", "mingw32"]:
955969
opts.append('-DVERSION_INFO="%s"' % self.distribution.get_version())
956970
cxx_opts.append(cpp_flag(self.compiler))
957-
if has_flag(self.compiler, '-fvisibility=hidden'):
958-
opts.append('-fvisibility=hidden')
959-
if sys.platform == 'darwin':
960-
if has_flag(self.compiler, '-stdlib=libc++'):
961-
opts.append('-stdlib=libc++')
962-
if has_flag(self.compiler, '-mmacosx-version-min=10.7'):
963-
opts.append('-mmacosx-version-min=10.7')
964-
elif ct == 'msvc':
971+
if has_flag(self.compiler, "-fvisibility=hidden"):
972+
opts.append("-fvisibility=hidden")
973+
if sys.platform == "darwin":
974+
if has_flag(self.compiler, "-stdlib=libc++"):
975+
opts.append("-stdlib=libc++")
976+
if has_flag(self.compiler, "-mmacosx-version-min=10.7"):
977+
opts.append("-mmacosx-version-min=10.7")
978+
elif ct == "msvc":
965979
opts.append('/DVERSION_INFO=\\"%s\\"' % self.distribution.get_version())
966980
for ext in self.extensions:
967981
ext.extra_compile_args = ext.extra_compile_args + opts

0 commit comments

Comments
 (0)