Skip to content
Merged
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
1 change: 0 additions & 1 deletion actions/generate_recipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@

RUN_DEPS = {
"gsl",
"lazy_import",
"libnetcdf",
"openmm",
"pandas",
Expand Down
6 changes: 0 additions & 6 deletions doc/source/acknowledgements.rst
Original file line number Diff line number Diff line change
Expand Up @@ -475,12 +475,6 @@ The header documentation reads;
imshow does not plot axis yet.
make a correct documentation

lazy_import
-----------

:mod:`sire` uses `lazy_import <https://github.com/mnmelo/lazy_import>`__ to
lazy load the modules. This is licensed under the GPLv3.

rich
----

Expand Down
5 changes: 5 additions & 0 deletions doc/source/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ organisation on `GitHub <https://github.com/openbiosim/sire>`__.

* Please add an item to this CHANGELOG for any new features or bug fixes when creating a PR.

* Replaced the third-party ``lazy_import`` dependency (GPLv3) with a minimal, standard-library-only
``importlib``-based implementation in ``sire.utils._lazy_import``. This also fixes a bug where
lazily-loaded modules could end up with two distinct class objects for the same module path
(e.g. via unpickling in a separate process), causing spurious ``isinstance()`` failures.

* Fixed ``sire.restraints.boresch()`` setting a dynamic ``_use_pbc`` Python attribute on
the returned ``BoreschRestraints`` instead of calling ``set_uses_pbc()``, which broke
pickling (e.g. for ``multiprocessing``/``ProcessPoolExecutor``) and meant the flag did
Expand Down
1 change: 0 additions & 1 deletion pixi.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ cmake = ">=3.30.0"
git = "*"
pybind11 = "*"
gsl = "*"
lazy_import = "*"
libboost-devel = "*"
libboost-python-devel = "*"
libcblas = "*"
Expand Down
2 changes: 1 addition & 1 deletion src/sire/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ add_subdirectory (vol)

install( FILES __init__.py _load.py _match.py
_parallel.py _pythonize.py
_measure.py _colname.py
_measure.py _colname.py _lazy_import.py
DESTINATION ${SIRE_PYTHON}/sire
)

Expand Down
113 changes: 67 additions & 46 deletions src/sire/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -803,56 +803,77 @@ def _convert(id):
__repository__ = config.sire_repository_url
__revisionid__ = config.sire_repository_version[0:7]

_can_lazy_import = False

if "SIRE_NO_LAZY_IMPORT" not in _os.environ:
try:
import lazy_import as _lazy_import
import logging as _logging

_logger = _logging.getLogger("lazy_import")
_logger.setLevel(_logging.ERROR)

# Previously needed to filter to remove excessive warnings
# from 'frozen importlib' when lazy loading.
# import warnings
# warnings.filterwarnings("ignore")

_can_lazy_import = True

except Exception as e:
print("Lazy import disabled")
print(e)
_can_lazy_import = False
from ._lazy_import import lazy_module as _lazy_module

_can_lazy_import = "SIRE_NO_LAZY_IMPORT" not in _os.environ

# Lazy import the modules for speed, and also to prevent pythonizing them
# if the users wants to run in legacy mode
# if the users wants to run in legacy mode.
#
# _lazy_module() doesn't execute anything regardless of call order - it
# just registers a stub - so the order here is cosmetic; kept alphabetical.
# See the eager fallback below for the one case where order does matter.
if _can_lazy_import:
analysis = _lazy_import.lazy_module("sire.analysis")
base = _lazy_import.lazy_module("sire.base")
cas = _lazy_import.lazy_module("sire.cas")
convert = _lazy_import.lazy_module("sire.convert")
cluster = _lazy_import.lazy_module("sire.cluster")
error = _lazy_import.lazy_module("sire.error")
ff = _lazy_import.lazy_module("sire.ff")
id = _lazy_import.lazy_module("sire.id")
io = _lazy_import.lazy_module("sire.io")
maths = _lazy_import.lazy_module("sire.maths")
mm = _lazy_import.lazy_module("sire.mm")
mol = _lazy_import.lazy_module("sire.mol")
morph = _lazy_import.lazy_module("sire.morph")
move = _lazy_import.lazy_module("sire.move")
options = _lazy_import.lazy_module("sire.options")
qm = _lazy_import.lazy_module("sire.qm")
qt = _lazy_import.lazy_module("sire.qt")
restraints = _lazy_import.lazy_module("sire.restraints")
search = _lazy_import.lazy_module("sire.search")
squire = _lazy_import.lazy_module("sire.squire")
stream = _lazy_import.lazy_module("sire.stream")
units = _lazy_import.lazy_module("sire.units")
utils = _lazy_import.lazy_module("sire.utils")
vol = _lazy_import.lazy_module("sire.vol")
analysis = _lazy_module("sire.analysis")
base = _lazy_module("sire.base")
cas = _lazy_module("sire.cas")
cluster = _lazy_module("sire.cluster")
convert = _lazy_module("sire.convert")
error = _lazy_module("sire.error")
ff = _lazy_module("sire.ff")
id = _lazy_module("sire.id")
io = _lazy_module("sire.io")
maths = _lazy_module("sire.maths")
mm = _lazy_module("sire.mm")
mol = _lazy_module("sire.mol")
morph = _lazy_module("sire.morph")
move = _lazy_module("sire.move")
options = _lazy_module("sire.options")
qm = _lazy_module("sire.qm")
qt = _lazy_module("sire.qt")
restraints = _lazy_module("sire.restraints")
search = _lazy_module("sire.search")
squire = _lazy_module("sire.squire")
stream = _lazy_module("sire.stream")
system = _lazy_module("sire.system")
units = _lazy_module("sire.units")
utils = _lazy_module("sire.utils")
vol = _lazy_module("sire.vol")
else:
# SIRE_NO_LAZY_IMPORT is set - import everything eagerly instead, so
# these are still bound as expected. Ordered to match
# _pythonize.py's _load_new_api_modules() (base first, then move, io,
# system, squire, mm, convert, ff, mol, analysis, cas, cluster, error,
# id, maths, morph, restraints, qt, stream, units, vol), with the
# modules pythonize doesn't force-load (options, qm, search, utils)
# appended at the end.
from . import (
base,
move,
io,
system,
squire,
mm,
convert,
ff,
mol,
analysis,
cas,
cluster,
error,
id,
maths,
morph,
restraints,
qt,
stream,
units,
vol,
options,
qm,
search,
utils,
)


def _version_string():
Expand Down
Loading
Loading