Skip to content

Commit 2202fb8

Browse files
authored
Merge pull request #56 from Tieqiong/setup
fix: find objcryst
2 parents a1420e4 + a86ab58 commit 2202fb8

File tree

3 files changed

+47
-13
lines changed

3 files changed

+47
-13
lines changed

.github/workflows/tests-on-pr.yml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,13 @@ jobs:
1414
run:
1515
shell: bash -l {0}
1616

17-
runs-on: macos-14
17+
runs-on: ${{ matrix.os }}
18+
strategy:
19+
fail-fast: false
20+
matrix:
21+
os: [ubuntu-latest, windows-latest, macos-13, macos-14]
22+
python-version: [3.11, 3.12, 3.13]
23+
1824
steps:
1925
- name: Check out diffpy.srreal
2026
uses: actions/checkout@v4
@@ -26,7 +32,7 @@ jobs:
2632
auto-update-conda: true
2733
environment-file: environment.yml
2834
auto-activate-base: false
29-
python-version: 3.12
35+
python-version: ${{ matrix.python-version }}
3036

3137
- name: Conda config
3238
run: >-
@@ -35,8 +41,8 @@ jobs:
3541
3642
- name: Install diffpy.srreal and requirements
3743
run: |
44+
conda install --file requirements/conda.txt
3845
conda install --file requirements/test.txt
39-
conda install boost numpy libdiffpy setuptools diffpy.structure periodictable gsl
4046
python -m pip install . --no-deps
4147
4248
- name: Validate diffpy.pdfgui

requirements/conda.txt

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1-
boost
2-
numpy
3-
libdiffpy
4-
setuptools
1+
libdiffpy=1.4.1rc1
2+
libboost-devel
3+
libobjcryst
4+
pyobjcryst
55
diffpy.structure
6-
gsl
7-
# periodictable
8-
# pyobjcryst (up to py3.11 for mac)
9-
# dlfcn-win32 (for windows)
6+
periodictable

setup.py

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,20 +48,51 @@ def get_boost_config():
4848
return {"include_dirs": [str(inc)], "library_dirs": [str(lib)]}
4949

5050

51+
def get_objcryst_libraries():
52+
conda_prefix = os.environ.get("CONDA_PREFIX")
53+
if not conda_prefix:
54+
raise EnvironmentError(
55+
"CONDA_PREFIX is not set. Please install ObjCryst using conda and activate the environment."
56+
)
57+
if os.name == "nt":
58+
libdir = Path(conda_prefix) / "Library" / "lib"
59+
else:
60+
libdir = Path(conda_prefix) / "lib"
61+
62+
libs = []
63+
for fn in os.listdir(libdir):
64+
stem = Path(fn).stem
65+
if "objcryst" not in stem.lower():
66+
continue
67+
# strip a leading "lib" so that setuptools does -lObjCryst, not -llibObjCryst
68+
if os.name != "nt" and stem.startswith("lib"):
69+
stem = stem[3:]
70+
libs.append(stem)
71+
72+
if not libs:
73+
raise RuntimeError(f"No ObjCryst libraries found in {libdir}")
74+
return libs
75+
76+
5177
if os.name == "nt":
5278
compile_args = ["/std:c++14"]
5379
macros = [("_USE_MATH_DEFINES", None)]
80+
extra_link_args = ["/FORCE:MULTIPLE"]
5481
else:
5582
compile_args = ["-std=c++11"]
5683
macros = []
84+
extra_link_args = []
5785

5886
boost_cfg = get_boost_config()
87+
objcryst_libs = get_objcryst_libraries()
88+
5989
ext_kws = {
60-
"libraries": ["diffpy"] + get_boost_libraries(),
90+
"libraries": ["diffpy"] + get_boost_libraries() + objcryst_libs,
6191
"extra_compile_args": compile_args,
62-
"extra_link_args": [],
92+
"extra_link_args": extra_link_args,
6393
"include_dirs": [numpy.get_include()] + boost_cfg["include_dirs"],
6494
"library_dirs": boost_cfg["library_dirs"],
95+
# "runtime_library_dirs": boost_cfg["library_dirs"],
6596
"define_macros": macros,
6697
}
6798

0 commit comments

Comments
 (0)