Skip to content

Instantly share code, notes, and snippets.

@jtdub
Last active November 20, 2019 15:20
Show Gist options
  • Save jtdub/e1e8fba390030deeac3e107f06d63fb5 to your computer and use it in GitHub Desktop.
Save jtdub/e1e8fba390030deeac3e107f06d63fb5 to your computer and use it in GitHub Desktop.

jamess-mbp:tmp jtdub$ cat test/__init__.py

from os.path import dirname, basename, isfile, join
import glob
import importlib


modules = glob.glob(join(dirname(__file__), "*.py"))
__all__ = [ basename(f)[:-3] for f in modules if isfile(f) and not f.endswith('__init__.py')]

custom_modules = [ "test." + basename(f)[:-3] for f in modules if isfile(f) and not f.endswith('__init__.py')]
plugin_module = importlib.import_module(custom_modules[0])

jamess-mbp:tmp jtdub$ ls test

__init__.py	__pycache__	test1.py	test2.py
__init__.pyc	test0.pyc	test1.pyc	test2.pyc

jamess-mbp:tmp jtdub$ cat test.py

#!/usr/bin/env python3

import test

plugin = test.plugin_module
t = plugin.TestClass()
t.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment