Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
cb9bcfc
updated cpp version and replaced boost smart pointer usages
SYMSCAE Jun 24, 2026
a77b086
added nanobind source to build system
SYMSCAE Jun 24, 2026
107ea7c
ran docformatter
SYMSCAE Jun 24, 2026
330e612
update precommit deps
SYMSCAE Jun 25, 2026
70778b9
fix docformatter conflicts
SYMSCAE Jun 26, 2026
790eff8
Merge pull request #87 from SYMSCAE/precommit-deps
sbillinge Jun 26, 2026
5094a2a
Merge branch 'main' into nanobind-deps
SYMSCAE Jun 26, 2026
63006a8
news
SYMSCAE Jun 26, 2026
71ddfd5
migrated syntax for srreal_converters and srreal_validators
SYMSCAE Jun 24, 2026
50e706b
migrated syntax for srreal_ext and srreal_registry
SYMSCAE Jun 24, 2026
eebb59d
reworked pickling and migrated syntax for wrap_AtomicStructureAdapter
SYMSCAE Jun 25, 2026
49430b4
migrated bindings for AtomRadiiTable, Attributes, BaseBondGenerator a…
SYMSCAE Jun 25, 2026
774b475
migrated bindings for BVParametersTable, BVSCalculator, EventTicker a…
SYMSCAE Jun 25, 2026
3920040
migrated bindings for ObjCrystAdapters, OverlapCalculator, PairQuanti…
SYMSCAE Jun 25, 2026
0066c2b
migrated bindings for PDFCalculators and PDFenvelope
SYMSCAE Jun 25, 2026
7f55adb
migrated bindings for PeakProfile, PeakWidthModel and ScatteringFacto…
SYMSCAE Jun 25, 2026
9fe4a79
migrated bindings for StructureAdapter and StructureDifference
SYMSCAE Jun 25, 2026
25c1e74
fix build
SYMSCAE Jun 25, 2026
ee7ef63
restore default constructors
SYMSCAE Jun 26, 2026
a56ab24
corrected code behaviors
SYMSCAE Jun 26, 2026
c4f74cd
restore PDFCalculator behavior
SYMSCAE Jun 26, 2026
334cfcd
reworked pickling system
SYMSCAE Jun 26, 2026
72deaae
fix tests
SYMSCAE Jun 26, 2026
711a416
ran docformatter
SYMSCAE Jul 7, 2026
8ef7657
cleanup boost imports
SYMSCAE Jul 8, 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
18 changes: 9 additions & 9 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ ci:
submodules: false
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
rev: v6.0.0
hooks:
- id: check-yaml
- id: end-of-file-fixer
Expand All @@ -21,31 +21,31 @@ repos:
- id: check-toml
- id: check-added-large-files
- repo: https://github.com/psf/black
rev: 24.4.2
rev: 26.3.1
hooks:
- id: black
- repo: https://github.com/pycqa/flake8
rev: 7.0.0
rev: 7.3.0
hooks:
- id: flake8
- repo: https://github.com/pycqa/isort
rev: 5.13.2
rev: 9.0.0a3
hooks:
- id: isort
args: ["--profile", "black"]
- repo: https://github.com/kynan/nbstripout
rev: 0.7.1
rev: 0.9.1
hooks:
- id: nbstripout
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v6.0.0
hooks:
- id: no-commit-to-branch
name: Prevent Commit to Main Branch
args: ["--branch", "main"]
stages: [pre-commit]
- repo: https://github.com/codespell-project/codespell
rev: v2.3.0
rev: v2.4.2
hooks:
- id: codespell
additional_dependencies:
Expand All @@ -58,8 +58,8 @@ repos:
additional_dependencies:
- "prettier@^3.2.4"
# docformatter - PEP 257 compliant docstring formatter
- repo: https://github.com/s-weigand/docformatter
rev: 5757c5190d95e5449f102ace83df92e7d3b06c6c
- repo: https://github.com/PyCQA/docformatter
rev: v1.7.8
hooks:
- id: docformatter
additional_dependencies: [tomli]
Expand Down
24 changes: 24 additions & 0 deletions news/cpp-version-update.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
**Added:**

* <news item>

**Changed:**

* updated cpp minimum version to c++23.
* replaced boost smart pointer usages with stl implementations.

**Deprecated:**

* <news item>

**Removed:**

* <news item>

**Fixed:**

* <news item>

**Security:**

* <news item>
23 changes: 23 additions & 0 deletions news/precommit-deps-update.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
**Added:**

* No news needed: updating pre-commit hooks, black, flake8, isort, nbstripout, codespell and docformatter. Not user facing.

**Changed:**

* <news item>

**Deprecated:**

* <news item>

**Removed:**

* <news item>

**Fixed:**

* <news item>

**Security:**

* <news item>
7 changes: 6 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
[build-system]
requires = ["setuptools>=62.0", "setuptools-git-versioning>=2.0", "numpy"]
requires = [
"setuptools>=62.0",
"setuptools-git-versioning>=2.0",
"numpy",
"nanobind",
]
build-backend = "setuptools.build_meta"

[project]
Expand Down
1 change: 1 addition & 0 deletions requirements/conda.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ libobjcryst
pyobjcryst
diffpy.structure
periodictable
nanobind
80 changes: 54 additions & 26 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,35 +9,27 @@
import glob
import os
import sys
from ctypes.util import find_library
from pathlib import Path

import numpy
from setuptools import Extension, setup
from setuptools.command.build_ext import build_ext


def get_boost_libraries():
major, minor = sys.version_info[:2]
candidates = [
f"boost_python{major}{minor}",
f"boost_python{major}",
"boost_python",
]
def get_nanobind_config():
import nanobind

