Skip to content

Commit

Permalink
Fix lazy import for docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Lilly-May committed Aug 30, 2024
1 parent ba09f89 commit e6f1498
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 18 deletions.
4 changes: 2 additions & 2 deletions docs/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@ Follow these steps to install pertpy on an Apple Silicon machine (tested on a Ma
brew install --cask mambaforge
```

3. Create a new environment using mamba (here with python 3.10) and activate it
3. Create a new environment using mamba and activate it

```console
mamba create -n pertpy-env python=3.11
mamba create -n pertpy-env
mamba activate pertpy-env
```

Expand Down
27 changes: 11 additions & 16 deletions pertpy/tools/__init__.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,20 @@
from functools import wraps
from importlib import import_module


def lazy_import(module_path, class_name, extras):
def _import():
try:
for extra in extras:
import_module(extra)
except ImportError as e:
raise ImportError(
f"Extra dependencies required: {', '.join(extras)}. "
f"Please install with: pip install {' '.join(extras)}"
) from e
try:
for extra in extras:
import_module(extra)
module = import_module(module_path)
return getattr(module, class_name)
except ImportError as e:
class Placeholder:
def __init__(self, *args, **kwargs):
raise ImportError(
f"Extra dependencies required: {', '.join(extras)}. "
f"Please install with: pip install {' '.join(extras)}"
) from e

@wraps(_import)
def wrapper(*args, **kwargs):
return _import()(*args, **kwargs)

return wrapper
return Placeholder


from pertpy.tools._augur import Augur
Expand Down

0 comments on commit e6f1498

Please sign in to comment.