diff --git a/tools/boilerplate/boilerplate.py b/tools/boilerplate/boilerplate.py index d11ca165374f379e7c420ec605dcdf67c7866665..3d556cccbeff4127dd123ab755f1f30eb1a2c521 100755 --- a/tools/boilerplate/boilerplate.py +++ b/tools/boilerplate/boilerplate.py @@ -21,12 +21,9 @@ from __future__ import print_function import argparse -import inspect -import subprocess import os +import subprocess import sys - - from importlib import import_module BOILERPLATE_PATH = os.getenv( @@ -36,6 +33,8 @@ sys.path.append(os.path.dirname(__file__)) sys.path.append(BOILERPLATE_PATH) +from recipe import Recipe # NOQA + def u8(s): if isinstance(s, bytes): @@ -59,9 +58,14 @@ def main(): recipes_module = import_module('recipes', package='boilerplate_data') - for k, v in recipes_module.__dict__.items(): - if inspect.isclass(v) and not k.startswith('_'): - v.configure_subparser(subparsers) + if hasattr(recipes_module, '__all__'): + for k in recipes_module.__all__: + getattr(recipes_module, k).configure_subparser(subparsers) + else: + for k in dir(recipes_module): + print(k) + if issubclass(getattr(recipes_module, k), Recipe) and not k.startswith('_'): + getattr(recipes_module, k).configure_subparser(subparsers) args = parser.parse_args() diff --git a/tools/boilerplate/boilerplate_data/recipes.py b/tools/boilerplate/boilerplate_data/recipes.py index a7ed0a2da976d4775369a19a7c4b93459cb551d2..81e70a6000457f31deff2d29b845efab124d4f74 100644 --- a/tools/boilerplate/boilerplate_data/recipes.py +++ b/tools/boilerplate/boilerplate_data/recipes.py @@ -23,10 +23,13 @@ import importlib import sys -from recipe import _Recipe +from recipe import Recipe -class BaseRecipe(_Recipe): +__all__ = ['BaseRecipe', 'CapRecipe', 'ComicRecipe', 'ComicTestRecipe'] + + +class BaseRecipe(Recipe): NAME = 'base' def generate(self): @@ -37,7 +40,7 @@ def generate(self): self.write('test.py', self.template('base_test')) -class CapRecipe(_Recipe): +class CapRecipe(Recipe): NAME = 'cap' def __init__(self, args): @@ -116,7 +119,7 @@ def generate(self): self.write('test.py', self.template('base_test')) -class ComicRecipe(_Recipe): +class ComicRecipe(Recipe): NAME = 'comic' def generate(self): @@ -124,7 +127,7 @@ def generate(self): self.write('module.py', self.template('comic_module')) -class ComicTestRecipe(_Recipe): +class ComicTestRecipe(Recipe): NAME = 'comic.test' @classmethod diff --git a/tools/boilerplate/recipe.py b/tools/boilerplate/recipe.py index 1d1939cc4df08313de17d198960f90bb366be0d2..9c1785b08ce9c09418bba93379d6459533062c2b 100644 --- a/tools/boilerplate/recipe.py +++ b/tools/boilerplate/recipe.py @@ -1,7 +1,7 @@ #! /usr/bin/env python # -*- coding: utf-8 -*- -# Copyright(C) 2013 Laurent Bachelier +# Copyright(C) 2013-2019 Laurent Bachelier, Sébastien Jean # # This file is part of weboob. # @@ -20,14 +20,15 @@ from __future__ import print_function -import os + +import codecs import datetime +import os import sys -import codecs from mako.lookup import TemplateLookup -from weboob import __version__ +from weboob import __version__ WEBOOB_MODULES = os.getenv( 'WEBOOB_MODULES', @@ -50,7 +51,7 @@ def write(target, contents): print('Created %s' % target) -class _Recipe(object): +class Recipe(object): @classmethod def configure_subparser(cls, subparsers): subparser = subparsers.add_parser(cls.NAME)