Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
101 changes: 50 additions & 51 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,71 +15,70 @@ jobs:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4
- name: Checkout
uses: actions/checkout@v4

- name: Base Setup
uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1
- name: Base Setup
uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1

- name: Install dependencies
run: python -m pip install -U "jupyterlab>=4.0.0,<5"
- name: Install dependencies
run: python -m pip install -U "jupyterlab>=4.0.0,<5"

- name: Lint the extension
run: |
set -eux
jlpm
jlpm run lint:check
- name: Lint the extension
run: |
set -eux
jlpm
jlpm run lint:check

- name: Build the extension
run: |
set -eux
python -m pip install .[test]
- name: Build the extension
run: |
set -eux
python -m pip install .[test]

jupyter labextension list
jupyter labextension list 2>&1 | grep -ie "jupyterlab-cell-diff.*OK"
python -m jupyterlab.browser_check
jupyter labextension list
jupyter labextension list 2>&1 | grep -ie "jupyterlab-cell-diff.*OK"
python -m jupyterlab.browser_check

- name: Package the extension
run: |
set -eux
- name: Package the extension
run: |
set -eux

pip install build
python -m build
pip uninstall -y "jupyterlab_cell_diff" jupyterlab
pip install build
python -m build
pip uninstall -y "jupyterlab_cell_diff" jupyterlab

- name: Upload extension packages
uses: actions/upload-artifact@v4
with:
name: extension-artifacts
path: dist/jupyterlab_cell_diff*
if-no-files-found: error
- name: Upload extension packages
uses: actions/upload-artifact@v4
with:
name: extension-artifacts
path: dist/jupyterlab_cell_diff*
if-no-files-found: error

test_isolated:
needs: build
runs-on: ubuntu-latest

steps:
- name: Install Python
uses: actions/setup-python@v5
with:
python-version: '3.9'
architecture: 'x64'
- uses: actions/download-artifact@v4
with:
name: extension-artifacts
- name: Install and Test
run: |
set -eux
# Remove NodeJS, twice to take care of system and locally installed node versions.
sudo rm -rf $(which node)
sudo rm -rf $(which node)

pip install "jupyterlab>=4.0.0,<5" jupyterlab_cell_diff*.whl

jupyter labextension list
jupyter labextension list 2>&1 | grep -ie "jupyterlab-cell-diff.*OK"
python -m jupyterlab.browser_check --no-browser-test

- name: Install Python
uses: actions/setup-python@v5
with:
python-version: '3.9'
architecture: 'x64'
- uses: actions/download-artifact@v4
with:
name: extension-artifacts
- name: Install and Test
run: |
set -eux
# Remove NodeJS, twice to take care of system and locally installed node versions.
sudo rm -rf $(which node)
sudo rm -rf $(which node)

pip install "jupyterlab>=4.0.0,<5" jupyterlab_cell_diff*.whl

jupyter labextension list
jupyter labextension list 2>&1 | grep -ie "jupyterlab-cell-diff.*OK"
python -m jupyterlab.browser_check --no-browser-test

check_links:
name: Check Links
Expand Down
5 changes: 2 additions & 3 deletions .github/workflows/check-release.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name: Check Release
on:
push:
branches: ["main"]
branches: ['main']
pull_request:
branches: ["*"]
branches: ['*']

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
Expand All @@ -23,7 +23,6 @@ jobs:
- name: Check Release
uses: jupyter-server/jupyter_releaser/.github/actions/check-release@v2
with:

token: ${{ secrets.GITHUB_TOKEN }}

- name: Upload Distributions
Expand Down
16 changes: 8 additions & 8 deletions .github/workflows/prep-release.yml
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
name: "Step 1: Prep Release"
name: 'Step 1: Prep Release'
on:
workflow_dispatch:
inputs:
version_spec:
description: "New Version Specifier"
default: "next"
description: 'New Version Specifier'
default: 'next'
required: false
branch:
description: "The branch to target"
description: 'The branch to target'
required: false
post_version_spec:
description: "Post Version Specifier"
description: 'Post Version Specifier'
required: false
# silent:
# description: "Set a placeholder in the changelog and don't publish the release."
# required: false
# type: boolean
since:
description: "Use PRs with activity since this date or git reference"
description: 'Use PRs with activity since this date or git reference'
required: false
since_last_stable:
description: "Use PRs with activity since the last stable git tag"
description: 'Use PRs with activity since the last stable git tag'
required: false
type: boolean
jobs:
Expand All @@ -45,6 +45,6 @@ jobs:
since: ${{ github.event.inputs.since }}
since_last_stable: ${{ github.event.inputs.since_last_stable }}

- name: "** Next Step **"
- name: '** Next Step **'
run: |
echo "Optional): Review Draft Release: ${{ steps.prep-release.outputs.release_url }}"
12 changes: 6 additions & 6 deletions .github/workflows/publish-release.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
name: "Step 2: Publish Release"
name: 'Step 2: Publish Release'
on:
workflow_dispatch:
inputs:
branch:
description: "The target branch"
description: 'The target branch'
required: false
release_url:
description: "The URL of the draft GitHub release"
description: 'The URL of the draft GitHub release'
required: false
steps_to_skip:
description: "Comma separated list of steps to skip"
description: 'Comma separated list of steps to skip'
required: false

