Skip to content

Commit

Permalink
use proxied couchdb except in Panel
Browse files Browse the repository at this point in the history
  • Loading branch information
pepijndevos committed May 4, 2022
1 parent 0316d7e commit d842b41
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 9 deletions.
6 changes: 0 additions & 6 deletions pyttoresque/app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
from jupyter_server.extension.application import ExtensionApp, ExtensionAppJinjaMixin
from tornado.web import addslash
from traitlets import Bool
from subprocess import Popen
from shutil import which

HERE = os.path.dirname(__file__)

Expand Down Expand Up @@ -56,10 +54,6 @@ def initialize_handlers(self):

super().initialize_handlers()

binpath = which('couchdb')
if binpath and self.couchdb:
Popen([binpath, '-couch_ini', os.path.join(HERE, "static", "local.ini")])


def main():
Mosaic.launch_instance()
Expand Down
10 changes: 10 additions & 0 deletions pyttoresque/app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import re
import traceback
import urllib.parse as ulp
import panel as pn
import holoviews as hv
import numpy as np
Expand Down Expand Up @@ -42,6 +43,15 @@ def __init__(self, **params):
async def _update_spice(self, *events):
try:
url = self.database_url
# if we have a localhost couchdb proxied through Jupyter
# actually use localhost because Jupyter is authenticated
purl = ulp.urlparse(url)
if purl.hostname == "localhost" and purl.path.startswith("/couchdb"):
netloc = f"{purl.username}:{purl.password}@localhost:5984"
path = purl.path[8:]
url = purl._replace(path=path, netloc=netloc).geturl()
self.database_url = url

name = self.schematic
async with netlist.SchematicService(url) as service:
it = service.live_schem_docs(name)
Expand Down
5 changes: 4 additions & 1 deletion pyttoresque/app/templates/editor.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@
<div id="mosaic_editor"></div>
<script>
{% if couchdb %}
window.dburl = "http://admin:admin@localhost:5984"
var url = new URL("/couchdb/", window.location)
url.username = "admin"
url.password = "admin"
window.dburl = url.href
{% endif %}
window.notebookurl = "../../lab"
window.simulatorurl = "../../panel/app"
Expand Down
5 changes: 4 additions & 1 deletion pyttoresque/app/templates/libman.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@
<div id="mosaic_libman"></div>
<script>
{% if couchdb %}
window.dburl = "http://admin:admin@localhost:5984"
var url = new URL("/couchdb/", window.location)
url.username = "admin"
url.password = "admin"
window.dburl = url.href
{% endif %}
</script>
<script src="{{ static_url('common.js') }}"></script>
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
],
'jupyter_serverproxy_servers': [
# name = packagename:function_name
# 'couchdb = pyttoresque.app:setup_couchdb',
'couchdb = pyttoresque.app:setup_couchdb',
'panel = pyttoresque.app:setup_panel',
]
},
Expand Down

0 comments on commit d842b41

Please sign in to comment.