Skip to content
This repository has been archived by the owner on May 3, 2024. It is now read-only.

Commit

Permalink
Startup optimization. Adds top-level convenience methods for running …
Browse files Browse the repository at this point in the history
…the shell and server from within Python.
  • Loading branch information
sernst committed Aug 16, 2016
1 parent c1edddc commit 19f7d93
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 24 deletions.
1 change: 1 addition & 0 deletions bin/cauldron
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env python3

print('A', flush=True)
import os
import sys
from argparse import ArgumentParser
Expand Down
28 changes: 28 additions & 0 deletions cauldron/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,31 @@
project = session.project

shared = session.project.shared


def run_shell():
"""
Starts the cauldron shell environment for console based interaction
:return:
"""

from cauldron.cli.shell import CauldronShell
CauldronShell().cmdloop()


def run_server(port=5010, debug=False, **kwargs):
"""
Run the cauldron http server used to interact with cauldron from a remote
host
:param port:
The port on which to bind the cauldron server
:param debug:
Whether or not the server should be run in debug mode. If true, the
server will echo debugging information during operation.
:param kwargs:
:return:
"""

from cauldron.cli.server import run as run_server
run_server.execute(port, debug, **kwargs)
1 change: 1 addition & 0 deletions cauldron/cli/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from cauldron.cli import commander
from cauldron.cli import parse


with open(environ.paths.package('package_data.json'), 'r+') as f:
package_data = json.load(f)

Expand Down
14 changes: 14 additions & 0 deletions cauldron/environ/paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,17 @@ def user(*args: typing.List[str]) -> str:
"""

return clean(os.path.join('~', '.cauldron', *args))


def results(*args: typing.List[str]) -> str:
"""
Creates an absolute path from the specified relative components within the
user's Cauldron app data folder.
:param args:
Relative components of the path relative to the root package
:return:
The absolute path
"""

return user('results', *args)
35 changes: 18 additions & 17 deletions cauldron/render/plots.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,11 @@
import typing
import io
from bs4 import BeautifulSoup

from cauldron import templating

try:
from matplotlib import pyplot as mpl_pyplot
from matplotlib.pyplot import Figure
except Exception:
mpl_pyplot = None
Figure = None

try:
from bokeh import embed
from bokeh.model import Model
except Exception:
embed = None
Model = None


def pyplot(
figure: Figure = None,
figure=None,
scale: float = 0.8,
clear: bool = True,
aspect_ratio: typing.Union[list, tuple] = None
Expand All @@ -34,6 +19,13 @@ def pyplot(
:return:
"""

try:
from matplotlib import pyplot as mpl_pyplot
from matplotlib.pyplot import Figure
except Exception:
mpl_pyplot = None
Figure = None

if not figure:
figure = mpl_pyplot.gcf()

Expand Down Expand Up @@ -76,7 +68,7 @@ def pyplot(


def bokeh_plot(
model: Model,
model,
scale: float = 0.7,
responsive: bool = True
) -> str:
Expand All @@ -88,6 +80,15 @@ def bokeh_plot(
:return:
"""

from bs4 import BeautifulSoup

try:
from bokeh import embed
from bokeh.model import Model
except Exception:
embed = None
Model = None

if responsive:
model.sizing_mode = "scale_width"
# model.responsive = True
Expand Down
7 changes: 1 addition & 6 deletions cauldron/session/display/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@
from cauldron.render import texts as render_texts
from cauldron.render import plots as render_plots

try:
from matplotlib import pyplot as mpl_plot
except Exception:
mpl_plot = None


def _get_report() -> 'report.Report':
"""
Expand Down Expand Up @@ -244,7 +239,7 @@ def workspace(values: bool = True, types: bool = True):


def pyplot(
figure: 'mpl_plot.Figure' = None,
figure = None,
scale: float = 0.8,
clear: bool = True,
aspect_ratio: typing.Union[list, tuple] = None
Expand Down
2 changes: 1 addition & 1 deletion cauldron/session/projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ def results_path(self) -> str:
if p:
return p

return environ.paths.user('results')
return environ.paths.results()

@results_path.setter
def results_path(self, value: str):
Expand Down

0 comments on commit 19f7d93

Please sign in to comment.