From 7edf39989e44c7f6aa38d800a5ffbdc290d740c0 Mon Sep 17 00:00:00 2001 From: Jarrett Johnson Date: Sat, 11 May 2024 00:46:00 -0400 Subject: [PATCH] Windows --- layer4/Cmd.cpp | 2 +- setup.py | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/layer4/Cmd.cpp b/layer4/Cmd.cpp index 02b4a1e2f..c03575188 100644 --- a/layer4/Cmd.cpp +++ b/layer4/Cmd.cpp @@ -6531,7 +6531,7 @@ static PyMethodDef Cmd_methods[] = { extern "C" { #endif -PyObject * PyInit__cmd(void) +PyMODINIT_FUNC PyInit__cmd(void) { static struct PyModuleDef moduledef = { PyModuleDef_HEAD_INIT, diff --git a/setup.py b/setup.py index 5657d49f6..e791de0a5 100644 --- a/setup.py +++ b/setup.py @@ -250,9 +250,32 @@ def finalize_options(self): self.pymol_path = install_pymol.change_root( self.root, self.pymol_path) + def install_lib_to(self, sub_dir_list: list[str], lib_name: str) -> None: + """ + Installs a library to the appropriate directory depending on the + operating system. + :sub_dir_list: The subdirectories where the library is located + relative to the build_lib and install_platlib directories. + :lib_name: The filename of the library (without the extension). + """ + lib_path = pathlib.Path(self.build_lib, *sub_dir_list) + if WIN: + lib_path = lib_path / "Release" / f"{lib_name}.pyd" + else: + lib_path = lib_path / f"{lib_name}.so" + dst = pathlib.Path(self.install_platlib, *sub_dir_list) + self.copy(str(lib_path), str(dst)) + + def install_pymol_lib(self) -> None: + """ + Installs PyMOL _cmd library + """ + self.install_lib_to(["pymol"], "_cmd") + def run(self): install.run(self) self.install_pymol_path() + self.install_pymol_lib() if not self.no_launcher: self.make_launch_script() @@ -605,6 +628,9 @@ def get_packages(base, parent='', r=None): champ_inc_dirs.append(sysconfig.get_paths()['include']) champ_inc_dirs.append(sysconfig.get_paths()['platinclude']) +if WIN: + py_lib = pathlib.Path(sysconfig.get_paths()['stdlib']).parent / 'libs' + lib_dirs.append(str(py_lib)) ext_modules += [ CMakeExtension( @@ -622,6 +648,7 @@ def get_packages(base, parent='', r=None): name="chempy.champ._champ", sources=get_sources(['contrib/champ']), include_dirs=champ_inc_dirs, + library_dirs=lib_dirs, ), ]