Skip to content

Commit a4b2a65

Browse files
committed
📖 Command-line options support using docopt.
1 parent 9b95972 commit a4b2a65

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

pytrain/__main__.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,25 @@
11
# PyTrain — Copyright (c) 2019, Alex J. Champandard.
2+
"""
3+
Usage: pytrain [-k FILTER] [-r ROOTDIR]
4+
5+
Options:
6+
-k FILTER Select which tests to run by matching this substring filter.
7+
-r ROOTDIR Base directory from which to collect all the tasks.
8+
"""
29

310
import asyncio
411

12+
from docopt import docopt
13+
14+
from . import __version__
515
from .application import Application
616
from .registry import Registry
717

818

919
def main():
10-
registry = Registry()
20+
config = docopt(__doc__, version=f"pytrain {__version__}")
21+
22+
registry = Registry(config)
1123
registry.load()
1224

1325
loop = asyncio.get_event_loop()

pytrain/registry.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,19 @@ def config(self, key, default):
1616

1717

1818
class Registry:
19-
def __init__(self):
19+
def __init__(self, config):
2020
self.functions = []
2121
self.modules = []
2222

23+
self.config = config
24+
2325
def load(self):
24-
for root, _, files in os.walk("examples"):
26+
for root, _, files in os.walk(self.config.get("-r") or "train"):
2527
if root.endswith("__pycache__"):
2628
continue
2729

2830
for filename in files:
29-
if not filename.startswith("train_"):
31+
if not filename.startswith(self.config.get("-k") or "train_"):
3032
continue
3133

3234
basename = os.path.splitext(filename)[0]

0 commit comments

Comments
 (0)