From 5072d22611966546af8b0fdc512e50f4908da948 Mon Sep 17 00:00:00 2001 From: Tieqiong Zhang Date: Thu, 31 Jul 2025 23:33:24 -0400 Subject: [PATCH 1/2] update setup.py for wheel build correct function name typos correct pip.txt add version fallback --- docs/examples/distanceprinter.py | 4 ++-- docs/examples/parallelPDF.py | 4 ++-- requirements/pip.txt | 2 ++ setup.py | 38 +++++++++++++++++++++----------- src/diffpy/srreal/version.py | 10 +++++++-- tests/testutils.py | 4 ++-- 6 files changed, 41 insertions(+), 21 deletions(-) diff --git a/docs/examples/distanceprinter.py b/docs/examples/distanceprinter.py index 870c7216..356f1123 100755 --- a/docs/examples/distanceprinter.py +++ b/docs/examples/distanceprinter.py @@ -47,9 +47,9 @@ def _addPairContribution(self, bnds, sumscale): def get_pyobjcryst_sphalerite(): - from pyobjcryst import loadCrystal + from pyobjcryst.crystal import create_crystal_from_cif - crst = loadCrystal("datafiles/sphalerite.cif") + crst = create_crystal_from_cif("datafiles/sphalerite.cif") return crst diff --git a/docs/examples/parallelPDF.py b/docs/examples/parallelPDF.py index 199ebaa1..762d4ea5 100755 --- a/docs/examples/parallelPDF.py +++ b/docs/examples/parallelPDF.py @@ -38,9 +38,9 @@ if opts.pyobjcryst: # use pyobjcryst if requested by the user from numpy import pi - from pyobjcryst import loadCrystal + from pyobjcryst.crystal import create_crystal_from_cif - menthol = loadCrystal(mentholcif) + menthol = create_crystal_from_cif(mentholcif) for sc in menthol.GetScatteringComponentList(): sp = sc.mpScattPow sp.Biso = sp.Biso or 8 * pi**2 * Uisodefault diff --git a/requirements/pip.txt b/requirements/pip.txt index e69de29b..a85739ed 100644 --- a/requirements/pip.txt +++ b/requirements/pip.txt @@ -0,0 +1,2 @@ +setuptools +numpy diff --git a/setup.py b/setup.py index d781a2a9..ab1f8587 100644 --- a/setup.py +++ b/setup.py @@ -17,14 +17,26 @@ def get_boost_libraries(): - base_lib = "boost_python" - major, minor = str(sys.version_info[0]), str(sys.version_info[1]) - tags = [f"{major}{minor}", major, ""] - mttags = ["", "-mt"] - candidates = [base_lib + tag for tag in tags for mt in mttags] + [base_lib] - for lib in candidates: - if find_library(lib): - return [lib] + major, minor = sys.version_info[:2] + candidates = [ + f"boost_python{major}{minor}", + f"boost_python{major}", + "boost_python", + ] + + conda_prefix = os.environ.get("CONDA_PREFIX") + if conda_prefix: + libdir = os.path.join(conda_prefix, "lib") + for name in candidates: + so = f"lib{name}.so" + if os.path.isfile(os.path.join(libdir, so)): + return [name] + + # fallback to ldconfig + for name in candidates: + found = find_library(name) + if found: + return [name] raise RuntimeError("Cannot find a suitable Boost.Python library.") @@ -111,11 +123,11 @@ def create_extensions(): # Extensions not included in pyproject.toml -setup_args = dict( - ext_modules=[], -) +def ext_modules(): + if set(sys.argv) & {"build_ext", "bdist_wheel", "install"}: + return create_extensions() + return [] if __name__ == "__main__": - setup_args["ext_modules"] = create_extensions() - setup(**setup_args) + setup(ext_modules=ext_modules()) diff --git a/src/diffpy/srreal/version.py b/src/diffpy/srreal/version.py index 54d1c6b3..a988772a 100644 --- a/src/diffpy/srreal/version.py +++ b/src/diffpy/srreal/version.py @@ -18,8 +18,14 @@ # __all__ = ["__date__", "__git_commit__", "__timestamp__", "__version__"] # obtain version information -from importlib.metadata import version +from importlib.metadata import PackageNotFoundError, version + +FALLBACK_VERSION = "1.3.0" + +try: + __version__ = version("diffpy.srreal") +except PackageNotFoundError: + __version__ = FALLBACK_VERSION -__version__ = version("diffpy.srreal") # End of file diff --git a/tests/testutils.py b/tests/testutils.py index c2991a33..cee8d01f 100644 --- a/tests/testutils.py +++ b/tests/testutils.py @@ -28,10 +28,10 @@ def datafile(filename): def loadObjCrystCrystal(filename): - from pyobjcryst import loadCrystal + from pyobjcryst.crystal import create_crystal_from_cif fullpath = datafile(filename) - crst = loadCrystal(fullpath) + crst = create_crystal_from_cif(fullpath) return crst From c88a7ea1c4d0d05f0200a288c61f3ccd75e835c6 Mon Sep 17 00:00:00 2001 From: Tieqiong Zhang Date: Fri, 1 Aug 2025 00:58:33 -0400 Subject: [PATCH 2/2] correct fixture typos... --- tests/test_bondcalculator.py | 2 +- tests/test_overlapcalculator.py | 2 +- tests/test_pdfcalcobjcryst.py | 2 +- tests/test_sfaverage.py | 2 +- tests/test_structureadapter.py | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/test_bondcalculator.py b/tests/test_bondcalculator.py index 4b280397..8dd39ad0 100644 --- a/tests/test_bondcalculator.py +++ b/tests/test_bondcalculator.py @@ -255,7 +255,7 @@ def test_setTypeMask(self): class TestBondCalculatorObjCryst(unittest.TestCase): @pytest.fixture(autouse=True) - def _check_periodictable(self, has_pyobjcryst, _msg_nopyobjcryst): + def _check_pyobjcryst(self, has_pyobjcryst, _msg_nopyobjcryst): if not has_pyobjcryst: pytest.skip(_msg_nopyobjcryst) diff --git a/tests/test_overlapcalculator.py b/tests/test_overlapcalculator.py index ce27bd31..c281ef7c 100644 --- a/tests/test_overlapcalculator.py +++ b/tests/test_overlapcalculator.py @@ -344,7 +344,7 @@ def test_neighborhoods(self): class TestOverlapCalculatorObjCryst(unittest.TestCase): @pytest.fixture(autouse=True) - def _check_periodictable(self, has_pyobjcryst, _msg_nopyobjcryst): + def _check_pyobjcryst(self, has_pyobjcryst, _msg_nopyobjcryst): if not has_pyobjcryst: pytest.skip(_msg_nopyobjcryst) diff --git a/tests/test_pdfcalcobjcryst.py b/tests/test_pdfcalcobjcryst.py index 3780558f..d0ef6da5 100644 --- a/tests/test_pdfcalcobjcryst.py +++ b/tests/test_pdfcalcobjcryst.py @@ -62,7 +62,7 @@ def _makePDFCalculator(crst, cfgdict): class TestPDFCalcObjcryst(unittest.TestCase): @pytest.fixture(autouse=True) - def _check_periodictable(self, has_pyobjcryst, _msg_nopyobjcryst): + def _check_pyobjcryst(self, has_pyobjcryst, _msg_nopyobjcryst): if not has_pyobjcryst: pytest.skip(_msg_nopyobjcryst) diff --git a/tests/test_sfaverage.py b/tests/test_sfaverage.py index 1171b590..bff8c800 100644 --- a/tests/test_sfaverage.py +++ b/tests/test_sfaverage.py @@ -79,7 +79,7 @@ def test_fromComposition(self): class TestSFAverageObjCryst(unittest.TestCase): @pytest.fixture(autouse=True) - def _check_periodictable(self, has_pyobjcryst, _msg_nopyobjcryst): + def _check_pyobjcryst(self, has_pyobjcryst, _msg_nopyobjcryst): if not has_pyobjcryst: pytest.skip(_msg_nopyobjcryst) diff --git a/tests/test_structureadapter.py b/tests/test_structureadapter.py index 186e2ba6..910faae8 100644 --- a/tests/test_structureadapter.py +++ b/tests/test_structureadapter.py @@ -286,7 +286,7 @@ def test_nosymmetry_pickling(self): class TestPyObjCrystAdapter(unittest.TestCase): @pytest.fixture(autouse=True) - def _check_periodictable(self, has_pyobjcryst, _msg_nopyobjcryst): + def _check_pyobjcryst(self, has_pyobjcryst, _msg_nopyobjcryst): if not has_pyobjcryst: pytest.skip(_msg_nopyobjcryst)