Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions .github/workflows/sdist.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Tests build sdist

on:
push:
pull_request:
workflow_dispatch:

jobs:
build_sdist:
name: Build diffpy.pdffit2 sdist
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.ref }}

- name: Build sdist
run: pipx run build --sdist

- uses: actions/upload-artifact@v4
with:
name: cibw-sdist
path: ./dist/*.tar.gz
23 changes: 23 additions & 0 deletions news/sdist.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
**Added:**

* <news item>

**Changed:**

* Changed setup.py to lazy evaluate gsl installation.

**Deprecated:**

* <news item>

**Removed:**

* <news item>

**Fixed:**

* <news item>

**Security:**

* <news item>
91 changes: 46 additions & 45 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,53 +141,54 @@ def run(self):
shutil.copy(str(dll_file), str(dest_path))


# Compile and link options----------------------------------------------------

os_name = os.name
gcfg = get_gsl_config()

# On macOS, dynamic linking may not be needed
if sys.platform == "darwin":
libraries = []
else:
libraries = ["gsl"]

include_dirs = [MYDIR] + gcfg["include_dirs"]
library_dirs = gcfg["library_dirs"]
define_macros = []
extra_objects = []
extra_compile_args = []
extra_link_args = []

compiler_type = get_compiler_type()
if compiler_type in ("unix", "cygwin", "mingw32"):
extra_compile_args = ["-std=c++11", "-Wall", "-Wno-write-strings", "-O3", "-funroll-loops", "-ffast-math"]
# Check for static GSL libraries and add them if found.
static_libs = [
os.path.join(p, "libgsl.a") for p in gcfg["library_dirs"] if os.path.isfile(os.path.join(p, "libgsl.a"))
]
if static_libs:
extra_objects += static_libs
# Use static linking: remove "-lgsl" to avoid dynamic linking conflicts.
libraries = []
elif compiler_type == "msvc":
define_macros += [("_USE_MATH_DEFINES", None)]
extra_compile_args = ["/EHs"]

# Extension keyword arguments.
ext_kws = {
"include_dirs": include_dirs,
"libraries": libraries,
"library_dirs": library_dirs,
"define_macros": define_macros,
"extra_compile_args": extra_compile_args,
"extra_link_args": extra_link_args,
"extra_objects": extra_objects,
}


def create_extensions():
"""Create the list of Extension objects for the build."""
# lazy evaluation prevents build sdist failure
try:
gcfg = get_gsl_config()
except EnvironmentError:
return []

# On macOS, dynamic linking may not be needed
if sys.platform == "darwin":
libraries = []
else:
libraries = ["gsl"]

include_dirs = [MYDIR] + gcfg["include_dirs"]
library_dirs = gcfg["library_dirs"]
define_macros = []
extra_objects = []
extra_compile_args = []
extra_link_args = []

compiler_type = get_compiler_type()
if compiler_type in ("unix", "cygwin", "mingw32"):
extra_compile_args = ["-std=c++11", "-Wall", "-Wno-write-strings", "-O3", "-funroll-loops", "-ffast-math"]
# Check for static GSL libraries and add them if found.
static_libs = [
os.path.join(p, "libgsl.a")
for p in gcfg["library_dirs"]
if os.path.isfile(os.path.join(p, "libgsl.a"))
]
if static_libs:
extra_objects += static_libs
# Use static linking: remove "-lgsl" to avoid dynamic linking conflicts.
libraries = []
elif compiler_type == "msvc":
define_macros += [("_USE_MATH_DEFINES", None)]
extra_compile_args = ["/EHs"]

# Extension keyword arguments.
ext_kws = {
"include_dirs": include_dirs,
"libraries": libraries,
"library_dirs": library_dirs,
"define_macros": define_macros,
"extra_compile_args": extra_compile_args,
"extra_link_args": extra_link_args,
"extra_objects": extra_objects,
}
ext = Extension("diffpy.pdffit2.pdffit2", glob.glob("src/extensions/**/*.cc"), **ext_kws)
return [ext]

Expand Down
Loading