Skip to content

Commit

Permalink
Merge branch 'main' into linux-dev
Browse files Browse the repository at this point in the history
  • Loading branch information
CodyCBakerPhD authored May 29, 2024
2 parents e455df9 + b03fcf2 commit a148984
Show file tree
Hide file tree
Showing 131 changed files with 376 additions and 254 deletions.
2 changes: 1 addition & 1 deletion .storybook/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { StorybookConfig } from '@storybook/web-components-vite';
import ViteYaml from "@modyfi/vite-plugin-yaml";

const config: StorybookConfig = {
stories: ["../src/**/*.mdx", "../src/**/*.stories.@(js|jsx|ts|tsx)"],
stories: ["../stories/**/*.mdx", "../stories/**/*.stories.@(js|jsx|ts|tsx)"],
addons: ["@storybook/addon-links", "@storybook/addon-essentials"],
framework: {
name: "@storybook/web-components-vite",
Expand Down
8 changes: 5 additions & 3 deletions generateInterfaceSchema.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from neuroconv import NWBConverter, converters, datainterfaces

filepath = Path("src") / "supported_interfaces.json"
generatedJSONSchemaPath = Path("schemas", "json", "generated")
generatedJSONSchemaPath = Path("stories") / "inputs" / "interface_schemas"
generatedJSONSchemaPath.mkdir(exist_ok=True, parents=True)

f = filepath.open()
Expand All @@ -29,9 +29,11 @@ class CustomNWBConverter(NWBConverter):
outfile.write(json.dumps(schema, indent=4))


sourceDataStoryPath = Path("src/electron/renderer/src/stories/pages/guided-mode/SourceData.stories.js")
sourceDataStoryPath = Path("stories/pages/SourceData.stories.js")

importCode = "\n".join(map(lambda arr: f"import {arr[0]}Schema from '../../../../../../{arr[1]}'", paths.items()))
importCode = "\n".join(
map(lambda arr: f"import {arr[0]}Schema from '../inputs/interface_schemas/{arr[1]}'", paths.items())
)
storyCode = "\n".join(
map(
lambda arr: f"""export const {arr[0]} = PageTemplate.bind({{}});
Expand Down
File renamed without changes
8 changes: 4 additions & 4 deletions src/electron/renderer/src/pages.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ import { GuidedInspectorPage } from "./stories/pages/guided-mode/options/GuidedI

import logo from "../assets/img/logo-guide-draft-transparent-tight.png";
import { GuidedPathExpansionPage } from "./stories/pages/guided-mode/data/GuidedPathExpansion";
import uploadIcon from "./stories/assets/dandi.svg?raw";
import inspectIcon from "./stories/assets/inspect.svg?raw";
import neurosiftIcon from "./stories/assets/neurosift-logo.svg?raw";
import uploadIcon from "../assets/icons/dandi.svg?raw";
import inspectIcon from "../assets/icons/inspect.svg?raw";
import neurosiftIcon from "../assets/icons/neurosift-logo.svg?raw";

import settingsIcon from "./stories/assets/settings.svg?raw";
import settingsIcon from "../assets/icons/settings.svg?raw";

import { UploadsPage } from "./stories/pages/uploads/UploadsPage";
import { SettingsPage } from "./stories/pages/settings/SettingsPage";
Expand Down
10 changes: 5 additions & 5 deletions src/electron/renderer/src/server/globals.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { isElectron, app, port } from '../electron/index.js'

import serverSVG from "../stories/assets/server.svg?raw";
import webAssetSVG from "../stories/assets/web_asset.svg?raw";
import wifiSVG from "../stories/assets/wifi.svg?raw";
import serverSVG from "../../assets/icons/server.svg?raw";
import webAssetSVG from "../../assets/icons/web_asset.svg?raw";
import wifiSVG from "../../assets/icons/wifi.svg?raw";

// Base Request URL for Python Server
export const baseUrl = `http://127.0.0.1:${port}`;
Expand Down Expand Up @@ -56,7 +56,7 @@ export const activateServer = () => {
export const serverGlobals = {
species: new Promise((res, rej) => {
onServerOpen(() => {
fetch(new URL("get-recommended-species", baseUrl))
fetch(new URL("/dandi/get-recommended-species", baseUrl))
.then((res) => res.json())
.then((species) => {
res(species)
Expand All @@ -67,7 +67,7 @@ export const serverGlobals = {
}),
cpus: new Promise((res, rej) => {
onServerOpen(() => {
fetch(new URL("cpus", baseUrl))
fetch(new URL("/system/cpus", baseUrl))
.then((res) => res.json())
.then((cpus) => {
res(cpus)
Expand Down
2 changes: 1 addition & 1 deletion src/electron/renderer/src/stories/FileSystemSelector.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { fs, remote } from "../electron/index";
import { List } from "./List";
const { dialog } = remote;

import restartSVG from "./assets/restart.svg?raw";
import restartSVG from "../../assets/icons/restart.svg?raw";
import { unsafeSVG } from "lit/directives/unsafe-svg.js";

function getObjectTypeReferenceString(type, multiple, { nested, native } = {}) {
Expand Down
4 changes: 2 additions & 2 deletions src/electron/renderer/src/stories/FullScreenToggle.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { LitElement, css, html } from "lit";

import fullScreenIcon from './assets/fullscreen.svg?raw'
import fullScreenExitIcon from './assets/fullscreen_exit.svg?raw'
import fullScreenIcon from '../../assets/icons/fullscreen.svg?raw'
import fullScreenExitIcon from '../../assets/icons/fullscreen_exit.svg?raw'

import { unsafeHTML } from "lit/directives/unsafe-html.js";

Expand Down
2 changes: 1 addition & 1 deletion src/electron/renderer/src/stories/Search.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { LitElement, html, css } from "lit";
import { styleMap } from "lit/directives/style-map.js";

import searchSVG from "./assets/search.svg?raw";
import searchSVG from "../../assets/icons/search.svg?raw";

import tippy from "tippy.js";
import { unsafeHTML } from "lit/directives/unsafe-html.js";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { header, tempPropertyKey } from "../../../forms/utils";
import { createGlobalFormModal } from "../../../forms/GlobalFormModal";
import { Button } from "../../../Button.js";

import globalIcon from "../../../assets/global.svg?raw";
import globalIcon from "../../../../../assets/icons/global.svg?raw";

const parentTableRenderConfig = {
Electrodes: (metadata) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { Button } from "../../../Button.js";
import { Modal } from "../../../Modal";
import { header } from "../../../forms/utils";

import autocompleteIcon from "../../../assets/inspect.svg?raw";
import autocompleteIcon from "../../../../../assets/icons/inspect.svg?raw";

const propOrder = ["path", "subject_id", "session_id"];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { createGlobalFormModal } from "../../../forms/GlobalFormModal";
import { header } from "../../../forms/utils";
import { Button } from "../../../Button.js";

import globalIcon from "../../../assets/global.svg?raw";
import globalIcon from "../../../../../assets/icons/global.svg?raw";

import { baseUrl } from "../../../../server/globals";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { html } from "lit";
import { Page } from "../../Page.js";

import { unsafeSVG } from "lit/directives/unsafe-svg.js";
import folderOpenSVG from "../../../assets/folder_open.svg?raw";
import folderOpenSVG from "../../../../../assets/icons/folder_open.svg?raw";

import { electron } from "../../../../electron/index.js";
import { getSharedPath, removeFilePaths, truncateFilePaths } from "../../../preview/NWBFilePreview.js";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { html } from "lit";
import { Page } from "../../Page.js";

import { unsafeSVG } from "lit/directives/unsafe-svg.js";
import folderOpenSVG from "../../../assets/folder_open.svg?raw";
import folderOpenSVG from "../../../../../assets/icons/folder_open.svg?raw";

import { electron } from "../../../../electron/index.js";
import { NWBFilePreview, getSharedPath } from "../../../preview/NWBFilePreview.js";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { until } from "lit/directives/until.js";

import { Button } from "../../../Button.js";

import keyIcon from "../../../assets/key.svg?raw";
import keyIcon from "../../../../../assets/icons/key.svg?raw";

import { validate } from "../../uploads/utils";
import { global } from "../../../../progress/index.js";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { html } from "lit";
import { unsafeSVG } from "lit/directives/unsafe-svg.js";
import folderOpenSVG from "../../../assets/folder_open.svg?raw";
import folderOpenSVG from "../../../../../assets/icons/folder_open.svg?raw";

import { Page } from "../../Page.js";
import { getStubArray } from "../options/GuidedStubPreview.js";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { Button } from "../../../Button.js";
import { createGlobalFormModal } from "../../../forms/GlobalFormModal";
import { header } from "../../../forms/utils";

import globalIcon from "../../../assets/global.svg?raw";
import globalIcon from "../../../../../assets/icons/global.svg?raw";

export class GuidedSubjectsPage extends Page {
constructor(...args) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@ export class PreviewPage extends Page {

updatePath = async (path) => {
if (path) {
const result = await fetch(`${baseUrl}/files/${path}`, { method: "POST" }).then((res) => res.text());
// Enable access to the explicit file path
const result = await fetch(`${baseUrl}/files/${path}`, {
method: "POST",
}).then((res) => res.text());

// Set Neurosift to access the returned URL
if (result) this.neurosift.url = result;
} else this.neurosift.url = undefined;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ import { merge, setUndefinedIfNotDeclared } from "../utils";
import { homeDirectory, notyf, testDataFolderPath } from "../../../dependencies/globals";
import { SERVER_FILE_PATH, electron, path, port, fs } from "../../../electron/index.js";

import saveSVG from "../../assets/save.svg?raw";
import folderSVG from "../../assets/folder_open.svg?raw";
import deleteSVG from "../../assets/delete.svg?raw";
import generateSVG from "../../assets/restart.svg?raw";
import saveSVG from "../../../../assets/icons/save.svg?raw";
import folderSVG from "../../../../assets/icons/folder_open.svg?raw";
import deleteSVG from "../../../../assets/icons/delete.svg?raw";
import generateSVG from "../../../../assets/icons/restart.svg?raw";

import { header } from "../../forms/utils";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import { validateDANDIApiKey } from "../../../validation/dandi";

import * as dandi from "dandi";

import keyIcon from "../../assets/key.svg?raw";
import keyIcon from "../../../../assets/icons/key.svg?raw";

import { AWARD_VALIDATION_FAIL_MESSAGE, awardNumberValidator, isStaging, validate } from "./utils";
import { createFormModal } from "../../forms/GlobalFormModal";
Expand Down
5 changes: 4 additions & 1 deletion src/electron/renderer/src/stories/preview/NWBFilePreview.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ class NWBPreviewInstance extends LitElement {
const isOnline = navigator.onLine;

return isOnline
? new Neurosift({ url: getURLFromFilePath(this.file, this.project), fullscreen: false })
? new Neurosift({
url: getURLFromFilePath(this.file, this.project),
fullscreen: false,
})
: until(
(async () => {
const htmlRep = await run("html", { nwbfile_path: this.file }, { swal: false });
Expand Down
4 changes: 3 additions & 1 deletion src/electron/renderer/src/stories/preview/Neurosift.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ export class Neurosift extends LitElement {
render() {
return this.url
? html` <div class="loader-container">
${new Loader({ message: `Loading Neurosift view...<br/><small>${this.url}</small>` })}
${new Loader({
message: `Loading Neurosift view...<br/><small>${this.url}</small>`,
})}
</div>
${this.fullscreen ? new FullScreenToggle({ target: this }) : ""}
<iframe
Expand Down
3 changes: 0 additions & 3 deletions src/pyflask/apis/__init__.py

This file was deleted.

96 changes: 41 additions & 55 deletions src/pyflask/app.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""The primary Flask server for the Python backend."""

import collections
import json
import multiprocessing
import sys
Expand All @@ -10,13 +11,12 @@
from os.path import isabs
from pathlib import Path
from signal import SIGINT
from typing import Union
from urllib.parse import unquote

# https://stackoverflow.com/questions/32672596/pyinstaller-loads-script-multiple-times#comment103216434_32677108
multiprocessing.freeze_support()


from apis import data_api, neuroconv_api, startup_api
from flask import Flask, request, send_file, send_from_directory
from flask_cors import CORS
from flask_restx import Api, Resource
Expand All @@ -27,12 +27,22 @@
is_packaged,
resource_path,
)
from namespaces import (
dandi_namespace,
data_namespace,
neuroconv_namespace,
neurosift_namespace,
startup_namespace,
system_namespace,
)

app = Flask(__name__)
neurosift_file_registry = collections.defaultdict(bool)

flask_app = Flask(__name__)

# Always enable CORS to allow distinct processes to handle frontend vs. backend
CORS(app)
app.config["CORS_HEADERS"] = "Content-Type"
CORS(flask_app)
flask_app.config["CORS_HEADERS"] = "Content-Type"

# Create logger configuration
LOG_FOLDER = Path(GUIDE_ROOT_FOLDER, "logs")
Expand All @@ -50,63 +60,39 @@
title="NWB GUIDE API",
description="The REST API for the NWB GUIDE provided by the Python Flask Server.",
)
api.add_namespace(startup_api)
api.add_namespace(neuroconv_api)
api.add_namespace(data_api)
api.init_app(app)
api.add_namespace(startup_namespace)
api.add_namespace(neuroconv_namespace)
api.add_namespace(data_namespace)
api.add_namespace(system_namespace)
api.add_namespace(dandi_namespace)
# api.add_namespace(neurosift_namespace) # TODO: enable later
api.init_app(flask_app)

registered = {}

@flask_app.route("/preview/<path:file_path>")
def send_preview(file_path):
return send_from_directory(directory=STUB_SAVE_FOLDER_PATH, path=file_path)

@app.route("/files")
def get_all_files():
return list(registered.keys())

@flask_app.route("/files/<path:file_path>", methods=["GET", "POST"])
def handle_file_request(file_path) -> Union[str, None]:
if ".nwb" not in file_path:
raise ValueError("This endpoint must be called on an NWB file!")

@app.route("/files/<path:path>", methods=["GET", "POST"])
def handle_file_request(path):
if request.method == "GET":
if registered[path]:
path = unquote(path)
if not isabs(path):
path = f"/{path}"
return send_file(path)
if neurosift_file_registry[file_path] is True:
file_path = unquote(file_path)
if not isabs(file_path):
file_path = f"/{file_path}"

return send_file(path_or_file=file_path)
else:
app.abort(404, "Resource is not accessible.")

else:
if ".nwb" in path:
registered[path] = True
return request.base_url
else:
app.abort(400, str("Path does not point to an NWB file."))


@app.route("/conversions/<path:path>")
def send_conversions(path):
return send_from_directory(CONVERSION_SAVE_FOLDER_PATH, path)


@app.route("/preview/<path:path>")
def send_preview(path):
return send_from_directory(STUB_SAVE_FOLDER_PATH, path)


@app.route("/cpus")
def get_cpu_count():
from psutil import cpu_count

physical = cpu_count(logical=False)
logical = cpu_count()

return dict(physical=physical, logical=logical)


@app.route("/get-recommended-species")
def get_species():
from dandi.metadata.util import species_map
neurosift_file_registry[file_path] = True

return species_map
return request.base_url


@api.route("/log")
Expand Down Expand Up @@ -154,13 +140,13 @@ def get(self):
)
log_handler.setFormatter(log_formatter)

app.logger.addHandler(log_handler)
app.logger.setLevel(DEBUG)
flask_app.logger.addHandler(log_handler)
flask_app.logger.setLevel(DEBUG)

app.logger.info(f"Logging to {LOG_FILE_PATH}")
flask_app.logger.info(f"Logging to {LOG_FILE_PATH}")

# Run the server
api.logger.info(f"Starting server on port {port}")
app.run(host="127.0.0.1", port=port)
flask_app.run(host="127.0.0.1", port=port)
else:
raise Exception("No port provided for the NWB GUIDE backend.")
Loading

0 comments on commit a148984

Please sign in to comment.