Skip to content

Commit

Permalink
Move dxtbx extensions from dxtbx.* to dxtbx.ext.*
Browse files Browse the repository at this point in the history
Keep them available from the old location, w/ added DeprecationWarnings

Fixes #29
  • Loading branch information
Anthchirp committed May 22, 2019
1 parent 19f630c commit 3d9bd91
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 9 deletions.
33 changes: 24 additions & 9 deletions __init__.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,33 @@
from __future__ import absolute_import, division, print_function

import logging
import warnings

try:
import boost.python
except Exception:
ext = None
else:
ext = boost.python.import_ext("dxtbx_ext", optional=True)
logging.getLogger("dxtbx").addHandler(logging.NullHandler())

if ext is not None:
from dxtbx_ext import *

logging.getLogger("dxtbx").addHandler(logging.NullHandler())
def _deprecate_function(name, func):
def _wrapper(*args, **kwargs):
warnings.warn(
"Addressing dxtbx extensions as dxtbx.{0} is deprecated. Instead use dxtbx.ext.{0}".format(
name
),
DeprecationWarning,
stacklevel=2,
)
return func(*args, **kwargs)

return _wrapper


try:
import dxtbx.ext as _ext

for funcname in dir(_ext):
if funcname != "ext" and not funcname.startswith("_"):
globals()[funcname] = _deprecate_function(funcname, getattr(_ext, funcname))
except ImportError:
_ext = None


class IncorrectFormatError(RuntimeError):
Expand Down
6 changes: 6 additions & 0 deletions ext.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from __future__ import absolute_import, division, print_function

import boost.python

ext = boost.python.import_ext("dxtbx_ext")
from dxtbx_ext import * # noqa: F401,F403

0 comments on commit 3d9bd91

Please sign in to comment.