Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve the logic behind importing a module #335

Merged
merged 6 commits into from
Oct 6, 2022
Merged
Show file tree
Hide file tree
Changes from 4 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
21 changes: 11 additions & 10 deletions docs/how_to/validate.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,25 @@ This guide shows you how to validate the `YAML file` that specifies a Lumen dash
## Run the specification routine
Use the `lumen validate` command line tool to run the validation. Insert the path to your specification file in place of `<dashboard.yml>` below.

```console
```bash
lumen validate <dashboard.yaml>
```

## Debug an invalid specification file
When the validation fails, it will provide an error message indicating the type and location of the issue.

### Indendation errors
Indendation errors often show up as "`expected... but found...`"
### Indentation errors
Indentation errors often show up as "`expected... but found...`"

```console
```python-traceback
expected <block end>, but found '?'
in "<unicode string>", line 28, column 3:
facet:
^
```

They may also appear as messages about certain values not being allowed in this hierarchy level:
```console
```python-traceback
ERROR: mapping values are not allowed here
in "<unicode string>", line 6, column 11:
shared: true
Expand All @@ -37,7 +37,7 @@ ERROR: mapping values are not allowed here

For constrained key and value fields, invalid entries will get caught, and a recommendation may be provided:

```console
```python-traceback
View component specification declared unknown type 'hvplotqedq'. Did you mean 'hvplot or 'hvplot_ui'?

table: southern_rockies
Expand All @@ -55,12 +55,13 @@ View component specification declared unknown type 'hvplotqedq'. Did you mean 'h
### Package not installed
The validation will also catch the declaration of packages not installed. For example:

```console
Source component specification declared unknown type 'intake'.
```bash
ERROR: In order to use the source component 'intake', the 'intake' package must be installed. It can be installed with:
conda install intake
```

In this case, simply install the package into your enviornment, such as with:
In this case, simply follow the instruction and install the package into your environment, such as with:

```console
```bash
conda install intake
```
15 changes: 12 additions & 3 deletions lumen/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,10 +363,19 @@ def _get_type(cls, component_type, spec=None):
)
if '.' in component_type:
return resolve_module_reference(component_type, base_type)

try:
__import__(f'lumen.{base_type.__name__.lower()}s.{component_type}')
except Exception:
pass
import_name = f'lumen.{base_type.__name__.lower()}s.{component_type}'
__import__(import_name)
except ImportError as e:
if e.name != import_name:
msg = (
f"In order to use the {base_type.__name__.lower()} "
f"component '{component_type}', the '{e.name}' package "
"must be installed. It can be installed with:"
f"\n conda install {e.name}"
hoxbro marked this conversation as resolved.
Show resolved Hide resolved
)
raise ImportError(msg)

subcls_types = set()
for subcls in param.concrete_descendents(cls).values():
Expand Down