Skip to content

Commit 93beba1

Browse files
committed
added pgweb
1 parent aa06e85 commit 93beba1

File tree

4 files changed

+210
-1
lines changed

4 files changed

+210
-1
lines changed

pyproject.toml

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
[build-system]
2+
requires = ["hatchling"]
3+
build-backend = "hatchling.build"
4+
5+
[project]
6+
name = "jupyter-pgweb-proxy"
7+
version = "0.0.1"
8+
authors = [
9+
{ name="Matus Kosut", email="[email protected]" },
10+
{ name="Hans Stemshaug", email="[email protected]" },
11+
]
12+
description = "A small example package"
13+
readme = "README.md"
14+
license = { file = "LICENSE.md" }
15+
requires-python = ">=3.8"
16+
dependencies = [
17+
"jupyter-server-proxy>=3.2.2",
18+
]
19+
classifiers = [
20+
"Framework :: Jupyter",
21+
"Framework :: Jupyter :: JupyterLab",
22+
"Intended Audience :: Developers",
23+
"Natural Language :: English",
24+
"License :: OSI Approved :: MIT License",
25+
"Programming Language :: Python :: 3",
26+
"Programming Language :: Python :: 3.8",
27+
"Programming Language :: Python :: 3.9",
28+
"Programming Language :: Python :: 3.10",
29+
]
30+
keywords = [
31+
"Jupyter Proxy",
32+
"Jupyter Server Proxy",
33+
"JupyterLab",
34+
]
35+
36+
[project.urls]
37+
"Homepage" = "https://github.com/huntdatacenter/jupyter-pgweb-proxy"
38+
39+
[project.optional-dependencies]
40+
dev = ["black", "ruamel.yaml", "pytest", "pytest-cov"]
41+
42+
[project.entry-points.jupyter_serverproxy_servers]
43+
pgweb = "jupyter_pgweb_proxy:run_app"
44+
45+
46+
[tool.hatch.build.targets.wheel]
47+
packages = ["src/jupyter_pgweb_proxy"]
48+
49+
[tool.hatch.build]
50+
sources = ["src"]
51+
artifacts = [
52+
"*.svg",
53+
]
54+
55+
[tool.hatch.build.targets.sdist]
56+
artifacts = []
57+
exclude = [".github"]
58+
59+
[tool.hatch.build.targets.jupyter_pgweb_proxy]
Lines changed: 82 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,82 @@
1-
# keep
1+
import os
2+
import logging
3+
import shutil
4+
import pwd
5+
import getpass
6+
from jupyter_pgweb_proxy.jupyter_config import config
7+
8+
9+
def _get_env(port, base_url):
10+
"""
11+
Returns a dict containing environment settings to launch the Web App.
12+
Args:
13+
port (int): Port number on which the Web app will be started. Ex: 8888
14+
base_url (str): Controls the prefix in the url on which
15+
the Web App will be available.
16+
Ex: localhost:8888/base_url/index.html
17+
Returns:
18+
[Dict]: Containing environment settings to launch the Web application.
19+
"""
20+
21+
return {
22+
"PGWEB_RUN_PORT": str(port),
23+
"PGWEB_URL_PREFIX": f"{base_url}pgweb",
24+
}
25+
26+
27+
def get_icon_path():
28+
return os.path.join(
29+
os.path.dirname(os.path.abspath(__file__)), "pgweb.svg"
30+
)
31+
32+
33+
def _get_timeout(default=15):
34+
try:
35+
return float(os.getenv('RSESSION_TIMEOUT', default))
36+
except Exception:
37+
return default
38+
39+
40+
def get_system_user():
41+
try:
42+
user = pwd.getpwuid(os.getuid())[0]
43+
except Exception:
44+
user = os.getenv('USER', getpass.getuser())
45+
return user
46+
47+
48+
def run_app():
49+
"""
50+
Setup application.
51+
This method is run by jupyter-server-proxy package to launch the Web app.
52+
"""
53+
54+
logging.basicConfig(level="INFO")
55+
logger = logging.getLogger("pgweb")
56+
logger.setLevel("INFO")
57+
logger.info("Initializing Jupyter pgweb Proxy")
58+
59+
icon_path = get_icon_path()
60+
try:
61+
executable_name = shutil.which("pgweb")
62+
except Exception:
63+
executable_name = "pgweb"
64+
host = "127.0.0.1"
65+
user = get_system_user()
66+
logger.debug(f"[{user}] Icon_path: {icon_path}")
67+
logger.debug(f"[{user}] Launch Command: {executable_name}")
68+
return {
69+
"command": [
70+
executable_name,
71+
f"--host={host}",
72+
"--port={port}",
73+
],
74+
"timeout": 100,
75+
"environment": _get_env,
76+
"absolute_url": True,
77+
# "rewrite_response": rewrite_netloc,
78+
"launcher_entry": {
79+
"title": "pgweb",
80+
"icon_path": icon_path
81+
},
82+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
# Configure application proxy to extend for Jupyter
3+
config = {
4+
# Link the documentation url here. This will show up on the website UI
5+
# where users can create issue's or make enhancement requests
6+
"doc_url": "https://docs.hdc.ntnu.no/do-science/hunt-workbench/",
7+
}

src/jupyter_pgweb_proxy/pgweb.svg

Lines changed: 62 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)