forked from projectmesa/mesa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
60 lines (45 loc) · 1.43 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import os
import sys
from pathlib import Path
from subprocess import call
import click
from mesa import __version__
PROJECT_PATH = click.Path(
exists=True, file_okay=False, dir_okay=True, resolve_path=True
)
COOKIECUTTER_DIR = "mesa/cookiecutter-mesa"
SCRIPTS_DIR = os.path.dirname(os.path.abspath(__file__))
COOKIECUTTER_PATH = os.path.join(os.path.dirname(SCRIPTS_DIR), COOKIECUTTER_DIR)
CONTEXT_SETTINGS = {"help_option_names": ["-h", "--help"]}
@click.group(context_settings=CONTEXT_SETTINGS)
def cli():
"Manage Mesa projects"
@cli.command()
@click.argument("project", type=PROJECT_PATH, default=".")
def runserver(project):
"""Run mesa project PROJECT
PROJECT is the path to the directory containing `run.py`, or the current
directory if not specified.
"""
run_path = Path(project) / "run.py"
if not run_path.exists():
sys.exit(f"ERROR: file {run_path} does not exist")
args = [sys.executable, str(run_path)]
call(args)
@click.command()
@click.option(
"--no-input", is_flag=True, help="Do not prompt user for custom mesa model input."
)
def startproject(no_input):
"""Create a new mesa project"""
args = ["cookiecutter", COOKIECUTTER_PATH]
if no_input:
args.append("--no-input")
call(args)
@click.command()
def version():
"""Show the version of mesa"""
print(f"mesa {__version__}")
cli.add_command(runserver)
cli.add_command(startproject)
cli.add_command(version)