示例#1
0
    def test_classes_by_shorthand(self):
        """Convert class paths into an ordered dict"""
        results = plugins.classes_by_shorthand(self._FORWARD)
        self.assertEqual(results['meta'], Meta)
        self.assertEqual(results['external-citations'], ExternalCitationParser)
        self.assertEqual(list(results)[0], 'meta')

        results = plugins.classes_by_shorthand(self._BACKWARD)
        self.assertEqual(list(results)[0], 'external-citations')
示例#2
0
def _init_classes():
    """Avoid leaking state variables by wrapping `LAYER_CLASSES` construction
    in a function"""
    classes = {doc_type: classes_by_shorthand(class_string_list)
               for doc_type, class_string_list in settings.LAYERS.items()}
    # Also add in the "ALL" layers
    for doc_type in classes:
        for layer_name, cls in classes['ALL'].items():
            classes[doc_type][layer_name] = cls
    return classes
import click
import logging

from regparser.commands import utils
from regparser.index import dependency, entry
from regparser.plugins import classes_by_shorthand
import settings


LAYER_CLASSES = {
    doc_type: classes_by_shorthand(class_string_list)
    for doc_type, class_string_list in settings.LAYERS.items()}
# Also add in the "ALL" layers
for doc_type in LAYER_CLASSES:
    for layer_name, cls in LAYER_CLASSES['ALL'].items():
        LAYER_CLASSES[doc_type][layer_name] = cls
logger = logging.getLogger(__name__)


def stale_layers(doc_entry, doc_type):
    """Return the name of layer dependencies which are now stale. Limit to a
    particular doc_type"""
    deps = dependency.Graph()
    layer_dir = entry.Layer(doc_type, *doc_entry.path)
    for layer_name in LAYER_CLASSES[doc_type]:
        # Layers depend on their associated tree
        deps.add(layer_dir / layer_name, doc_entry)
    if doc_type == 'cfr':
        # Meta layer also depends on the version info
        deps.add(layer_dir / 'meta', entry.Version(*doc_entry.path))
示例#4
0
import click
import logging

from regparser.commands import utils
from regparser.index import dependency, entry
from regparser.plugins import classes_by_shorthand
import settings

LAYER_CLASSES = {
    doc_type: classes_by_shorthand(class_string_list)
    for doc_type, class_string_list in settings.LAYERS.items()
}
# Also add in the "ALL" layers
for doc_type in LAYER_CLASSES:
    for layer_name, cls in LAYER_CLASSES['ALL'].items():
        LAYER_CLASSES[doc_type][layer_name] = cls
logger = logging.getLogger(__name__)


def stale_layers(doc_entry, doc_type):
    """Return the name of layer dependencies which are now stale. Limit to a
    particular doc_type"""
    deps = dependency.Graph()
    layer_dir = entry.Layer(doc_type, *doc_entry.path)
    for layer_name in LAYER_CLASSES[doc_type]:
        # Layers depend on their associated tree
        deps.add(layer_dir / layer_name, doc_entry)
    if doc_type == 'cfr':
        # Meta layer also depends on the version info
        deps.add(layer_dir / 'meta', entry.Version(*doc_entry.path))