|
| 1 | +# Copyright 2026 AstroLab Software |
| 2 | +# Author: Julien Peloton |
| 3 | +# |
| 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 at |
| 7 | +# |
| 8 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +# |
| 10 | +# Unless required by applicable law or agreed to in writing, software |
| 11 | +# 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 and |
| 14 | +# limitations under the License. |
| 15 | +import fink_filters.rubin.blocks as fblocks |
| 16 | +import importlib |
| 17 | + |
| 18 | + |
| 19 | +def extract_blocks(with_description=False): |
| 20 | + """Extract user-defined blocks |
| 21 | +
|
| 22 | + Parameters |
| 23 | + ---------- |
| 24 | + with_description: bool |
| 25 | + If True, returns block names and descriptions. |
| 26 | + Otherwise, returns only block names. |
| 27 | +
|
| 28 | + Returns |
| 29 | + ------- |
| 30 | + block_names: list of str |
| 31 | + List of block names |
| 32 | + descriptions: list of str, optional |
| 33 | + Long descriptions for blocks |
| 34 | + """ |
| 35 | + # User-defined blocks |
| 36 | + block_names = [prop for prop in dir(fblocks) if prop.startswith("b_")] |
| 37 | + |
| 38 | + if with_description: |
| 39 | + module_name = importlib.import_module(fblocks.__name__) |
| 40 | + descriptions = [ |
| 41 | + getattr(module_name, block).__doc__.split("\n")[0] for block in block_names |
| 42 | + ] |
| 43 | + return block_names, descriptions |
| 44 | + |
| 45 | + return block_names |
0 commit comments