1# -*- coding: utf-8 -*-2# Copyright 2011 Takeshi KOMIYA3#4# Licensed under the Apache License, Version 2.0 (the "License");5# you may not use this file except in compliance with the License.6# You may obtain a copy of the License at7#8# http://www.apache.org/licenses/LICENSE-2.09#10# Unless required by applicable law or agreed to in writing, software11# distributed under the License is distributed on an "AS IS" BASIS,12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.13# See the License for the specific language governing permissions and14# limitations under the License.1516from __future__ import division1718from importlib import metadata1920renderers = {}21searchpath = []222324def init_renderers():25 for plugin in metadata.entry_points(group='blockdiag_noderenderer'):26 module = plugin.load()27 if hasattr(module, 'setup'):28 module.setup(module)293031def install_renderer(name, renderer):32 renderers[name] = renderer333435def set_default_namespace(path):36 searchpath[:] = []37 for path in path.split(','):38 searchpath.append(path)394041def get(shape):42 if not renderers:43 init_renderers()4445 for path in searchpath:46 name = "%s.%s" % (path, shape)47 if name in renderers:48 return renderers[name]4950 return renderers.get(shape)