Skip to content

Commit

Permalink
Adding console script (#23)
Browse files Browse the repository at this point in the history
* Adding console script to make it easy to run examples

* Adding docs on how to set up examples
  • Loading branch information
jsignell authored Apr 1, 2019
1 parent 76ca35e commit 7dfd9d6
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 0 deletions.
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,31 @@ or with pip:
pip install colorcet
```

Once installed you can copy the examples into the current directory using the colorcet command and run them using the Jupyter notebook:

```
colorcet examples
cd colorcet-examples
jupyter notebook
```

(Here colorcet examples is a shorthand for colorcet copy-examples --path colorcet-examples && colorcet fetch-data --path colorcet-examples.)

To work with JupyterLab you will also need the PyViz JupyterLab extension:

```
conda install -c conda-forge jupyterlab
jupyter labextension install @pyviz/jupyterlab_pyviz
```

Once you have installed JupyterLab and the extension launch it with:

```
jupyter-lab
```

If you want to try out the latest features between releases, you can get the latest dev release by specifying -c pyviz/label/dev in place of -c pyviz.

For more information take a look at [Getting Started](http://colorcet.pyviz.org/getting_started).

## Learning more
Expand Down
15 changes: 15 additions & 0 deletions colorcet/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,21 @@

__version__ = '1.0.0'

# make pyct's example/data commands available if possible
from functools import partial
try:
from pyct.cmd import copy_examples as _copy, fetch_data as _fetch, examples as _examples
copy_examples = partial(_copy, 'colorcet')
fetch_data = partial(_fetch, 'colorcet')
examples = partial(_examples, 'colorcet')
except ImportError:
def _missing_cmd(*args,**kw):
return("install pyct to enable this command (e.g. `conda install -c pyviz pyct`)")
_copy = _fetch = _examples = _missing_cmd
def _err(): raise ValueError(_missing_cmd())
fetch_data = copy_examples = examples = _err
del partial, _examples, _copy, _fetch

from collections import OrderedDict

class AttrODict(OrderedDict):
Expand Down
12 changes: 12 additions & 0 deletions colorcet/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
def main(args=None):
try:
import pyct.cmd
except ImportError:
import sys
from . import _missing_cmd
print(_missing_cmd())
sys.exit(1)
return pyct.cmd.substitute_main('colorcet',args=args)

if __name__ == "__main__":
main()
5 changes: 5 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ def get_setup_version(reponame):
python_requires=">=2.7",
install_requires=install_requires,
extras_require=extras_require,
entry_points={
'console_scripts': [
'colorcet = colorcet.__main__:main'
]
},
)


Expand Down

0 comments on commit 7dfd9d6

Please sign in to comment.