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: normalize git urls in conversion from jupyter to marimo deps (#7876)
Myles Scolnickd7421e12d85b
diff --git a/marimo/_convert/ipynb/to_ir.py b/marimo/_convert/ipynb/to_ir.pyindex e87591df81..462bac90d0 100644--- a/marimo/_convert/ipynb/to_ir.py+++ b/marimo/_convert/ipynb/to_ir.py@@ -403,6 +403,58 @@ class ExclamationMarkResult:needs_subprocess: bool+def _normalize_git_url_package(package: str) -> str:+ """+ Normalize git URL packages to PEP 508 format.++ Converts:+ git+https://github.com/user/repo.git+ To:+ repo @ git+https://github.com/user/repo.git++ Returns the package as-is if it's not a git URL.+ """+ # Check if this looks like a git URL or VCS URL+ # Common patterns: git+https://, git+ssh://, git+git://, or any URL ending in .git+ is_git_url = package.startswith("git+") or (+ "://" in package+ and package.rstrip("/").endswith(".git")+ and " @ " not in package+ )++ if is_git_url:+ import urllib.parse++ # Extract the repo name from the URL+ if package.startswith("git+"):+ url_without_prefix = package[4:] # Remove "git+"+ else:+ url_without_prefix = package++ # Parse the URL to extract the path+ parsed = urllib.parse.urlparse(url_without_prefix)+ path = parsed.path++ # Get the last part of the path as the repo name+ repo_name = path.rstrip("/").split("/")[-1]++ # Remove .git extension if present+ if repo_name.endswith(".git"):+ repo_name = repo_name[:-4]++ # If we couldn't extract a name, use a placeholder+ if not repo_name:+ repo_name = "package"++ # Ensure the URL has git+ prefix+ if not package.startswith("git+"):+ package = f"git+{package}"++ return f"{repo_name} @ {package}"++ return package++def _extract_pip_install(command_line: str, command_tokens: list[str]) -> ExclamationCommandResult:@@ -414,7 +466,8 @@ def _extract_pip_install(packages = [p for p in command_tokens[install_idx + 1 :] if not p.startswith("-")]- pip_packages = packages+ # Normalize git URLs to PEP 508 format+ pip_packages = [_normalize_git_url_package(p) for p in packages]# Comment out the pip commandreplacement = (diff --git a/tests/_convert/ipynb/test_ipynb_to_ir.py b/tests/_convert/ipynb/test_ipynb_to_ir.pyindex d6c3f61bf5..a17d42b091 100644--- a/tests/_convert/ipynb/test_ipynb_to_ir.py+++ b/tests/_convert/ipynb/test_ipynb_to_ir.py@@ -1,6 +1,7 @@from __future__ import annotationsimport ast+import jsonfrom textwrap import dedentimport pytest@@ -1069,8 +1070,6 @@ def test_transform_add_subprocess_import_not_needed():def test_build_metadata_with_pip_packages():- import json-# Create a minimal notebook with pip installnotebook = {"cells": [@@ -1092,8 +1091,6 @@ def test_build_metadata_with_pip_packages():def test_build_metadata_no_pip_packages():- import json-# Create a notebook without pip installnotebook = {"cells": [@@ -1115,8 +1112,6 @@ def test_build_metadata_no_pip_packages():def test_build_metadata_with_existing_metadata():- import json-# Create a notebook with existing PEP 723 metadatanotebook = {"cells": [@@ -1139,8 +1134,6 @@ def test_build_metadata_with_existing_metadata():def test_integration_exclamation_marks_full_pipeline():- import json-# Test the full pipeline with mixed commandsnotebook = {"cells": [@@ -1180,3 +1173,86 @@ def test_integration_exclamation_marks_full_pipeline():"# packages added via marimo's package management:" in sfor s in sources)+++def test_transform_git_url_packages():+ from marimo._convert.ipynb.to_ir import _normalize_git_url_package++ # Test git+https URL+ result = _normalize_git_url_package(+ "git+https://github.com/locuslab/mugrade.git"+ )+ assert result == "mugrade @ git+https://github.com/locuslab/mugrade.git"++ # Test https URL (should be converted to git+https)+ result = _normalize_git_url_package(+ "https://github.com/user/mypackage.git"+ )+ assert result == "mypackage @ git+https://github.com/user/mypackage.git"++ # Test URL without .git extension+ result = _normalize_git_url_package("git+https://github.com/user/repo")+ assert result == "repo @ git+https://github.com/user/repo"++ # Test regular package (should remain unchanged)+ result = _normalize_git_url_package("numpy")+ assert result == "numpy"++ result = _normalize_git_url_package("pandas>=1.0.0")+ assert result == "pandas>=1.0.0"++ # Test GitLab URL+ result = _normalize_git_url_package(+ "git+https://gitlab.com/user/project.git"+ )+ assert result == "project @ git+https://gitlab.com/user/project.git"+++def test_integration_git_url_in_notebook():+ # Test the full pipeline with git URL install+ notebook = {+ "cells": [+ {+ "cell_type": "code",+ "source": "!pip install --upgrade --no-deps git+https://github.com/locuslab/mugrade.git",+ "metadata": {},+ }+ ],+ "metadata": {},+ "nbformat": 4,+ "nbformat_minor": 2,+ }++ result = convert_from_ipynb_to_notebook_ir(json.dumps(notebook))++ # Check that the git URL was properly converted to PEP 508 format+ assert (+ 'dependencies = ["mugrade @ git+https://github.com/locuslab/mugrade.git"]'+ in result.header.value+ )+++def test_integration_mixed_packages_with_git_url():+ # Test the full pipeline with mixed packages including git URLs+ notebook = {+ "cells": [+ {+ "cell_type": "code",+ "source": "!pip install numpy pandas git+https://github.com/user/package.git",+ "metadata": {},+ }+ ],+ "metadata": {},+ "nbformat": 4,+ "nbformat_minor": 2,+ }++ result = convert_from_ipynb_to_notebook_ir(json.dumps(notebook))++ # Check that all packages are properly formatted+ header_value = result.header.value+ assert '"numpy"' in header_value+ assert '"pandas"' in header_value+ assert (+ '"package @ git+https://github.com/user/package.git"' in header_value+ )