github.com/apache/beam/sdks/v2@v2.48.2/python/apache_beam/utils/plugin.py (about) 1 # 2 # Licensed to the Apache Software Foundation (ASF) under one or more 3 # contributor license agreements. See the NOTICE file distributed with 4 # this work for additional information regarding copyright ownership. 5 # The ASF licenses this file to You under the Apache License, Version 2.0 6 # (the "License"); you may not use this file except in compliance with 7 # the License. You may obtain a copy of the License at 8 # 9 # http://www.apache.org/licenses/LICENSE-2.0 10 # 11 # Unless required by applicable law or agreed to in writing, software 12 # distributed under the License is distributed on an "AS IS" BASIS, 13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 # See the License for the specific language governing permissions and 15 # limitations under the License. 16 # 17 18 """A BeamPlugin base class.""" 19 20 # pytype: skip-file 21 22 23 class BeamPlugin(object): 24 """Plugin base class to be extended by dependent users such as FileSystem. 25 Any instantiated subclass will be imported at worker startup time.""" 26 @classmethod 27 def get_all_subclasses(cls): 28 """Get all the subclasses of the BeamPlugin class.""" 29 all_subclasses = [] 30 for subclass in cls.__subclasses__(): 31 all_subclasses.append(subclass) 32 all_subclasses.extend(subclass.get_all_subclasses()) 33 return all_subclasses 34 35 @classmethod 36 def get_all_plugin_paths(cls): 37 """Get full import paths of the BeamPlugin subclass.""" 38 def fullname(o): 39 return o.__module__ + "." + o.__name__ 40 41 return [fullname(o) for o in cls.get_all_subclasses()]