Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
738d462
gitignore
Tieqiong Feb 1, 2025
59d5688
fix win include and export
Tieqiong Feb 1, 2025
601959f
fix build scripts for Windows
Tieqiong Feb 1, 2025
28c0622
small fix
Tieqiong Feb 2, 2025
4192120
Merge pull request #36 from Tieqiong/windows
sbillinge Feb 2, 2025
86ba6f7
add flags for objcryst
Tieqiong Jun 19, 2025
cb4e557
Merge pull request #37 from Tieqiong/objcryst_flag
sbillinge Jun 19, 2025
251f9aa
correct prefix
Tieqiong Jun 20, 2025
fd7a40f
Merge pull request #38 from Tieqiong/prefix
sbillinge Jun 20, 2025
b472d41
auto release with sha after tag push
Tieqiong Jun 23, 2025
ec370af
Merge pull request #39 from Tieqiong/workflow
sbillinge Jun 24, 2025
ba376c7
add precommit hooks and configuration files
Tieqiong Jun 25, 2025
5e9ea98
add comments into ignore_words
Tieqiong Jun 25, 2025
1785ad7
Merge pull request #41 from Tieqiong/linting
sbillinge Jun 26, 2025
fdb9d4b
bump fallback_version
Tieqiong Sep 16, 2025
01bd9e4
rename doc to docs
Tieqiong Sep 16, 2025
dc08600
Merge pull request #43 from Tieqiong/ver
sbillinge Sep 17, 2025
f1343ba
Merge Windows build fixes from diffpy/libdiffpy windows (up to b472d41)
SYMSCAE Oct 28, 2026
69c43f4
style: apply clang-format (Google style) to C++ sources
SYMSCAE Oct 28, 2026
178deab
Merge upstream windows commit ba376c7 (clang-format and pre-commit se…
SYMSCAE Oct 28, 2026
3a2ad63
Merge remaining upstream windows commits into skpkg-migration
SYMSCAE Oct 28, 2026
0769619
chore: add .git-blame-ignore-revs and news for the Windows merge
SYMSCAE Oct 28, 2026
a1e7fa7
build: fix Windows build settings
SYMSCAE Oct 28, 2026
8eca86a
fix: resolve release versions from lightweight Git tags
SYMSCAE Oct 28, 2026
c4af821
fix: run C++ matrix tests and repair Windows DLL support
SYMSCAE Oct 28, 2026
97130d5
ci: speed up environment setup and C++ builds
SYMSCAE Oct 28, 2026
345f7a9
Remove git blame settings
SYMSCAE Oct 28, 2026
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
10 changes: 10 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
BasedOnStyle: Google

IndentWidth: 2
ContinuationIndentWidth: 2
TabWidth: 2
UseTab: Never

ColumnLimit: 80

SortIncludes: false
55 changes: 55 additions & 0 deletions .github/scripts/configure-matrix.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
"""Configure SCons and CxxTest for the CI matrix."""

import json
from pathlib import Path

requirements = ["python"]
for filename in ("build.txt", "conda.txt", "tests.txt"):
for line in (Path("requirements") / filename).read_text().splitlines():
spec = line.split("#", 1)[0].strip()
if spec and spec != "cxxtest":
requirements.append(spec)

Path("build").mkdir(exist_ok=True)
Path("build/matrix-environment.yml").write_text(
json.dumps(
{
"name": "test",
"channels": ["conda-forge"],
"dependencies": requirements,
},
indent=2,
)
+ "\n"
)

Path("sconscript.local").write_text("""\
Import('env')
import os
import sys

prefix = os.environ['CONDA_PREFIX']
cxxtest = Dir('#/build/cxxtest').abspath
env.Replace(CXXTEST=os.path.join(cxxtest, 'bin', 'cxxtestgen'),
CXXTEST_INSTALL_DIR=cxxtest, CXXTEST_PYTHON=sys.executable)

if env['PLATFORM'] == 'win32':
from SCons.Platform.win32 import exec_spawn

# The outer CI shell already activates conda and SCons configures MSVC.
# /D stops each compiler/test-generator child from repeating cmd AutoRun.
def spawn_without_autorun(sh, escape, cmd, args, child_env):
return exec_spawn([sh, '/D', '/C', escape(' '.join(args))], child_env)

env['SPAWN'] = spawn_without_autorun
else:
env.Replace(CXX=os.environ.get('CXX', os.path.join(prefix, 'bin', 'c++')))
env.Prepend(CCFLAGS=['-isystem' + os.path.join(prefix, 'include')])
env.Append(LIBPATH=os.path.join(prefix, 'lib'))
env.Append(LINKFLAGS='-Wl,-rpath,' + os.path.join(prefix, 'lib'))
if env['PLATFORM'] == 'darwin':
sdk = os.environ.get('CONDA_BUILD_SYSROOT')
if sdk:
env.Append(CXXFLAGS=['-isysroot', sdk])
env.Append(LINKFLAGS=['-isysroot', sdk])
""")
104 changes: 97 additions & 7 deletions .github/workflows/matrix-and-codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,102 @@ on:
- published
workflow_dispatch:

concurrency:
group: matrix-${{ github.ref }}
cancel-in-progress: ${{ github.event_name != 'release' }}

jobs:
matrix-coverage:
uses: scikit-package/release-scripts/.github/workflows/_matrix-and-codecov-on-merge-to-main.yml@v0
with:
project: libdiffpy
c_extension: true
headless: false
secrets:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
name: C++ tests (${{ matrix.os }}, Python ${{ matrix.python-version }})
runs-on: ${{ matrix.os }}
timeout-minutes: 45
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest, macos-15-intel]
python-version: ["3.12", "3.13", "3.14"]
include:
- os: ubuntu-latest
shell: bash -l {0}
build: coverage
jobs: 4
- os: windows-latest
shell: cmd /C CALL {0}
build: fast
jobs: 4
- os: macos-latest
shell: bash -l {0}
build: fast
jobs: 2
- os: macos-15-intel
shell: bash -l {0}
build: fast
jobs: 4
defaults:
run:
shell: ${{ matrix.shell }}

