-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This commit adds a minimal but extendable command line interface to honeybee. I'm using click to create the `cli` which gives us a great level of flexibility and fits our needs for ladybug tools. Since the command line interface might not be needed for all the installations I added click to setup.py as an `extra_requires` for `cli`. One needs to use `pip install honeybee-core[cli]` or `pip install honeybee-core[all]` to install both honeybee core and the cli dependencies.
- Loading branch information
1 parent
d8df3b2
commit b8b521a
Showing
10 changed files
with
170 additions
and
40 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,6 @@ | ||
honeybee command line interface | ||
=============================== | ||
|
||
.. click:: honeybee.cli:main | ||
:prog: honeybee | ||
:show-nested: |
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,4 @@ | ||
from honeybee.cli import main | ||
|
||
if __name__ == '__main__': | ||
main() |
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,78 @@ | ||
""" | ||
Command Line Interface (CLI) entry point for honeybee and honeybee extensions. | ||
Use this file only to add command related to honeybee-core. For adding extra commands | ||
from each extention see below. | ||
Honeybee is using click (https://click.palletsprojects.com/en/7.x/) for creating the CLI. | ||
You can extend the command line interface from inside each extention by following these | ||
steps: | ||
1. Create a ``cli.py`` file in your extension. | ||
2. Import the ``main`` function from this ``honeybee.cli``. | ||
3. Add your commands and command groups to main using add_command method. | ||
4. Add ``import [your-extention].cli`` to ``__init__.py`` file to the commands are added | ||
to the cli when the module is loaded. | ||
The good practice is to group all your extention commands in a command group named after | ||
the extension. This will make the commands organized under extension namespace. For | ||
instance commands for `honeybee-radiance` will be called like ``honeybee radiance [radiance-command]``. | ||
.. code-block:: python | ||
import click | ||
from honeybee.cli import main | ||
@click.group() | ||
def radiance(): | ||
pass | ||
# add commands to radiance group | ||
@radiance.command('daylight-factor') | ||
# ... | ||
def daylight_factor(): | ||
pass | ||
# finally add the newly created commands to honeybee cli | ||
main.add_command(radiance) | ||
# do not forget to import this module in __init__.py otherwise it will not be added | ||
# to honeybee commands. | ||
Note: | ||
For extension with several commands you can use a folder structure instead of a single | ||
file. Refer to ``honeybee-radiance`` for an example. | ||
""" | ||
|
||
try: | ||
import click | ||
except ImportError: | ||
raise ImportError( | ||
'click module is not installed. Try `pip install honeybee-core[cli]` command.' | ||
) | ||
import importlib | ||
import sys | ||
import logging | ||
import honeybee | ||
|
||
# use this logger for logging inside this file and all the extensions | ||
_logger = logging.getLogger(__name__) | ||
|
||
@click.group() | ||
@click.version_option() | ||
def main(): | ||
pass | ||
|
||
|
||
@main.command('viz') | ||
def viz(): | ||
"""Check if honeybee is flying!""" | ||
click.echo('viiiiiiiiiiiiizzzzzzzzz!') | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
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