Commit 35f9fa40 authored by Laurent Bachelier's avatar Laurent Bachelier 🐧

boilerplate: Use __all__ if possible

parent d646c9c2
Pipeline #2043 passed with stages
in 16 minutes and 17 seconds
......@@ -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 @@ BOILERPLATE_PATH = os.getenv(
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()
......
......@@ -23,10 +23,13 @@ from __future__ import print_function
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 @@ class BaseRecipe(_Recipe):
self.write('test.py', self.template('base_test'))
class CapRecipe(_Recipe):
class CapRecipe(Recipe):
NAME = 'cap'
def __init__(self, args):
......@@ -116,7 +119,7 @@ class CapRecipe(_Recipe):
self.write('test.py', self.template('base_test'))
class ComicRecipe(_Recipe):
class ComicRecipe(Recipe):
NAME = 'comic'
def generate(self):
......@@ -124,7 +127,7 @@ class ComicRecipe(_Recipe):
self.write('module.py', self.template('comic_module'))
class ComicTestRecipe(_Recipe):
class ComicTestRecipe(Recipe):
NAME = 'comic.test'
@classmethod
......
#! /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)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment