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