Commit 0012fa2b authored by Yuxin Wu's avatar Yuxin Wu

Explicit import under 'if False' to trick jedi (#656)

parent 07c1807a
...@@ -2,6 +2,24 @@ ...@@ -2,6 +2,24 @@
# File: __init__.py # File: __init__.py
if False:
from .base import *
from .concurrency import *
from .graph import *
from .group import *
from .hooks import *
from .inference import *
from .inference_runner import *
from .monitor import *
from .param import *
from .prof import *
from .saver import *
from .stats import *
from .steps import *
from .summary import *
from .trigger import *
from pkgutil import iter_modules from pkgutil import iter_modules
import os import os
......
# -*- coding: UTF-8 -*- # -*- coding: UTF-8 -*-
# File: __init__.py # File: __init__.py
if False:
from .base import *
from .common import *
from .format import *
from .image import *
from .parallel_map import *
from .parallel import *
from .raw import *
from .remote import *
from . import imgaug
from . import dataset
from . import dftools
from pkgutil import iter_modules from pkgutil import iter_modules
import os import os
...@@ -33,8 +46,8 @@ for _, module_name, __ in iter_modules( ...@@ -33,8 +46,8 @@ for _, module_name, __ in iter_modules(
_global_import(module_name) _global_import(module_name)
dataset = LazyLoader('dataset', globals(), 'tensorpack.dataflow.dataset') globals()['dataset'] = LazyLoader('dataset', globals(), 'tensorpack.dataflow.dataset')
imgaug = LazyLoader('imgaug', globals(), 'tensorpack.dataflow.imgaug') globals()['imgaug'] = LazyLoader('imgaug', globals(), 'tensorpack.dataflow.imgaug')
del LazyLoader del LazyLoader
......
# -*- coding: UTF-8 -*- # -*- coding: UTF-8 -*-
# File: __init__.py # File: __init__.py
if False:
from .bsds500 import *
from .cifar import *
from .ilsvrc import *
from .mnist import *
from .svhn import *
from pkgutil import iter_modules from pkgutil import iter_modules
import os import os
......
# -*- coding: UTF-8 -*- # -*- coding: UTF-8 -*-
# File: __init__.py # File: __init__.py
if False:
from .base import *
from .convert import *
from .crop import *
from .deform import *
from .geometry import *
from .imgproc import *
from .meta import *
from .misc import *
from .noise import *
from .paste import *
from .transform import *
import os import os
from pkgutil import iter_modules from pkgutil import iter_modules
......
# -*- coding: UTF-8 -*- # -*- coding: UTF-8 -*-
# File: __init__.py # File: __init__.py
if False:
from .model_desc import *
from .training import *
from .distributed import *
from .predict import *
from .utils import *
from pkgutil import iter_modules from pkgutil import iter_modules
import os import os
...@@ -8,7 +14,6 @@ import os.path ...@@ -8,7 +14,6 @@ import os.path
__all__ = [] __all__ = []
def global_import(name): def global_import(name):
p = __import__(name, globals(), locals(), level=1) p = __import__(name, globals(), locals(), level=1)
lst = p.__all__ if '__all__' in dir(p) else [] lst = p.__all__ if '__all__' in dir(p) else []
......
# -*- coding: UTF-8 -*- # -*- coding: UTF-8 -*-
# File: __init__.py # File: __init__.py
if False:
from .input_source_base import *
from .input_source import *
from pkgutil import iter_modules from pkgutil import iter_modules
import os import os
......
# -*- coding: UTF-8 -*- # -*- coding: UTF-8 -*-
# File: __init__.py # File: __init__.py
if False:
from .batch_norm import *
from .common import *
from .conv2d import *
from .fc import *
from .image_sample import *
from .layer_norm import *
from .linearwrap import *
from .nonlin import *
from .pool import *
from .regularize import *
from pkgutil import iter_modules from pkgutil import iter_modules
import os import os
......
# -*- coding: UTF-8 -*- # -*- coding: UTF-8 -*-
# File: __init__.py # File: __init__.py
if False:
from .base import *
from .concurrency import *
from .config import *
from .dataset import *
from .multigpu import *
from pkgutil import iter_modules from pkgutil import iter_modules
import os import os
......
...@@ -2,10 +2,14 @@ ...@@ -2,10 +2,14 @@
# File: __init__.py # File: __init__.py
from pkgutil import iter_modules
import os
from .tower import get_current_tower_context, TowerContext from .tower import get_current_tower_context, TowerContext
if False:
from .common import *
from .sessinit import *
from .argscope import *
# don't want to include everything from .tower # don't want to include everything from .tower
__all__ = ['get_current_tower_context', 'TowerContext'] __all__ = ['get_current_tower_context', 'TowerContext']
...@@ -19,22 +23,19 @@ def _global_import(name): ...@@ -19,22 +23,19 @@ def _global_import(name):
__all__.append(k) __all__.append(k)
_TO_IMPORT = set([ _TO_IMPORT = frozenset([
'common', 'common',
'sessinit', 'sessinit',
'argscope', 'argscope',
]) ])
_CURR_DIR = os.path.dirname(__file__) for module_name in _TO_IMPORT:
for _, module_name, _ in iter_modules( _global_import(module_name)
[_CURR_DIR]): """
srcpath = os.path.join(_CURR_DIR, module_name + '.py') Here the goal is to keep submodule names (sesscreate, varmanip, etc) out of __all__,
if not os.path.isfile(srcpath): so that these names will be invisible under `tensorpack.` namespace.
continue
if module_name.startswith('_'): To use these utilities, users are expected to import them explicitly, e.g.:
continue
if module_name in _TO_IMPORT: import tensorpack.tfutils.symbolic_functions as symbf
_global_import(module_name) # import the content to tfutils.* """
__all__.extend(['sessinit', 'summary', 'optimizer',
'sesscreate', 'gradproc', 'varreplace', 'symbolic_functions',
'distributed', 'tower'])
# -*- coding: UTF-8 -*- # -*- coding: UTF-8 -*-
# File: __init__.py # File: __init__.py
if False:
from .base import *
from .config import *
from .interface import *
from .tower import *
from .trainers import *
from pkgutil import iter_modules from pkgutil import iter_modules
import os import os
......
...@@ -37,15 +37,5 @@ def get_rng(obj=None): ...@@ -37,15 +37,5 @@ def get_rng(obj=None):
"Please do `from tensorpack.utils.utils import get_rng`") "Please do `from tensorpack.utils.utils import get_rng`")
return gr(obj) return gr(obj)
# Import no submodules. they are supposed to be explicitly imported by users.
_CURR_DIR = os.path.dirname(__file__) __all__.extend(['logger', 'get_nr_gpu', 'change_gpu', 'get_rng'])
for _, module_name, _ in iter_modules(
[_CURR_DIR]):
srcpath = os.path.join(_CURR_DIR, module_name + '.py')
if not os.path.isfile(srcpath):
continue
if module_name.startswith('_'):
continue
__all__.extend([
'logger',
'get_nr_gpu', 'change_gpu', 'get_rng'])
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
max-line-length = 120 max-line-length = 120
ignore = E265,E741,E742,E743 ignore = E265,E741,E742,E743
exclude = .git, exclude = .git,
tensorpack/__init__.py, __init__.py,
setup.py, setup.py,
docs, docs,
examples, examples,
......
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