Skip to content

Instantly share code, notes, and snippets.

@andgineer
Created April 5, 2024 04:21
Show Gist options
  • Save andgineer/5d09ed56852c9bcd36db4091476461e0 to your computer and use it in GitHub Desktop.
Save andgineer/5d09ed56852c9bcd36db4091476461e0 to your computer and use it in GitHub Desktop.
Register `invoke` tasks from all Python files in the directory.
import os
from invoke import Collection
import importlib
tasks_dir = os.path.dirname(os.path.abspath(__file__))
ns = Collection()
for filename in os.listdir(tasks_dir):
if filename.endswith(".py"):
module_name = os.path.splitext(filename)[0]
module = importlib.import_module(module_name)
ns.add_collection(Collection.from_module(module))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment