Skip to content

Commit ddc890e

Browse files
committed
tweaked main.py to work with entrypoints
1 parent 30a5449 commit ddc890e

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

piccolo/main.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import importlib
2+
import os
3+
import sys
24

35
import click
46

@@ -28,21 +30,24 @@ def migration():
2830

2931

3032
def main():
31-
cli()
32-
33+
# In case it's run from an entrypoint:
34+
sys.path.insert(0, os.getcwd())
3335

34-
if __name__ == "__main__":
3536
try:
3637
import piccolo_conf
3738
except ImportError:
3839
print("Can't import piccolo_conf - some commands may be missing.")
40+
else:
41+
COMMANDS = getattr(piccolo_conf, "COMMANDS", [])
3942

40-
COMMANDS = getattr(piccolo_conf, "COMMANDS", [])
43+
for command in COMMANDS:
44+
command_name = command.split(".")[-1]
45+
command_module = importlib.import_module(command)
46+
command_func = getattr(command_module, "command")
47+
cli.add_command(click.command(name=command_name)(command_func))
48+
49+
cli()
4150

42-
for command in COMMANDS:
43-
command_name = command.split(".")[-1]
44-
command_module = importlib.import_module(command)
45-
command_func = getattr(command_module, "command")
46-
cli.add_command(click.command(name=command_name)(command_func))
4751

52+
if __name__ == "__main__":
4853
main()

0 commit comments

Comments
 (0)