steps:
- name: Check out libdiffpy
uses: actions/checkout@v6
with:
fetch-depth: 0

- name: Fetch upstream release tags
run: git fetch --tags https://github.com/diffpy/libdiffpy.git

# CxxTest is header-only and its generator runs directly from source.
# The conda-forge package is not available on every matrix platform.
- name: Check out CxxTest 4.4
uses: actions/checkout@v6
with:
repository: CxxTest/cxxtest
ref: 191adddb3876ab389c0c856e1c03874bf70f8ee4
path: build/cxxtest

- name: Prepare C++ test configuration
shell: python {0}
run: |
import runpy
runpy.run_path('.github/scripts/configure-matrix.py')

- name: Create build environment
uses: conda-incubator/setup-miniconda@v3
with:
activate-environment: test
channels: conda-forge
conda-remove-defaults: "true"
auto-update-conda: false
auto-activate-base: false
python-version: ${{ matrix.python-version }}
environment-file: build/matrix-environment.yml
channel-priority: strict

- name: Build and run C++ tests
run: scons -j${{ matrix.jobs }} build=${{ matrix.build }} test

- name: Generate coverage report
if: runner.os == 'Linux' && matrix.python-version == '3.14'
run: >-
gcovr --gcov-executable "$CONDA_PREFIX/bin/gcov"
--root . --filter 'build/coverage-.*/diffpy/'
--xml coverage.xml

- name: Save coverage report
if: runner.os == 'Linux' && matrix.python-version == '3.14'
uses: actions/upload-artifact@v4
with:
name: coverage-report
path: coverage.xml
if-no-files-found: error

- name: Upload coverage to Codecov
# Fork push builds have no upstream Codecov token; keep their artifact.
if: >-
runner.os == 'Linux' && matrix.python-version == '3.14' &&
github.repository == 'diffpy/libdiffpy'
uses: codecov/codecov-action@v5
with:
files: coverage.xml
fail_ci_if_error: true
token: ${{ secrets.CODECOV_TOKEN }}
8 changes: 6 additions & 2 deletions .github/workflows/tests-on-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ on:
pull_request:
workflow_dispatch:

concurrency:
group: tests-on-pr-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
tests-on-pr:
runs-on: ubuntu-latest
Expand All @@ -23,7 +27,7 @@ jobs:
activate-environment: test
channels: conda-forge
conda-remove-defaults: "true"
auto-update-conda: true
auto-update-conda: false
auto-activate-base: false

- name: Conda config
Expand Down Expand Up @@ -53,7 +57,7 @@ jobs:
- name: Build and run C++ tests with coverage
run: |
"$CONDA_PREFIX/bin/c++" --version
scons build=coverage test
scons -j4 build=coverage test

- name: Generate coverage report
run: >-
Expand Down
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,12 @@ target/

# Ipython Notebook
.ipynb_checkpoints

# source distribution tarball
libdiffpy-*.tar.gz

# Windows build artifacts (MSVC)
.vs/
*.exp
*.lib
*.dll
6 changes: 6 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ repos:
hooks:
- id: isort
args: ["--profile", "black"]
- repo: https://github.com/pre-commit/mirrors-clang-format
rev: v20.1.6
hooks:
- id: clang-format
name: clang-format (C/C++)
files: \.(c|cpp|cc|cxx|h|hpp|hh)$
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v6.0.0
hooks:
Expand Down
67 changes: 54 additions & 13 deletions SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ SCons construction environment can be customized in sconscript.local script.

import os
import platform
from os.path import join as pjoin
from SCons.Script import *

