File: cext.py

package info (click to toggle)
python-ase 3.22.1-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 14,344 kB
  • sloc: python: 126,379; xml: 946; makefile: 111; javascript: 47
file content (23 lines) | stat: -rw-r--r-- 519 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
"""Use C-extensions from asecext.

This module defines a decorator that can be used to replace pure Python
functions with faster C-implementations from the ase_ext module.
"""

import functools

try:
    import ase_ext
except ImportError:
    ase_ext = None


def cextension(func):
    if ase_ext is None:
        return func
    cfunc = getattr(ase_ext, func.__name__, None)
    if cfunc is None:
        return func
    functools.update_wrapper(cfunc, func)
    cfunc.__pure_python_function__ = func
    return cfunc