Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Align path format for windows. #243

Merged
merged 17 commits into from
Nov 9, 2022
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion plugins/auth/fps_auth/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

auth_config = get_config(AuthConfig)

jupyter_dir = Path.home() / ".local" / "share" / "jupyter"
jupyter_dir = Path.home() / ".local/share/jupyter"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the hard-coded / going to play well on Windows?

Copy link
Contributor Author

@specter119 specter119 Nov 9, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, hard-code /, works as excepted.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From what I can read, I think it works because Python does some tricks to convert forward slashes to backslashes if needed when opening files, but the best practice is still to use pathlib's / operator.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

revert these changes.

jupyter_dir.mkdir(parents=True, exist_ok=True)
name = "jupyverse"
if auth_config.test:
Expand Down
3 changes: 2 additions & 1 deletion plugins/auth/fps_auth/fixtures.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from uuid import uuid4

import pytest # type: ignore
from fps_auth.config import AuthConfig, get_auth_config

from .config import AuthConfig, get_auth_config


@pytest.fixture
Expand Down
2 changes: 1 addition & 1 deletion plugins/contents/fps_contents/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ async def read_content(path: Union[str, Path], get_content: bool, as_json: bool
return Content(
**{
"name": path.name,
"path": str(path),
"path": path.as_posix(),
"last_modified": get_file_modification_time(path),
"created": get_file_creation_time(path),
"content": content,
Expand Down
30 changes: 21 additions & 9 deletions plugins/jupyterlab/fps_jupyterlab/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@

router = APIRouter()
prefix_dir, federated_extensions = init_router(router, "lab")
jupyterlab_dir = Path(jupyterlab.__file__).parent.parent
jupyterlab_dir = Path(jupyterlab.__file__).parents[1]

config = get_jlab_config()
if config.dev_mode:
static_lab_dir = jupyterlab_dir / "dev_mode" / "static"
static_lab_dir = jupyterlab_dir / "dev_mode/static"
else:
static_lab_dir = prefix_dir / "share" / "jupyter" / "lab" / "static"
static_lab_dir = prefix_dir / "share/jupyter/lab/static"

router.mount(
"/static/lab",
Expand All @@ -40,16 +40,28 @@ async def get_lab(
lab_config=Depends(get_lab_config),
):
return HTMLResponse(
get_index("default", lab_config.collaborative, config.dev_mode, frontend_config.base_url)
get_index(
"default",
lab_config.collaborative,
config.dev_mode,
frontend_config.base_url,
)
)


@router.get("/lab/tree/{path:path}")
async def load_workspace(
path, frontend_config=Depends(get_frontend_config), lab_config=Depends(get_lab_config)
path,
frontend_config=Depends(get_frontend_config),
lab_config=Depends(get_lab_config),
):
return HTMLResponse(
get_index("default", lab_config.collaborative, config.dev_mode, frontend_config.base_url)
get_index(
"default",
lab_config.collaborative,
config.dev_mode,
frontend_config.base_url,
)
)


Expand Down Expand Up @@ -127,7 +139,7 @@ def get_index(workspace, collaborative, dev_mode, base_url="/"):
vendor_id = path.name.split(".")[1]
break
full_static_url = f"{base_url}static/lab"
extensions_dir = prefix_dir / "share" / "jupyter" / "labextensions"
extensions_dir = prefix_dir / "share/jupyter/labextensions"
federated_extensions, disabled_extension = get_federated_extensions(extensions_dir)

page_config = {
Expand Down Expand Up @@ -164,9 +176,9 @@ def get_index(workspace, collaborative, dev_mode, base_url="/"):
"quitButton": True,
"settingsUrl": "/lab/api/settings",
"store_id": 0,
"schemasDir": str(prefix_dir / "share" / "jupyter" / "lab" / "schemas"),
"schemasDir": (prefix_dir / "share/jupyter/lab/schemas").as_posix(),
"terminalsAvailable": True,
"themesDir": str(prefix_dir / "share" / "jupyter" / "lab" / "themes"),
"themesDir": (prefix_dir / "share/jupyter/lab/themes").as_posix(),
"themesUrl": "/lab/api/themes",
"token": "4e2804532de366abc81e32ab0c6bf68a73716fafbdbb2098",
"translationsApiUrl": "/lab/api/translations",
Expand Down
2 changes: 1 addition & 1 deletion plugins/kernels/fps_kernels/kernel_driver/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ async def connect(self, startup_timeout: float = float("inf")) -> None:
await self._wait_for_ready(startup_timeout)
self.listen_channels()

def connect_channels(self, connection_cfg: cfg_t = None):
def connect_channels(self, connection_cfg: Optional[cfg_t] = None):
connection_cfg = connection_cfg or self.connection_cfg
self.shell_channel = connect_channel("shell", connection_cfg)
self.control_channel = connect_channel("control", connection_cfg)
Expand Down
18 changes: 11 additions & 7 deletions plugins/kernels/fps_kernels/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ async def get_kernelspecs(
frontend_config=Depends(get_frontend_config),
user: User = Depends(current_user(permissions={"kernelspecs": ["read"]})),
):
for path in (prefix_dir / "share" / "jupyter" / "kernels").glob("*/kernel.json"):
for path in (prefix_dir / "share/jupyter/kernels").glob("*/kernel.json"):
with open(path) as f:
spec = json.load(f)
name = path.parent.name
Expand All @@ -57,11 +57,13 @@ async def get_kernelspec(
file_name,
user: User = Depends(current_user()),
):
return FileResponse(prefix_dir / "share" / "jupyter" / "kernels" / kernel_name / file_name)
return FileResponse(prefix_dir / f"share/jupyter/kernels/{kernel_name}/{file_name}")


@router.get("/api/kernels")
async def get_kernels(user: User = Depends(current_user(permissions={"kernels": ["read"]}))):
async def get_kernels(
user: User = Depends(current_user(permissions={"kernels": ["read"]})),
):
results = []
for kernel_id, kernel in kernels.items():
results.append(
Expand Down Expand Up @@ -102,7 +104,9 @@ async def rename_session(


@router.get("/api/sessions")
async def get_sessions(user: User = Depends(current_user(permissions={"sessions": ["read"]}))):
async def get_sessions(
user: User = Depends(current_user(permissions={"sessions": ["read"]})),
):
for session in sessions.values():
kernel_id = session["kernel"]["id"]
kernel_server = kernels[kernel_id]["server"]
Expand All @@ -123,9 +127,9 @@ async def create_session(
create_session = await request.json()
kernel_name = create_session["kernel"]["name"]
kernel_server = KernelServer(
kernelspec_path=str(
prefix_dir / "share" / "jupyter" / "kernels" / kernel_name / "kernel.json"
),
kernelspec_path=(
prefix_dir / f"share/jupyter/kernels/{kernel_name}/kernel.json"
).as_posix(),
davidbrochart marked this conversation as resolved.
Show resolved Hide resolved
)
kernel_id = str(uuid.uuid4())
kernels[kernel_id] = {"name": kernel_name, "server": kernel_server, "driver": None}
Expand Down
16 changes: 8 additions & 8 deletions plugins/lab/fps_lab/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@

prefix_dir = Path(sys.prefix)
if jlab_dev_mode:
jlab_dir = Path(jupyterlab.__file__).parent.parent / "dev_mode"
jlab_dir = Path(jupyterlab.__file__).parents[1] / "dev_mode"
else:
jlab_dir = prefix_dir / "share" / "jupyter" / "lab"
jlab_dir = prefix_dir / "share/jupyter/lab"


def init_router(router, redirect_after_root):
extensions_dir = prefix_dir / "share" / "jupyter" / "labextensions"
extensions_dir = prefix_dir / "share/jupyter/labextensions"
federated_extensions, _ = get_federated_extensions(extensions_dir)

for ext in federated_extensions:
Expand Down Expand Up @@ -66,7 +66,7 @@ async def get_root(

@router.get("/favicon.ico")
async def get_favicon():
return FileResponse(Path(jupyverse.__file__).parent / "static" / "favicon.ico")
return FileResponse(Path(jupyverse.__file__).parent / "static/favicon.ico")

@router.get("/static/notebook/components/MathJax/{rest_of_path:path}")
async def get_mathjax(rest_of_path):
Expand Down Expand Up @@ -124,7 +124,7 @@ async def get_translation(
LOCALE = language
package = ep.load()
data = {}
for path in (Path(package.__file__).parent / "locale" / language / "LC_MESSAGES").glob(
for path in (Path(package.__file__).parent / f"locale/{language}/LC_MESSAGES").glob(
"*.json"
):
with open(path) as f:
Expand All @@ -138,7 +138,7 @@ async def get_setting(
name2,
user: User = Depends(current_user()),
):
with open(jlab_dir / "static" / "package.json") as f:
with open(jlab_dir / "static/package.json") as f:
package = json.load(f)
if name0 in ["@jupyterlab", "@retrolab"]:
schemas_parent = jlab_dir
Expand Down Expand Up @@ -181,14 +181,14 @@ async def change_setting(

@router.get("/lab/api/settings")
async def get_settings(user: User = Depends(current_user())):
with open(jlab_dir / "static" / "package.json") as f:
with open(jlab_dir / "static/package.json") as f:
package = json.load(f)
if user:
user_settings = json.loads(user.settings)
else:
user_settings = {}
settings = []
for path in (jlab_dir / "schemas" / "@jupyterlab").glob("*/*.json"):
for path in (jlab_dir / "schemas/@jupyterlab").glob("*/*.json"):
with open(path) as f:
schema = json.load(f)
key = f"{path.parent.name}:{path.stem}"
Expand Down
5 changes: 3 additions & 2 deletions plugins/lab/fps_lab/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import json
from glob import glob
from pathlib import Path
from typing import List, Tuple

Expand All @@ -8,9 +7,11 @@ def get_federated_extensions(extensions_dir: Path) -> Tuple[List, List]:
federated_extensions = []
disabledExtensions = []

for path in glob(str(extensions_dir / "**" / "package.json"), recursive=True):
for path in extensions_dir.rglob("**/package.json"):
with open(path) as f:
package = json.load(f)
if "jupyterlab" not in package.keys():
davidbrochart marked this conversation as resolved.
Show resolved Hide resolved
continue
name = package["name"]
extension = package["jupyterlab"]["_build"]
extension["name"] = name
Expand Down
18 changes: 9 additions & 9 deletions plugins/retrolab/fps_retrolab/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@

router.mount(
"/lab/extensions/@retrolab/lab-extension/static",
StaticFiles(directory=retrolab_dir / "labextension" / "static"),
StaticFiles(directory=retrolab_dir / "labextension/static"),
name="labextension/static",
)

for path in (retrolab_dir / "labextension" / "static").glob("remoteEntry.*.js"):
for path in (retrolab_dir / "labextension/static").glob("remoteEntry.*.js"):
load = f"static/{path.name}"
break
retro_federated_extensions = [
Expand Down Expand Up @@ -91,12 +91,12 @@ async def get_terminal(


def get_index(doc_name, retro_page, collaborative, base_url="/"):
extensions_dir = prefix_dir / "share" / "jupyter" / "labextensions"
extensions_dir = prefix_dir / "share/jupyter/labextensions"
federated_extensions, disabled_extension = get_federated_extensions(extensions_dir)
page_config = {
"appName": "RetroLab",
"appNamespace": "retro",
"appSettingsDir": str(prefix_dir / "share" / "jupyter" / "lab" / "settings"),
"appSettingsDir": (prefix_dir / "share/jupyter/lab/settings").as_posix(),
"appUrl": "/lab",
"appVersion": retrolab.__version__,
"baseUrl": base_url,
Expand All @@ -117,19 +117,19 @@ def get_index(doc_name, retro_page, collaborative, base_url="/"):
"fullTranslationsApiUrl": f"{base_url}lab/api/translations",
"fullTreeUrl": f"{base_url}lab/tree",
"fullWorkspacesApiUrl": f"{base_url}lab/api/workspaces",
"labextensionsPath": [str(prefix_dir / "share" / "jupyter" / "labextensions")],
"labextensionsPath": [(prefix_dir / "share/jupyter/labextensions").as_posix()],
"labextensionsUrl": "/lab/extensions",
"licensesUrl": "/lab/api/licenses",
"listingsUrl": "/lab/api/listings",
"mathjaxConfig": "TeX-AMS-MML_HTMLorMML-full,Safe",
"retroLogo": False,
"retroPage": retro_page,
"schemasDir": str(prefix_dir / "share" / "jupyter" / "lab" / "schemas"),
"schemasDir": (prefix_dir / "share/jupyter/lab/schemas").as_posix(),
"settingsUrl": "/lab/api/settings",
"staticDir": str(retrolab_dir / "static"),
"templatesDir": str(retrolab_dir / "templates"),
"staticDir": (retrolab_dir / "static").as_posix(),
"templatesDir": (retrolab_dir / "templates").as_posix(),
"terminalsAvailable": True,
"themesDir": str(prefix_dir / "share" / "jupyter" / "lab" / "themes"),
"themesDir": (prefix_dir / "share/jupyter/lab/themes").as_posix(),
"themesUrl": "/lab/api/themes",
"translationsApiUrl": "/lab/api/translations",
"treeUrl": "/lab/tree",
Expand Down
2 changes: 1 addition & 1 deletion plugins/yjs/fps_yjs/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def get_room(self, path: str) -> YRoom:
# it is a stored document (e.g. a notebook)
file_format, file_type, file_path = path.split(":", 2)
p = Path(file_path)
updates_file_path = str(p.parent / f".{file_type}:{p.name}.y")
updates_file_path = (p.parent / f".{file_type}:{p.name}.y").as_posix()
ystore = JupyterSQLiteYStore(path=updates_file_path) # FIXME: pass in config
self.rooms[path] = DocumentRoom(file_type, ystore)
else:
Expand Down
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

@pytest.fixture()
def cwd():
return Path(__file__).parent.parent
return Path(__file__).parents[1]


def get_open_port():
Expand Down
6 changes: 3 additions & 3 deletions tests/test_contents.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def test_tree(client, tmp_path):
size=size,
mimetype="text/plain",
name=fname,
path=str(dname / fname),
path=(dname / fname).as_posix(),
format=None,
)
)
Expand All @@ -38,7 +38,7 @@ def test_tree(client, tmp_path):
size=None,
mimetype=None,
name=sub_dname,
path=str(dname / sub_dname),
path=(dname / sub_dname).as_posix(),
format="json",
)
)
Expand All @@ -48,7 +48,7 @@ def test_tree(client, tmp_path):
size=None,
mimetype=None,
name="",
path=str(dname),
path=dname.as_posix(),
format="json",
)
response = client.get("/api/contents", params={"content": 1})
Expand Down
4 changes: 1 addition & 3 deletions tests/test_kernels.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@
async def test_kernel_messages(client, capfd):
kernel_id = "kernel_id_0"
kernel_name = "python3"
kernelspec_path = (
Path(sys.prefix) / "share" / "jupyter" / "kernels" / kernel_name / "kernel.json"
)
kernelspec_path = Path(sys.prefix) / f"share/jupyter/kernels/{kernel_name}/kernel.json"
assert kernelspec_path.exists()
kernel_server = KernelServer(kernelspec_path=kernelspec_path, capture_kernel_output=False)
await kernel_server.start()
Expand Down