Skip to content

Commit f8ace0c

Browse files
authoredJan 13, 2025
Merge pull request #128 from Tieqiong/sdist
fix: build sdist failing
2 parents 5c1641f + 8008d20 commit f8ace0c

File tree

2 files changed

+69
-45
lines changed

2 files changed

+69
-45
lines changed
 

‎news/sdist.rst

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
**Added:**
2+
3+
* <news item>
4+
5+
**Changed:**
6+
7+
* Changed setup.py to lazy evaluate gsl installation.
8+
9+
**Deprecated:**
10+
11+
* <news item>
12+
13+
**Removed:**
14+
15+
* <news item>
16+
17+
**Fixed:**
18+
19+
* <news item>
20+
21+
**Security:**
22+
23+
* <news item>

‎setup.py

+46-45
Original file line numberDiff line numberDiff line change
@@ -141,53 +141,54 @@ def run(self):
141141
shutil.copy(str(dll_file), str(dest_path))
142142

143143

144-
# Compile and link options----------------------------------------------------
145-
146-
os_name = os.name
147-
gcfg = get_gsl_config()
148-
149-
# On macOS, dynamic linking may not be needed
150-
if sys.platform == "darwin":
151-
libraries = []
152-
else:
153-
libraries = ["gsl"]
154-
155-
include_dirs = [MYDIR] + gcfg["include_dirs"]
156-
library_dirs = gcfg["library_dirs"]
157-
define_macros = []
158-
extra_objects = []
159-
extra_compile_args = []
160-
extra_link_args = []
161-
162-
compiler_type = get_compiler_type()
163-
if compiler_type in ("unix", "cygwin", "mingw32"):
164-
extra_compile_args = ["-std=c++11", "-Wall", "-Wno-write-strings", "-O3", "-funroll-loops", "-ffast-math"]
165-
# Check for static GSL libraries and add them if found.
166-
static_libs = [
167-
os.path.join(p, "libgsl.a") for p in gcfg["library_dirs"] if os.path.isfile(os.path.join(p, "libgsl.a"))
168-
]
169-
if static_libs:
170-
extra_objects += static_libs
171-
# Use static linking: remove "-lgsl" to avoid dynamic linking conflicts.
172-
libraries = []
173-
elif compiler_type == "msvc":
174-
define_macros += [("_USE_MATH_DEFINES", None)]
175-
extra_compile_args = ["/EHs"]
176-
177-
# Extension keyword arguments.
178-
ext_kws = {
179-
"include_dirs": include_dirs,
180-
"libraries": libraries,
181-
"library_dirs": library_dirs,
182-
"define_macros": define_macros,
183-
"extra_compile_args": extra_compile_args,
184-
"extra_link_args": extra_link_args,
185-
"extra_objects": extra_objects,
186-
}
187-
188-
189144
def create_extensions():
190145
"""Create the list of Extension objects for the build."""
146+
# lazy evaluation prevents build sdist failure
147+
try:
148+
gcfg = get_gsl_config()
149+
except EnvironmentError:
150+
return []
151+
152+
# On macOS, dynamic linking may not be needed
153+
if sys.platform == "darwin":
154+
libraries = []
155+
else:
156+
libraries = ["gsl"]
157+
158+
include_dirs = [MYDIR] + gcfg["include_dirs"]
159+
library_dirs = gcfg["library_dirs"]
160+
define_macros = []
161+
extra_objects = []
162+
extra_compile_args = []
163+
extra_link_args = []
164+
165+
compiler_type = get_compiler_type()
166+
if compiler_type in ("unix", "cygwin", "mingw32"):
167+
extra_compile_args = ["-std=c++11", "-Wall", "-Wno-write-strings", "-O3", "-funroll-loops", "-ffast-math"]
168+
# Check for static GSL libraries and add them if found.
169+
static_libs = [
170+
os.path.join(p, "libgsl.a")
171+
for p in gcfg["library_dirs"]
172+
if os.path.isfile(os.path.join(p, "libgsl.a"))
173+
]
174+
if static_libs:
175+
extra_objects += static_libs
176+
# Use static linking: remove "-lgsl" to avoid dynamic linking conflicts.
177+
libraries = []
178+
elif compiler_type == "msvc":
179+
define_macros += [("_USE_MATH_DEFINES", None)]
180+
extra_compile_args = ["/EHs"]
181+
182+
# Extension keyword arguments.
183+
ext_kws = {
184+
"include_dirs": include_dirs,
185+
"libraries": libraries,
186+
"library_dirs": library_dirs,
187+
"define_macros": define_macros,
188+
"extra_compile_args": extra_compile_args,
189+
"extra_link_args": extra_link_args,
190+
"extra_objects": extra_objects,
191+
}
191192
ext = Extension("diffpy.pdffit2.pdffit2", glob.glob("src/extensions/**/*.cc"), **ext_kws)
192193
return [ext]
193194

0 commit comments

Comments
 (0)