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

Commit

Permalink
Merge pull request #30 from sernst/project-opening
Browse files Browse the repository at this point in the history
Project Opening
  • Loading branch information
sernst committed Jun 11, 2018
2 parents b6cc8ef + 12ba3c7 commit 66955fd
Show file tree
Hide file tree
Showing 64 changed files with 583 additions and 423 deletions.
1 change: 1 addition & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ omit =
/conda-recipe/*.py
/docker-builder.py
/launcher.py
*.py.txt
12 changes: 4 additions & 8 deletions cauldron/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,30 +22,28 @@

def get_environment_info() -> dict:
"""
Information about Cauldron and its Python interpreter
Information about Cauldron and its Python interpreter.
:return:
A dictionary containing information about the Cauldron and its
Python environment. This information is useful when providing feedback
and bug reports
and bug reports.
"""

data = _environ.systems.get_system_data()
data['cauldron'] = _environ.package_settings.copy()
return data


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

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
host.
:param port:
The port on which to bind the cauldron server.
Expand All @@ -55,7 +53,6 @@ def run_server(port=5010, debug=False, **kwargs):
:param kwargs:
Custom properties to alter the way the server runs.
"""

from cauldron.cli.server import run
run.execute(port=port, debug=debug, **kwargs)

Expand Down Expand Up @@ -92,9 +89,8 @@ def run_project(
Any variables to be available in the cauldron.shared object during
execution of the project can be specified here as keyword arguments.
:return:
A response object that contains information about the run process
A response object that contains information about the run process.
"""

from cauldron.cli import batcher
return batcher.run_project(
project_directory=project_directory,
Expand Down
2 changes: 1 addition & 1 deletion cauldron/cli/batcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def on_complete(message: str = None) -> environ.Response:
if response.failed:
return on_complete('[ERROR]: Aborted trying to open project')

project = cauldron.project.internal_project
project = cauldron.project.get_internal_project()
project.shared.put(**(shared_data if shared_data is not None else dict()))

commander.preload()
Expand Down
3 changes: 2 additions & 1 deletion cauldron/cli/commands/open/opener.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import time

import cauldron
from cauldron import environ
Expand Down Expand Up @@ -150,7 +151,7 @@ def open_project(
message='Unable to update loaded project status'
).console(whitespace=1).response

project = cauldron.project.internal_project
project = cauldron.project.get_internal_project()
if results_path:
project.results_path = results_path

Expand Down
3 changes: 1 addition & 2 deletions cauldron/cli/server/routes/display.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@

@server_run.APPLICATION.route('/view/<path:route>', methods=['GET', 'POST'])
def view(route: str):

project = cauldron.project.internal_project
project = cauldron.project.get_internal_project()
results_path = project.results_path if project else None
if not project or not results_path:
return '', 204
Expand Down
2 changes: 1 addition & 1 deletion cauldron/cli/server/routes/execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ def abort():
except Exception:
pass

project = cd.project.internal_project
project = cd.project.get_internal_project()

if project and project.current_step:
step = project.current_step
Expand Down
15 changes: 5 additions & 10 deletions cauldron/cli/server/routes/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,11 @@ def server_status():
@server_runner.APPLICATION.route('/status', methods=['GET', 'POST'])
@authorization.gatekeeper
def project_status():
"""
:return:
"""

"""..."""
r = Response()

try:
project = cauldron.project.internal_project
project = cauldron.project.get_internal_project()
if project:
r.update(project=project.status())
else:
Expand All @@ -55,10 +51,9 @@ def project_status():
)
@authorization.gatekeeper
def clean_step(step_name: str):
""" """

"""..."""
r = Response()
project = cauldron.project.internal_project
project = cauldron.project.get_internal_project()

if not project:
return flask.jsonify(r.fail(
Expand Down Expand Up @@ -92,7 +87,7 @@ def project_data():
r = Response()

try:
project = cauldron.project.internal_project
project = cauldron.project.get_internal_project()
if project:
r.update(project=project.kernel_serialize())
else:
Expand Down
18 changes: 8 additions & 10 deletions cauldron/cli/server/routes/synchronize/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,10 @@
@authorization.gatekeeper
def touch_project():
"""
Touches the project to trigger refreshing its cauldron.json state
Touches the project to trigger refreshing its cauldron.json state.
"""

r = Response()
project = cd.project.internal_project
project = cd.project.get_internal_project()

if project:
project.refresh()
Expand All @@ -53,9 +52,8 @@ def fetch_synchronize_status():
Returns the synchronization status information for the currently opened
project
"""

r = Response()
project = cd.project.internal_project
project = cd.project.get_internal_project()

if not project:
r.fail(
Expand Down Expand Up @@ -117,7 +115,7 @@ def sync_open_project():

open_response = project_opener.open_project(project_folder, forget=True)
open_response.join()
project = cd.project.internal_project
project = cd.project.get_internal_project()
project.remote_source_directory = source_directory

sync_status.update({}, time=-1, project=project)
Expand Down Expand Up @@ -152,7 +150,7 @@ def sync_source_file():
message='Missing or invalid arguments'
).response.flask_serialize()

project = cd.project.internal_project
project = cd.project.get_internal_project()

if not project:
return r.fail(
Expand Down Expand Up @@ -201,7 +199,7 @@ def sync_source_file():
def download_file(filename: str):
""" downloads the specified project file if it exists """

project = cd.project.internal_project
project = cd.project.get_internal_project()
source_directory = project.source_directory if project else None

if not filename or not project or not source_directory:
Expand All @@ -228,7 +226,7 @@ def download_file(filename: str):
def download_project_file(filename: str):
""" downloads the specified project file if it exists """

project = cd.project.internal_project
project = cd.project.get_internal_project()
source_directory = project.source_directory if project else None

if not filename or not project or not source_directory:
Expand Down Expand Up @@ -279,7 +277,7 @@ def sync_create_project():

sync_status.update({}, time=-1, project=None)

project = cd.project.internal_project
project = cd.project.get_internal_project()
project.remote_source_directory = remote_source_directory

with open(project.source_path, 'r') as f:
Expand Down
8 changes: 2 additions & 6 deletions cauldron/cli/server/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,8 @@ def get_server_data() -> dict:


def get_running_step_changes(write: bool = False) -> list:
"""
:return:
"""

project = cd.project.internal_project
"""..."""
project = cd.project.get_internal_project()

running_steps = list(filter(
lambda step: step.is_running,
Expand Down
80 changes: 40 additions & 40 deletions cauldron/environ/logger.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import threading
import sys
import os
import typing
import sys
import threading
import traceback
import typing
from textwrap import dedent
from textwrap import indent

Expand All @@ -11,28 +11,36 @@
_logging_paths = []


def add_output_path(path: str) -> str:
if not path:
path = paths.clean(os.getcwd())
else:
path = paths.clean(path)

if path not in _logging_paths:
_logging_paths.append(path)
def add_output_path(path: str = None) -> str:
"""
Adds the specified path to the output logging paths if it is not
already in the listed paths.
return path
:param path:
The path to add to the logging output paths. If the path is empty
or no path is given, the current working directory will be used
instead.
"""
cleaned = paths.clean(path or os.getcwd())
if cleaned not in _logging_paths:
_logging_paths.append(cleaned)
return cleaned


def remove_output_path(path: str) -> str:
if not path:
path = paths.clean(os.getcwd())
else:
path = paths.clean(path)
def remove_output_path(path: str = None) -> str:
"""
Removes the specified path from the output logging paths if it is
in the listed paths.
if path in _logging_paths:
:param path:
The path to remove from the logging output paths. If the path is empty
or no path is given, the current working directory will be used
instead.
"""
cleaned = paths.clean(path or os.getcwd())
if cleaned in _logging_paths:
_logging_paths.remove(path)

return path
return cleaned


def header(
Expand All @@ -59,7 +67,6 @@ def header(
:param indent_by:
:return:
"""

if level == 0:
message = text
elif level < 3:
Expand Down Expand Up @@ -159,7 +166,6 @@ def log(
log file specified in the file_path argument
:param kwargs:
"""

m = add_to_message(message)
for key, value in kwargs.items():
m.append('{key}: {value}'.format(key=key, value=value))
Expand Down Expand Up @@ -208,38 +214,30 @@ def raw(
threading.current_thread().logs.append(message)

def write_file(write_path: str):
mode = 'a' if append_to_file else 'w'
try:
with open(paths.clean(write_path), mode) as f:
f.write('{}\n'.format(message))
except FileNotFoundError:
return write_path

return None
mode = 'a' if append_to_file and os.path.exists(write_path) else 'w'
with open(paths.clean(write_path), mode) as f:
f.write('{}\n'.format(message))

file_paths = list(set([p for p in (_logging_paths + [file_path]) if p]))
for path in file_paths:
write_file(path)


def add_to_message(data, indent_level=0) -> list:
""" Adds data to the message object """

m = []
"""Adds data to the message object"""
message = []

if isinstance(data, str):
m.append(indent(
message.append(indent(
dedent(data.strip('\n')).strip(),
indent_level * ' '
))
return m
return message

for line in data:
if isinstance(line, str):
m += add_to_message(line, indent_level)
else:
m += add_to_message(line, indent_level + 1)
return m
offset = 0 if isinstance(line, str) else 1
message += add_to_message(line, indent_level + offset)
return message


def get_error_stack() -> typing.List[dict]:
Expand All @@ -252,6 +250,8 @@ def get_error_stack() -> typing.List[dict]:

if location == '<module>':
location = None
elif location:
location = location.split('__cauldron_shared_libs')[-1]

stack.append(dict(
filename=filename,
Expand Down
1 change: 1 addition & 0 deletions cauldron/render/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ def plotly(
return templating.render_template(
'plotly-component.html',
dom=dom,
scale=scale,
min_height=round(100.0 * scale),
id=dom_id
)
Expand Down
7 changes: 1 addition & 6 deletions cauldron/render/texts.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,7 @@ def text(value: str) -> str:


def preformatted_text(source: str) -> str:
"""
:param source:
:return:
"""

"""Renders preformatted text box"""
environ.abort_thread()

if not source:
Expand Down

0 comments on commit 66955fd

Please sign in to comment.