jobs:
Expand Down Expand Up @@ -47,13 +47,13 @@ jobs:
token: ${{ steps.app-token.outputs.token }}
release_url: ${{ steps.populate-release.outputs.release_url }}

- name: "** Next Step **"
- name: '** Next Step **'
if: ${{ success() }}
run: |
echo "Verify the final release"
echo ${{ steps.finalize-release.outputs.release_url }}

- name: "** Failure Message **"
- name: '** Failure Message **'
if: ${{ failure() }}
run: |
echo "Failed to Publish the Draft Release Url:"
Expand Down
69 changes: 63 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,25 +32,53 @@ jupyter labextension develop . --overwrite

### Commands

The extension provides a command to show cell diffs:
The extension provides commands to show diffs in multiple formats:

- `jupyterlab-cell-diff:show-codemirror` - Show diff using `@codemirror/merge`
- `jupyterlab-cell-diff:split-cell-diff` - Show cell diff using split view (side-by-side comparison)
- `jupyterlab-cell-diff:unified-cell-diff` - Show cell diff using unified view
- `jupyterlab-cell-diff:unified-file-diff` - Show file diff using unified view for regular Python files and other text files

https://github.com/user-attachments/assets/0dacd7f0-5963-4ebe-81da-2958f0117071

### Programmatic Usage

#### Split Cell Diff (Side-by-side View)

```typescript
app.commands.execute('jupyterlab-cell-diff:show-codemirror', {
app.commands.execute('jupyterlab-cell-diff:split-cell-diff', {
cellId: 'cell-id',
originalSource: 'print("Hello")',
newSource: 'print("Hello, World!")'
newSource: 'print("Hello, World!")',
showActionButtons: true,
openDiff: true
});
```

#### Command Arguments
#### Unified Cell Diff

```typescript
app.commands.execute('jupyterlab-cell-diff:unified-cell-diff', {
cellId: 'cell-id',
originalSource: 'print("Hello")',
newSource: 'print("Hello, World!")',
showActionButtons: true
});
```

The `jupyterlab-cell-diff:show-codemirror` command accepts the following arguments:
#### Unified File Diff

```typescript
app.commands.execute('jupyterlab-cell-diff:unified-file-diff', {
filePath: '/path/to/file.py',
originalSource: 'print("Hello")',
newSource: 'print("Hello, World!")',
showActionButtons: true
});
```

### Command Arguments

#### `jupyterlab-cell-diff:split-cell-diff` (Split View)

| Argument | Type | Required | Description |
| ------------------- | --------- | -------- | ------------------------------------------------------------------------------------ |
Expand All @@ -61,6 +89,35 @@ The `jupyterlab-cell-diff:show-codemirror` command accepts the following argumen
| `notebookPath` | `string` | No | Path to the notebook containing the cell. If not provided, uses the current notebook |
| `openDiff` | `boolean` | No | Whether to open the diff widget automatically (default: `true`) |

#### `jupyterlab-cell-diff:unified-cell-diff` (Unified View)

| Argument | Type | Required | Description |
| ------------------- | --------- | -------- | ------------------------------------------------------------------------------------ |
| `cellId` | `string` | No | ID of the cell to show diff for. If not provided, uses the active cell |
| `originalSource` | `string` | Yes | Original source code to compare against |
| `newSource` | `string` | Yes | New source code to compare with |
| `showActionButtons` | `boolean` | No | Whether to show action buttons for chunk acceptance (default: `true`) |
| `notebookPath` | `string` | No | Path to the notebook containing the cell. If not provided, uses the current notebook |

#### `jupyterlab-cell-diff:unified-file-diff` (File Diff)

| Argument | Type | Required | Description |
| ------------------- | --------- | -------- | --------------------------------------------------------------------- |
| `filePath` | `string` | No | Path to the file to diff. Defaults to current file in editor. |
| `originalSource` | `string` | Yes | Original source code to compare against |
| `newSource` | `string` | Yes | New source code to compare with |
| `showActionButtons` | `boolean` | No | Whether to show action buttons for chunk acceptance (default: `true`) |

## Architecture

### Diff Strategies

The extension provides two diff viewing strategies:

- **Split diff** (`split-cell-diff`): Uses CodeMirror's two-pane view. Displays original and modified code side-by-side in separate panels with diff highlighting.

- **Unified diff** (`unified-cell-diff`/`unified-file-diff`): Uses CodeMirror's `unifiedMergeView`. Displays changes in a single unified view with added/removed lines clearly marked. Can be used for both cell diffs and regular file diffs.

## Uninstall

To remove the extension, execute:
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,15 @@
},
"dependencies": {
"@codemirror/lang-python": "^6.2.1",
"@codemirror/merge": "^6.10.2",
"@codemirror/merge": "^6.11.0",
"@codemirror/view": "^6.38.2",
"@jupyter/ydoc": "^3.1.0",
"@jupyterlab/application": "^4.0.0",
"@jupyterlab/cells": "^4.0.0",
"@jupyterlab/codeeditor": "^4.0.0",
"@jupyterlab/codemirror": "^4.4.7",
"@jupyterlab/coreutils": "^6.0.0",
"@jupyterlab/fileeditor": "^4.0.0",
"@jupyterlab/notebook": "^4.0.0",
"@jupyterlab/services": "^7.0.0",
"@jupyterlab/translation": "^4.0.0",
Expand Down
Loading
Loading