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

Daniel sandbox #62

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
Open
Changes from 8 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
14 changes: 9 additions & 5 deletions lira/parsers/rst.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging
import importlib

from docutils.frontend import OptionParser
from docutils.nodes import Element
Expand All @@ -23,13 +24,16 @@ class DirectiveNode(Element):
- content
- options
"""

tagname = "directive"


def importable(value):
# TODO: check if value can be imported
return value
def is_importable(value):
module_name, class_name = value.rsplit(".",1)
MyClass = getattr(importlib.import_module(module_name), class_name, ValueError)
This conversation was marked as resolved.
Show resolved Hide resolved
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to try...except in case there is an import error.

if MyClass is ValueError:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to check for validator_class is not None and isinstance(validator_class, Validator)

raise ValueError
else:
return value


class BaseDirective(Directive):
Expand Down Expand Up @@ -73,7 +77,7 @@ class TestBlockDirective(BaseDirective):

option_spec = {
"help": str,
"validator": importable,
"validator": is_importable,
}
has_content = True

Expand Down