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 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
19 changes: 15 additions & 4 deletions lira/parsers/rst.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import importlib
import logging

from docutils.frontend import OptionParser
Expand All @@ -7,6 +8,7 @@

from lira.parsers import BaseParser
from lira.parsers import nodes as booknodes
from lira.validators import Validator

logger = logging.getLogger(__name__)

Expand All @@ -26,9 +28,18 @@ class DirectiveNode(Element):
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)
try:
TargetClass = getattr(importlib.import_module(module_name), class_name, None)
if TargetClass is None or not issubclass(TargetClass, Validator):
raise ValueError
else:
Copy link
Member

Choose a reason for hiding this comment

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

This else can be removed

return value

except ImportError:

raise ValueError


class BaseDirective(Directive):
Expand Down Expand Up @@ -72,7 +83,7 @@ class TestBlockDirective(BaseDirective):

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

Expand Down