package_dir = Path(nanobind.__file__).parent
return {
"include_dirs": [
nanobind.include_dir(),
str(package_dir / "ext" / "robin_map" / "include"),
],
"source": str(Path(nanobind.source_dir()) / "nb_combined.cpp"),
}

conda_prefix = os.environ.get("CONDA_PREFIX")
if conda_prefix:
libdir = os.path.join(conda_prefix, "lib")
for name in candidates:
so = f"lib{name}.so"
if os.path.isfile(os.path.join(libdir, so)):
return [name]

# fallback to ldconfig
for name in candidates:
found = find_library(name)
if found:
return [name]
raise RuntimeError("Cannot find a suitable Boost.Python library.")
nanobind_macros = [("NB_COMPACT_ASSERTIONS", None)]


def get_boost_config():
Expand Down Expand Up @@ -90,19 +82,21 @@ def get_objcryst_libraries():


if os.name == "nt":
compile_args = ["/std:c++14"]
compile_args = ["/std:c++23"]
nanobind_compile_args = ["/std:c++23"]
macros = [("_USE_MATH_DEFINES", None)]
extra_link_args = ["/FORCE:MULTIPLE"]
else:
compile_args = ["-std=c++11"]
compile_args = ["-std=c++23"]
nanobind_compile_args = ["-std=c++23", "-fno-strict-aliasing"]
macros = []
extra_link_args = []

boost_cfg = get_boost_config()
objcryst_libs = get_objcryst_libraries()

ext_kws = {
"libraries": ["diffpy"] + get_boost_libraries() + objcryst_libs,
"libraries": ["diffpy"] + objcryst_libs,
"extra_compile_args": compile_args,
"extra_link_args": extra_link_args,
"include_dirs": [numpy.get_include()] + boost_cfg["include_dirs"],
Expand All @@ -112,13 +106,44 @@ def get_objcryst_libraries():
}


class build_ext_with_nanobind(build_ext):
def build_extension(self, ext):
nanobind_source = getattr(ext, "nanobind_source", None)
if not nanobind_source:
super().build_extension(ext)
return

original_extra_objects = list(ext.extra_objects or [])
try:
nanobind_objects = self.compiler.compile(
[nanobind_source],
output_dir=self.build_temp,
macros=(ext.define_macros or []) + nanobind_macros,
include_dirs=ext.include_dirs,
debug=self.debug,
extra_postargs=nanobind_compile_args,
depends=ext.depends,
)
ext.extra_objects = original_extra_objects + nanobind_objects
super().build_extension(ext)
finally:
ext.extra_objects = original_extra_objects


def create_extensions():
"Initialize Extension objects for the setup function."
nanobind_cfg = get_nanobind_config()
ext = Extension(
"diffpy.srreal.srreal_ext",
glob.glob("src/extensions/*.cpp"),
**ext_kws,
**{
**ext_kws,
"include_dirs": (
ext_kws["include_dirs"] + nanobind_cfg["include_dirs"]
),
},
)
ext.nanobind_source = nanobind_cfg["source"]
return [ext]


Expand All @@ -130,4 +155,7 @@ def ext_modules():


if __name__ == "__main__":
setup(ext_modules=ext_modules())
setup(
cmdclass={"build_ext": build_ext_with_nanobind},
ext_modules=ext_modules(),
)
1 change: 0 additions & 1 deletion src/diffpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
##############################################################################
"""Blank namespace package for module diffpy."""


from pkgutil import extend_path

__path__ = extend_path(__path__, __name__)
Expand Down
1 change: 0 additions & 1 deletion src/diffpy/srreal/_cleanup.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ class prototypes is implemented in libdiffpy. Any Python-extended classes
a call of _registerThisType.
"""


import atexit
import weakref

Expand Down
13 changes: 6 additions & 7 deletions src/diffpy/srreal/_final_imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,16 @@
"""Finalize tweak of classes from the extension module srreal_ext.

This private module handles loading of Python-level tweaks of the
extension-defined classes. Any client that imports this module
must call the `import_now` function. If this module is not loaded
by the time of srreal_ext initialization, `import_now` is executed
from srreal_ext.
extension-defined classes. Any client that imports this module must
call the `import_now` function. If this module is not loaded by the
time of srreal_ext initialization, `import_now` is executed from
srreal_ext.

This avoids unresolvable import dependencies for any order of imports.
"""

_import_now_called = False


def import_now():
"""Import all Python modules that tweak extension-defined
Expand All @@ -46,6 +48,3 @@ def import_now():
import_module("diffpy.srreal.pdfcalculator")
import_module("diffpy.srreal.structureconverters")
return


_import_now_called = False
6 changes: 3 additions & 3 deletions src/diffpy/srreal/atomradiitable.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
##############################################################################
"""Class AtomRadiiTable -- storage of empirical atom radii."""


# exported items, these also makes them show in pydoc.
__all__ = ["AtomRadiiTable", "ConstantRadiiTable", "CovalentRadiiTable"]

Expand Down Expand Up @@ -66,8 +65,9 @@ def clone(self):
return copy.copy(self)

def type(self):
"""Unique string identifier of the CovalentRadiiTable type. This
is used for class registration and as an argument for the
"""Unique string identifier of the CovalentRadiiTable type.
This is used for class registration and as an argument for the
createByType function.
Return string.
Expand Down
2 changes: 1 addition & 1 deletion src/diffpy/srreal/attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#
##############################################################################
"""class Attributes -- wrapper to C++ class diffpy::Attributes
A base to PairQuantity and quite a few other classes.
A base to PairQuantity and quite a few other classes.
"""

__all__ = ["Attributes"]
Expand Down
Loading
Loading