diff --git a/docs/examples/distanceprinter.py b/docs/examples/distanceprinter.py index 870c721..356f112 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 199ebaa..762d4ea 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 e69de29..a85739e 100644 --- a/requirements/pip.txt +++ b/requirements/pip.txt @@ -0,0 +1,2 @@ +setuptools +numpy diff --git a/setup.py b/setup.py index d781a2a..ab1f858 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 54d1c6b..a988772 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/test_bondcalculator.py b/tests/test_bondcalculator.py index 4b28039..8dd39ad 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 ce27bd3..c281ef7 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 3780558..d0ef6da 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 1171b59..bff8c80 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 186e2ba..910faae 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) diff --git a/tests/testutils.py b/tests/testutils.py index c2991a3..cee8d01 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