MCPcopy Index your code
hub / github.com/DanielBok/nlopt-python / build_extension

Method build_extension

extensions.py:40–114  ·  view source on GitHub ↗
(self, ext: Extension)

Source from the content-addressed store, hash-verified

38 return "Debug" if self.debug else "Release"
39
40 def build_extension(self, ext: Extension):
41 # - make sure path ends with delimiter
42 # - required for auto-detection of auxiliary "native" libs
43 ext_dir = Path(self.get_ext_fullpath(ext.name)).parent.absolute()
44 _ed = ext_dir.as_posix()
45
46 build_dir = create_directory(Path(self.build_temp))
47
48 # package builds in 2 steps, first to compile the nlopt package and second to build the DLL
49 cmd = [
50 "cmake",
51 "-LAH",
52 f"-DCMAKE_LIBRARY_OUTPUT_DIRECTORY={_ed}",
53 f"-DPython_EXECUTABLE={sys.executable}",
54 "-DNLOPT_GUILE=OFF",
55 "-DNLOPT_MATLAB=OFF",
56 "-DNLOPT_OCTAVE=OFF",
57 ext.source_dir.as_posix(),
58 ]
59
60 if platform.system() == "Windows":
61 cmd.insert(
62 2, f"-DCMAKE_LIBRARY_OUTPUT_DIRECTORY_{self.config.upper()}={_ed}"
63 )
64
65 execute_command(
66 cmd=cmd,
67 cwd=build_dir,
68 env={
69 **os.environ.copy(),
70 "CXXFLAGS": f'{os.environ.get("CXXFLAGS", "")} -DVERSION_INFO="{self.distribution.get_version()}"',
71 },
72 )
73
74 # build the DLL
75 execute_command(
76 [
77 "cmake",
78 "--build",
79 ".",
80 "--config",
81 self.config,
82 "--",
83 "-m" if platform.system() == "Windows" else "-j2",
84 ],
85 cwd=build_dir,
86 )
87
88 # Copy over the important bits
89 nlopt_py = build_dir / "extern" / "nlopt" / "src" / "swig" / "python" / "nlopt.py"
90
91 logging.info(
92 f"Ext Dir - {ext_dir}\n"
93 + "\n".join(f" - {file.as_posix()}" for file in ext_dir.rglob("*"))
94 )
95 for folder in [ext_dir, nlopt_py.parent]:
96 logging.info(
97 f"Files in {folder.as_posix()}\n"

Callers 1

runMethod · 0.95

Calls 2

create_directoryFunction · 0.85
execute_commandFunction · 0.85

Tested by

no test coverage detected