Skip to content
Open
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
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
61 changes: 57 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,23 @@

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


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"),
}


nanobind_macros = [("NB_COMPACT_ASSERTIONS", None)]


def get_boost_libraries():
Expand Down Expand Up @@ -90,11 +107,13 @@ 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 = []

Expand All @@ -112,13 +131,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 +180,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
7 changes: 2 additions & 5 deletions src/diffpy/srreal/bondcalculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
##############################################################################
"""Class BondCalculator -- distances between atoms in the structure."""


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

Expand All @@ -28,14 +27,12 @@

BondCalculator.rmin = propertyFromExtDoubleAttr(
"rmin",
"""Lower bound for the bond distances.
[0 A]""",
"Lower bound for the bond distances. [0 A]",
)

BondCalculator.rmax = propertyFromExtDoubleAttr(
"rmax",
"""Upper bound for the bond distances.
[5 A]""",
"Upper bound for the bond distances. [5 A]",
)


Expand Down
1 change: 0 additions & 1 deletion src/diffpy/srreal/bvparameterstable.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
"""Class BVParametersTable -- storage of bond valence parameters class BVParam
-- bond valence data associated with specific cation-anion pair."""


# exported items, these also makes them show in pydoc.
__all__ = ["BVParam", "BVParametersTable"]

Expand Down
27 changes: 14 additions & 13 deletions src/diffpy/srreal/bvscalculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
##############################################################################
"""Class BVSCalculator -- bond valence sums calculator."""


# exported items
__all__ = ["BVSCalculator"]

Expand All @@ -28,30 +27,32 @@

BVSCalculator.valenceprecision = propertyFromExtDoubleAttr(
"valenceprecision",
"""Cutoff value for valence contributions at long distances.
[1e-5]""",
"Cutoff value for valence contributions at long distances. [1e-5]",
)

BVSCalculator.rmaxused = propertyFromExtDoubleAttr(
"rmaxused",
"""Effective bound for bond lengths, where valence contributions
become smaller than valenceprecission, read-only. Always smaller or
equal to rmax. The value depends on ions present in the structure.
""",
(
"Effective bound for bond lengths, where valence contributions"
" become smaller than valenceprecission, read-only."
" Always smaller or equal to rmax."
" The value depends on ions present in the structure."
),
)

BVSCalculator.rmin = propertyFromExtDoubleAttr(
"rmin",
"""Lower bound for the summed bond lengths.
[0 A]""",
"Lower bound for the summed bond lengths. [0 A]",
)

BVSCalculator.rmax = propertyFromExtDoubleAttr(
"rmax",
"""Upper bound for the summed bond lengths. The calculation is
actually cut off much earlier when valence contributions get below
valenceprecission. See also rmaxused and valenceprecission.
[1e6 A]""",
(
"Upper bound for the summed bond lengths."
" The calculation is actually cut off much earlier when"
" valence contributions get below valenceprecission."
" See also rmaxused and valenceprecission. [1e6 A]"
),
)


Expand Down
1 change: 0 additions & 1 deletion src/diffpy/srreal/eventticker.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
"""Class EventTicker -- storage of modification times of dependent
objects."""


# exported items
__all__ = ["EventTicker"]

Expand Down
Loading
Loading