Skip to content

Commit 5072d22

Browse files
committed
update setup.py for wheel build
correct function name typos correct pip.txt add version fallback
1 parent 8f68bf6 commit 5072d22

File tree

6 files changed

+41
-21
lines changed

6 files changed

+41
-21
lines changed

docs/examples/distanceprinter.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ def _addPairContribution(self, bnds, sumscale):
4747

4848

4949
def get_pyobjcryst_sphalerite():
50-
from pyobjcryst import loadCrystal
50+
from pyobjcryst.crystal import create_crystal_from_cif
5151

52-
crst = loadCrystal("datafiles/sphalerite.cif")
52+
crst = create_crystal_from_cif("datafiles/sphalerite.cif")
5353
return crst
5454

5555

docs/examples/parallelPDF.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@
3838
if opts.pyobjcryst:
3939
# use pyobjcryst if requested by the user
4040
from numpy import pi
41-
from pyobjcryst import loadCrystal
41+
from pyobjcryst.crystal import create_crystal_from_cif
4242

43-
menthol = loadCrystal(mentholcif)
43+
menthol = create_crystal_from_cif(mentholcif)
4444
for sc in menthol.GetScatteringComponentList():
4545
sp = sc.mpScattPow
4646
sp.Biso = sp.Biso or 8 * pi**2 * Uisodefault

requirements/pip.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
setuptools
2+
numpy

setup.py

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,26 @@
1717

1818

1919
def get_boost_libraries():
20-
base_lib = "boost_python"
21-
major, minor = str(sys.version_info[0]), str(sys.version_info[1])
22-
tags = [f"{major}{minor}", major, ""]
23-
mttags = ["", "-mt"]
24-
candidates = [base_lib + tag for tag in tags for mt in mttags] + [base_lib]
25-
for lib in candidates:
26-
if find_library(lib):
27-
return [lib]
20+
major, minor = sys.version_info[:2]
21+
candidates = [
22+
f"boost_python{major}{minor}",
23+
f"boost_python{major}",
24+
"boost_python",
25+
]
26+
27+
conda_prefix = os.environ.get("CONDA_PREFIX")
28+
if conda_prefix:
29+
libdir = os.path.join(conda_prefix, "lib")
30+
for name in candidates:
31+
so = f"lib{name}.so"
32+
if os.path.isfile(os.path.join(libdir, so)):
33+
return [name]
34+
35+
# fallback to ldconfig
36+
for name in candidates:
37+
found = find_library(name)
38+
if found:
39+
return [name]
2840
raise RuntimeError("Cannot find a suitable Boost.Python library.")
2941

3042

@@ -111,11 +123,11 @@ def create_extensions():
111123

112124

113125
# Extensions not included in pyproject.toml
114-
setup_args = dict(
115-
ext_modules=[],
116-
)
126+
def ext_modules():
127+
if set(sys.argv) & {"build_ext", "bdist_wheel", "install"}:
128+
return create_extensions()
129+
return []
117130

118131

119132
if __name__ == "__main__":
120-
setup_args["ext_modules"] = create_extensions()
121-
setup(**setup_args)
133+
setup(ext_modules=ext_modules())

src/diffpy/srreal/version.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,14 @@
1818
# __all__ = ["__date__", "__git_commit__", "__timestamp__", "__version__"]
1919

2020
# obtain version information
21-
from importlib.metadata import version
21+
from importlib.metadata import PackageNotFoundError, version
22+
23+
FALLBACK_VERSION = "1.3.0"
24+
25+
try:
26+
__version__ = version("diffpy.srreal")
27+
except PackageNotFoundError:
28+
__version__ = FALLBACK_VERSION
2229

23-
__version__ = version("diffpy.srreal")
2430

2531
# End of file

tests/testutils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ def datafile(filename):
2828

2929

3030
def loadObjCrystCrystal(filename):
31-
from pyobjcryst import loadCrystal
31+
from pyobjcryst.crystal import create_crystal_from_cif
3232

3333
fullpath = datafile(filename)
34-
crst = loadCrystal(fullpath)
34+
crst = create_crystal_from_cif(fullpath)
3535
return crst
3636

3737

0 commit comments

Comments
 (0)