def subdictionary(d, keyset):
return dict(kv for kv in d.items() if kv[0] in keyset)
Expand All @@ -31,46 +33,82 @@ DefaultEnvironment(ENV=subdictionary(os.environ, '''
PATH CPATH CPLUS_INCLUDE_PATH LIBRARY_PATH LD_RUN_PATH
LD_LIBRARY_PATH DYLD_LIBRARY_PATH DYLD_FALLBACK_LIBRARY_PATH
MACOSX_DEPLOYMENT_TARGET
HOME USERPROFILE HOMEDRIVE HOMEPATH APPDATA LOCALAPPDATA
'''.split())
)

# Create construction environment
env = DefaultEnvironment().Clone()

# Variables definitions below work only with 0.98.1 or later.
# Variables definitions below work only with 0.98.1 or later
env.EnsureSConsVersion(0, 98, 1)

# Customizable compile variables
vars = Variables('sconsvars.py')

vars.Add(PathVariable(
'prefix',
'installation prefix directory',
'/usr/local'))
vars.Update(env)
# Set PATHs
if 'PREFIX' in os.environ:
vars.Add(PathVariable(
'prefix',
'installation prefix directory',
os.environ['PREFIX']))
vars.Update(env)
elif 'CONDA_PREFIX' in os.environ:
vars.Add(PathVariable(
'prefix',
'installation prefix directory',
os.environ['CONDA_PREFIX']))
vars.Update(env)
else:
vars.Add(PathVariable(
'prefix',
'installation prefix directory',
'/usr/local'))
vars.Update(env)

if env['PLATFORM'] == "win32":
include_path = pjoin(env['prefix'], 'Library', 'include')
lib_path = pjoin(env['prefix'], 'Library', 'lib')
shared_path = pjoin(env['prefix'], 'Library', 'share')

# Windows programs started by SCons, such as python for cxxtestgen,
# fail without these system variables.
for k in ('SYSTEMROOT', 'SYSTEMDRIVE', 'COMSPEC', 'PATHEXT', 'TEMP', 'TMP'):
if k in os.environ:
env['ENV'][k] = os.environ[k]
else:
include_path = pjoin(env['prefix'], 'include')
lib_path = pjoin(env['prefix'], 'lib')
shared_path = pjoin(env['prefix'], 'share')

vars.Add(PathVariable(
'libdir',
'installation directory for compiled library [prefix/lib]',
env['prefix'] + '/lib',
'installation directory for compiled programs',
lib_path,
PathVariable.PathAccept))
vars.Add(PathVariable(
'includedir',
'installation directory for C++ header files [prefix/include]',
env['prefix'] + '/include',
'installation directory for C++ header files',
include_path,
PathVariable.PathAccept))
vars.Add(PathVariable(
'datadir',
'installation directory for architecture independent data [prefix/share]',
env['prefix'] + '/share',
'installation directory for architecture independent data',
shared_path,
PathVariable.PathAccept))

env.AppendUnique(CPPPATH=[include_path])
env.AppendUnique(LIBPATH=[lib_path])

# Customizable build variables
vars.Add(EnumVariable(
'build',
'compiler settings',
'fast', allowed_values=('fast', 'debug', 'develop', 'coverage')))
vars.Add(EnumVariable(
'tool',
'C++ compiler toolkit to be used',
'default', allowed_values=('default', 'intelc')))
'default', allowed_values=('default', 'clang', 'gcc', 'intelc')))
vars.Add(BoolVariable(
'enable_objcryst',
'enable objcryst support, when installed', None))
Expand All @@ -83,10 +121,13 @@ vars.Add(
vars.Add(BoolVariable(
'test_installed',
'build tests using the installed library.', False))

vars.Update(env)

env.Help(MY_SCONS_HELP % vars.GenerateHelpText(env))

env['has_objcryst'] = None

btags = [env['build'], platform.machine()]
if env['profile']: btags.append('profile')
builddir = env.Dir('build/' + '-'.join(btags))
Expand Down
16 changes: 7 additions & 9 deletions examples/testlib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,14 @@
// c++ testlib.cpp -ldiffpy
// ./a.out


#include <iostream>
#include <diffpy/srreal/ScatteringFactorTable.hpp>

int main(int argc, char* argv[])
{
using namespace diffpy::srreal;
ScatteringFactorTablePtr ntbl;
ntbl = ScatteringFactorTable::createByType("neutron");
ntbl->lookup("Pb");
std::cout << "Installation of libdiffpy shared library works!\n";
return 0;
int main(int argc, char* argv[]) {
using namespace diffpy::srreal;
ScatteringFactorTablePtr ntbl;
ntbl = ScatteringFactorTable::createByType("neutron");
ntbl->lookup("Pb");
std::cout << "Installation of libdiffpy shared library works!\n";
return 0;
}
Loading
Loading