A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.
Python artificial-intelligencedagdata-sciencedata-visualizationdataflowdeveloper-toolsmachine-learningnotebookspipelinepythonreactivesqlweb-app
fix: opening files when using 'marimo <dev>' (#1775)
Myles Scolnickf0802e5743e2
diff --git a/frontend/src/components/pages/home-page.tsx b/frontend/src/components/pages/home-page.tsxindex 4d36e94811..6b3d0fea27 100644--- a/frontend/src/components/pages/home-page.tsx+++ b/frontend/src/components/pages/home-page.tsx@@ -6,13 +6,8 @@ import {shutdownSession,} from "@/core/network/requests";import { combineAsyncData, useAsyncData } from "@/hooks/useAsyncData";-import React, {- Suspense,- useContext,- useEffect,- useRef,- useState,-} from "react";+import type React from "react";+import { Suspense, useContext, useEffect, useRef, useState } from "react";import { Spinner } from "../icons/spinner";import {BookTextIcon,@@ -28,7 +23,7 @@ import {} from "lucide-react";import { ShutdownButton } from "../editor/controls/shutdown-button";import {- SessionId,+ type SessionId,generateSessionId,getSessionId,isSessionId,@@ -40,17 +35,22 @@ import { assertExists } from "@/utils/assertExists";import { Button } from "@/components/ui/button";import { Tooltip } from "@/components/ui/tooltip";import { toast } from "@/components/ui/use-toast";-import { FileInfo, MarimoFile } from "@/core/network/types";+import type { FileInfo, MarimoFile } from "@/core/network/types";import { ConfigButton } from "../app-config/app-config-button";import { Checkbox } from "@/components/ui/checkbox";import { Label } from "@/components/ui/label";import { MarkdownIcon } from "@/components/editor/cell/code/icons";import { asURL } from "@/utils/url";import { timeAgo } from "@/utils/dates";-import { NodeApi, NodeRendererProps, Tree, TreeApi } from "react-arborist";+import {+ type NodeApi,+ type NodeRendererProps,+ Tree,+ type TreeApi,+} from "react-arborist";import { cn } from "@/utils/cn";import {- FileType,+ type FileType,guessFileType,FILE_TYPE_ICONS,} from "../editor/file-tree/types";@@ -62,6 +62,7 @@ import {} from "../home/state";import { Maps } from "@/utils/maps";import { Input } from "../ui/input";+import { Paths } from "@/utils/paths";function tabTarget(path: string) {// Consistent tab target so we open in the same tab when clicking on the same notebook@@ -276,9 +277,10 @@ const Node = ({ node, style }: NodeRendererProps<FileInfo>) => {);}- const relativePath = node.data.path.startsWith(root)- ? node.data.path.slice(root.length + 1)- : node.data.path;+ const relativePath =+ node.data.path.startsWith(root) && Paths.isAbsolute(node.data.path)+ ? node.data.path.slice(root.length + 1)+ : node.data.path;const isMarkdown = relativePath.endsWith(".md");diff --git a/frontend/src/utils/__tests__/path.test.ts b/frontend/src/utils/__tests__/path.test.tsindex ac9d3b68c4..fec46e05fd 100644--- a/frontend/src/utils/__tests__/path.test.ts+++ b/frontend/src/utils/__tests__/path.test.ts@@ -1,8 +1,15 @@/* Copyright 2024 Marimo. All rights reserved. */import { describe, expect, it } from "vitest";-import { FilePath, PathBuilder, Paths } from "../paths";+import { type FilePath, PathBuilder, Paths } from "../paths";describe("Paths", () => {+ it("isAbsolute", () => {+ expect(Paths.isAbsolute("/")).toBe(true);+ expect(Paths.isAbsolute("/user/docs/Letter.txt")).toBe(true);+ expect(Paths.isAbsolute("C:\\user\\docs\\Letter.txt")).toBe(true);+ expect(Paths.isAbsolute("user/docs/Letter.txt")).toBe(false);+ });+describe("dirname", () => {it("should return the directory path of a given path", () => {expect(Paths.dirname("/user/docs/Letter.txt")).toBe("/user/docs");diff --git a/frontend/src/utils/paths.ts b/frontend/src/utils/paths.tsindex f18f5b401a..1234a702da 100644--- a/frontend/src/utils/paths.ts+++ b/frontend/src/utils/paths.ts@@ -1,10 +1,15 @@/* Copyright 2024 Marimo. All rights reserved. */-import { TypedString } from "./typed";+import type { TypedString } from "./typed";export type FilePath = TypedString<"FilePath">;export const Paths = {+ isAbsolute: (path: string): boolean => {+ return (+ path.startsWith("/") || path.startsWith("\\") || path.startsWith("C:\\")+ );+ },dirname: (path: string) => {return PathBuilder.guessDeliminator(path).dirname(path as FilePath);},