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: dont search winpython in scanner for workspace files (#8633)
Myles Scolnick7694f8952bf8
diff --git a/marimo/_server/files/directory_scanner.py b/marimo/_server/files/directory_scanner.pyindex d31ce2d7ef..63c92a4219 100644--- a/marimo/_server/files/directory_scanner.py+++ b/marimo/_server/files/directory_scanner.py@@ -90,11 +90,16 @@ class DirectoryScanner:# Package management"node_modules","site-packages",+ # Portable Python distributions+ "winpython",+ # Conda / pixi environments+ ".pixi",# Testing and tooling".tox",".nox",".pytest_cache",".mypy_cache",+ ".ruff_cache",# Version control".git",}@@ -183,46 +188,60 @@ class DirectoryScanner:if entry.name.startswith("."):continue- if entry.is_dir():- if entry.name in self.SKIP_DIRS or depth == self.max_depth:+ try:+ # Skip symlinks to avoid cycles and broken links+ if entry.is_symlink():continue- children = recurse(entry.path, depth + 1)- if children:- entry_path = Path(entry.path)- relative_path = str(- entry_path.relative_to(self.directory)- )- folders.append(- FileInfo(++ if entry.is_dir():+ if (+ entry.name in self.SKIP_DIRS+ or entry.name.lower() in self.SKIP_DIRS+ or depth == self.max_depth+ ):+ continue+ children = recurse(entry.path, depth + 1)+ if children:+ entry_path = Path(entry.path)+ relative_path = str(+ entry_path.relative_to(self.directory)+ )+ folders.append(+ FileInfo(+ id=relative_path,+ path=relative_path,+ name=entry.name,+ is_directory=True,+ is_marimo_file=False,+ children=children,+ )+ )+ elif entry.name.endswith(self.allowed_extensions):+ if is_marimo_app(entry.path):+ file_count[0] += 1+ entry_path = Path(entry.path)+ relative_path = str(+ entry_path.relative_to(self.directory)+ )+ file_info = FileInfo(id=relative_path,path=relative_path,name=entry.name,- is_directory=True,- is_marimo_file=False,- children=children,+ is_directory=False,+ is_marimo_file=True,+ last_modified=entry.stat().st_mtime,)- )- elif entry.name.endswith(self.allowed_extensions):- if is_marimo_app(entry.path):- file_count[0] += 1- entry_path = Path(entry.path)- relative_path = str(- entry_path.relative_to(self.directory)- )- file_info = FileInfo(- id=relative_path,- path=relative_path,- name=entry.name,- is_directory=False,- is_marimo_file=True,- last_modified=entry.stat().st_mtime,- )- files.append(file_info)- # Also add to partial results for timeout recovery- self.partial_results.append(file_info)- # Check if we've reached the limit- if file_count[0] >= self.max_files:- break+ files.append(file_info)+ # Also add to partial results for timeout recovery+ self.partial_results.append(file_info)+ # Check if we've reached the limit+ if file_count[0] >= self.max_files:+ break+ except OSError as e:+ LOGGER.debug(+ "Error processing entry %s: %s", entry.path, e+ )+ continue# Sort folders then files, based on natural sort (alpha, then num)return sorted(folders, key=natural_sort_file) + sorted(diff --git a/tests/_server/test_directory_scanner.py b/tests/_server/test_directory_scanner.pyindex 0d33a58db8..6f08f46806 100644--- a/tests/_server/test_directory_scanner.py+++ b/tests/_server/test_directory_scanner.py@@ -121,7 +121,13 @@ class TestDirectoryScanner(unittest.TestCase):def test_skip_common_directories(self):"""Test that common directories are skipped."""- for dirname in ["venv", "node_modules", "__pycache__", ".git"]:+ for dirname in [+ "venv",+ "node_modules",+ "__pycache__",+ ".git",+ "winpython",+ ]:skip_dir = os.path.join(self.test_dir, dirname)os.makedirs(skip_dir)with open(os.path.join(skip_dir, "app.py"), "w") as f:@@ -133,6 +139,23 @@ class TestDirectoryScanner(unittest.TestCase):for path in file_paths:assert "venv" not in pathassert "node_modules" not in path+ assert "__pycache__" not in path+ assert ".git" not in path+ assert "winpython" not in path++ def test_skip_common_directories_case_insensitive(self):+ """Test that SKIP_DIRS matching is case-insensitive."""+ # WinPython distributions often use varied casing like "WinPython"+ skip_dir = os.path.join(self.test_dir, "WinPython")+ os.makedirs(skip_dir)+ with open(os.path.join(skip_dir, "app.py"), "w") as f:+ f.write("import marimo\napp = marimo.App()\n")++ scanner = DirectoryScanner(self.test_dir)+ files = scanner.scan()+ file_paths = [f.path for f in files if not f.is_directory]+ for path in file_paths:+ assert "winpython" not in path.lower()def test_skip_hidden_files(self):"""Test that hidden files are skipped."""@@ -144,6 +167,39 @@ class TestDirectoryScanner(unittest.TestCase):file_names = [f.name for f in files if not f.is_directory]assert ".hidden_app.py" not in file_names+ def test_skip_symlinks(self):+ """Test that symlinks are skipped to avoid cycles and broken links."""+ try:+ # Create a symlink that points to a non-existent target (broken)+ broken_link = os.path.join(self.test_dir, "broken_link.py")+ broken_target = os.path.join(self.test_dir, "nonexistent_app.py")+ os.symlink(broken_target, broken_link)++ # Create a directory symlink that would cause a cycle+ cycle_link = os.path.join(self.test_dir, "cycle")+ os.symlink(self.test_dir, cycle_link, target_is_directory=True)++ # Create a symlink to a valid marimo file+ valid_target = os.path.join(self.test_dir, "app1.py")+ valid_link = os.path.join(self.test_dir, "linked_app.py")+ os.symlink(valid_target, valid_link)+ except (OSError, NotImplementedError):+ self.skipTest("Symlinks not supported on this platform")++ scanner = DirectoryScanner(self.test_dir)+ files = scanner.scan()+ file_names = [f.name for f in files if not f.is_directory]+ dir_names = [f.name for f in files if f.is_directory]++ # Symlinked files and directories should be skipped+ assert "broken_link.py" not in file_names+ assert "linked_app.py" not in file_names+ assert "cycle" not in dir_names++ # Original files should still be found+ assert "app1.py" in file_names+ assert "app2.py" in file_names+def test_partial_results_populated_during_scan(self):"""Test that partial_results is populated during scanning."""scanner = DirectoryScanner(self.test_dir)