forked from projectmesa/mesa
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request projectmesa#522 from djmitche/use-click
Use click and add `mesa run`
- Loading branch information
Showing
19 changed files
with
89 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import sys | ||
import os | ||
import click | ||
|
||
PROJECT_PATH = click.Path(exists=True, file_okay=False, dir_okay=True, resolve_path=True) | ||
|
||
|
||
@click.group() | ||
def cli(): | ||
'Manage Mesa projects' | ||
|
||
|
||
@cli.command() | ||
@click.argument('project', type=PROJECT_PATH, default='.') | ||
def run(project): | ||
'''Run mesa project PROJECT | ||
PROJECT is the path to the directory containing `run.py`, or the current | ||
directory if not specified. | ||
''' | ||
sys.path.insert(0, project) | ||
os.chdir(project) | ||
|
||
with open("run.py") as f: | ||
code = compile(f.read(), "run.py", 'exec') | ||
exec(code, {}, {}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,5 +9,5 @@ tornado==4.5.3 | |
flake8==2.5.2 | ||
tqdm | ||
networkx==2.1 | ||
|
||
click==6.7 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import os | ||
import sys | ||
import unittest | ||
from unittest.mock import patch | ||
from click.testing import CliRunner | ||
|
||
from mesa.main import cli | ||
|
||
|
||
class TestCli(unittest.TestCase): | ||
''' | ||
Test CLI commands | ||
''' | ||
|
||
def setUp(self): | ||
self.old_sys_path = sys.path[:] | ||
self.runner = CliRunner() | ||
|
||
def tearDown(self): | ||
sys.path[:] = self.old_sys_path | ||
|
||
def test_run(self): | ||
with patch('mesa.visualization.ModularVisualization.ModularServer') as ModularServer: | ||
example_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), '../examples/wolf_sheep')) | ||
with self.runner.isolated_filesystem(): | ||
result = self.runner.invoke(cli, ['run', example_dir]) | ||
assert result.exit_code == 0, result.output | ||
assert ModularServer().launch.call_count == 1 |