### Virtualenv Setup with Node.js (Python 3.5 Example) Source: https://github.com/jupyter/nbdime/blob/main/docs/source/nodevenv.md This example shows the command sequence and expected output when setting up a virtual environment with Node.js for Python 3.5. ```bash $ python -m venv myenv $ source myenv/bin/activate (myenv) $ pip install nodeenv Collecting nodeenv Downloading nodeenv-1.0.0.tar.gz Installing collected packages: nodeenv Running setup.py install for nodeenv ... done Successfully installed nodeenv-1.0.0 (myenv) $ nodeenv -p * Install prebuilt node (7.2.0) ..... done. * Appending data to /Users/username/myenv/bin/activate (myenv) $ ``` -------------------------------- ### Install Test Dependencies Source: https://github.com/jupyter/nbdime/blob/main/docs/source/testing.md Install all necessary dependencies for testing nbdime. Ensure you have the test extras installed. ```bash pip install .[test] ``` -------------------------------- ### Install Test Dependencies Source: https://github.com/jupyter/nbdime/blob/main/ui-tests/README.md Installs necessary dependencies for running Playwright tests and installs the Playwright browsers. This is typically a one-time setup. ```sh cd ./ui-tests npm install npx playwright install cd .. ``` -------------------------------- ### Install Python Packaging Tools Source: https://github.com/jupyter/nbdime/blob/main/RELEASE.md Install necessary tools for Python packaging. Ensure you have Python and pip installed. ```bash pip install build twine hatch ``` -------------------------------- ### Create and Activate Virtualenv with Node.js Source: https://github.com/jupyter/nbdime/blob/main/docs/source/nodevenv.md Use this sequence to create a virtual environment, activate it, install nodeenv, and then install Node.js within the virtualenv. ```bash python -m venv myenv source myenv/bin/activate pip install nodeenv nodeenv -p ``` -------------------------------- ### Matplotlib Plotting Example Source: https://github.com/jupyter/nbdime/blob/main/nbdime/tests/files/mixed-conflicts--2.ipynb Demonstrates basic plotting with matplotlib, including creating figures, plotting sine and exponential functions, and printing a message. Requires matplotlib to be installed and configured for inline display. ```python %matplotlib inline from pylab import * figure(1) x = [1, 2, 5] plot(x, sin(x)) x = [0, 1, 4] plot(x, exp(x)) print("No conflict at beginning or end here.") figure(2) plot([1,2,3], [1,3,2]) ``` ```text Output: No conflict at beginning or end here. ``` ```text Result: [] ``` ```text Result: ``` ```text Result: ``` -------------------------------- ### Development Install nbdime Source: https://github.com/jupyter/nbdime/blob/main/README.md Install a development version of nbdime using pip. This requires npm to be installed and available on your PATH. See the documentation for additional details on development installs. ```bash pip install -e git+https://github.com/jupyter/nbdime#egg=nbdime ``` -------------------------------- ### Install and Enable nbdime Notebook Extension Source: https://github.com/jupyter/nbdime/blob/main/docs/source/extensions.md Installs and enables the nbdime frontend extension for classic Jupyter notebooks. Use --sys-prefix for virtual environments, --user for the current user, or --system for all users. ```bash jupyter nbextension install --py nbdime [--sys-prefix/--user/--system] jupyter nbextension enable --py nbdime [--sys-prefix/--user/--system] ``` -------------------------------- ### Matplotlib Plotting Example Source: https://github.com/jupyter/nbdime/blob/main/nbdime/tests/files/mixed-conflicts--3.ipynb Demonstrates basic plotting with matplotlib in Python, including setting up the environment, plotting sine and tangent functions, and creating a second figure. This snippet requires the matplotlib library to be installed and configured. ```python %matplotlib inline from pylab import * figure(1) x = [0, 2, 3] plot(x, sin(x)) x = [1, 2, 4] plot(x, tan(x)) print("No conflict at beginning or end here.") figure(2) plot([1,2,3], [1,3,2]) ``` ```text Output: No conflict at beginning or end here. ``` ```text Result: [] ``` ```text Result: ``` ```text Result: ``` -------------------------------- ### Install Development Version from Cloned Repository Source: https://github.com/jupyter/nbdime/blob/main/docs/source/installing.md Clone the nbdime repository and then use pip to install the development version. This approach is useful if you plan to make modifications to the source code. ```bash git clone https://github.com/jupyter/nbdime cd nbdime pip install -e '.[test,docs]' ``` -------------------------------- ### Install nbdime with pip Source: https://github.com/jupyter/nbdime/blob/main/README.md Use this command to install the nbdime package using pip. For more details, refer to the installation documentation. ```bash pip install nbdime ``` -------------------------------- ### Compile Extension Source: https://github.com/jupyter/nbdime/blob/main/ui-tests/README.md Installs dependencies and builds the extension. This is a prerequisite for most testing operations. ```sh npm install npm run build ``` -------------------------------- ### Start Server for Test Creation Source: https://github.com/jupyter/nbdime/blob/main/ui-tests/README.md Starts the development server, which is necessary before using the Playwright code generator. ```sh cd ./ui-tests npm start ``` -------------------------------- ### Example NbDiff Configuration Source: https://github.com/jupyter/nbdime/blob/main/docs/source/config.md A sample JSON configuration file for NbDiff, demonstrating how to set options like 'details'. ```default { "NbDiff": { "details": false } } ``` -------------------------------- ### Use Mercurial Diff Tools Source: https://github.com/jupyter/nbdime/blob/main/docs/source/vcs.md Examples of how to invoke nbdime's diff tools from Mercurial after configuration. ```bash hg nbdiff ``` ```bash hg nbdiffweb ``` -------------------------------- ### Install nbdime JupyterLab Extension Source: https://github.com/jupyter/nbdime/blob/main/docs/source/extensions.md Installs the nbdime extension for JupyterLab. ```bash jupyter labextension install nbdime-jupyterlab ``` -------------------------------- ### Install Latest Stable Release with Pip Source: https://github.com/jupyter/nbdime/blob/main/docs/source/installing.md Use this command to install the most recent stable version of nbdime. This command also installs and enables the necessary server, notebook, and jupyterlab extensions. ```bash pip install --upgrade nbdime ``` -------------------------------- ### Install Test Requirements Source: https://github.com/jupyter/nbdime/blob/main/README.md Install the necessary test requirements for nbdime using pip. This command includes the test extra. ```bash pip install nbdime[test] ``` -------------------------------- ### Install Development Version from Source (Direct) Source: https://github.com/jupyter/nbdime/blob/main/docs/source/installing.md Install the latest development version of nbdime directly from its GitHub repository using pip. This method installs the Python package and automatically handles Node.js package dependencies. ```bash pip install -e git+https://github.com/jupyter/nbdime#egg=nbdime ``` -------------------------------- ### Example Output Source: https://github.com/jupyter/nbdime/blob/main/nbdime/tests/files/apap--2.ipynb This represents a typical output from a code execution, showing a matplotlib figure object. ```text Result: ``` -------------------------------- ### Python Example Code Source: https://github.com/jupyter/nbdime/blob/main/nbdime/tests/files/apap--2.ipynb This is a sample Python code block used for testing purposes. ```python Some lines To help with Alignment Another one bites the dust ``` -------------------------------- ### Common Path Example - Local Changes Source: https://github.com/jupyter/nbdime/blob/main/docs/source/merging.md Illustrates the 'patch' and 'addrange' operations for local changes within a notebook's cells, specifically focusing on source and outputs. ```default patch "cells" ┗━┓ patch index 0 ┣━┓ patch "source" ┃ ┗━ addrange ┗━┓ patch "outputs" ┗━ addrange ``` -------------------------------- ### Enable nbdime Extensions Source: https://github.com/jupyter/nbdime/blob/main/docs/source/installing.md If extensions did not install or enable automatically, use this command to enable them. The flags determine the scope of the enable operation. ```bash nbdime extensions --enable [--sys-prefix/--user/--system] ``` -------------------------------- ### Python Code Example Source: https://github.com/jupyter/nbdime/blob/main/nbdime/tests/files/apap--3.ipynb A sample Python code block used for testing alignment and diffing. ```python Some lines To help with Alignment War! What is it good for? ``` -------------------------------- ### Enable nbdime Extensions Source: https://github.com/jupyter/nbdime/blob/main/docs/source/extensions.md Installs and enables all nbdime extensions for Jupyter. Use --sys-prefix for virtual environments, --user for the current user, or --system for all users. ```bash nbdime extensions --enable [--sys-prefix/--user/--system] ``` -------------------------------- ### Common Path Example - Remote Changes Source: https://github.com/jupyter/nbdime/blob/main/docs/source/merging.md Shows the 'patch' and 'removerange' operations for remote changes to a notebook's cells, focusing on the removal of outputs. ```default patch "cells" ┗━┓ patch index 0 ┗━┓ patch "outputs" ┗━ removerange ``` -------------------------------- ### Display Jupyter Paths Source: https://github.com/jupyter/nbdime/blob/main/docs/source/extensions.md Prints the paths Jupyter uses for configuration and data. Useful for troubleshooting extension installation issues. ```bash jupyter --paths ``` -------------------------------- ### Upload Python Package to PyPI Source: https://github.com/jupyter/nbdime/blob/main/RELEASE.md Upload the built Python packages from the dist/ directory to the Python Package Index (PyPI). Ensure twine is installed. ```bash twine upload dist/* ``` -------------------------------- ### Comment Example Source: https://github.com/jupyter/nbdime/blob/main/ui-tests/data/diff_test1/left.ipynb This snippet shows a single-line comment in Python. Comments are ignored by the interpreter and used for code explanation. ```python # one comment ``` -------------------------------- ### Python Syntax Error Example Source: https://github.com/jupyter/nbdime/blob/main/nbdime/tests/files/mixed-conflicts--2.ipynb Illustrates a common Python syntax error. This snippet is intended to show how invalid syntax is reported. ```python test 2 hello 2 more text 2 world 2 ``` ```text File "", line 1 test 2 ^ SyntaxError: invalid syntax ``` -------------------------------- ### Python NameError Example Source: https://github.com/jupyter/nbdime/blob/main/nbdime/tests/files/mixed-conflicts--1.ipynb Illustrates a NameError in Python when a variable is used before assignment. ```python NameError Traceback (most recent call last) in () 1 test ----> 2 hello 3 more 4 text 5 world NameError: name 'hello' is not defined ``` -------------------------------- ### Matplotlib Plotting Example Source: https://github.com/jupyter/nbdime/blob/main/nbdime/tests/files/mixed-conflicts--1.ipynb Uses matplotlib to generate two plots: a sine wave and a cosine wave. Requires '%matplotlib inline' for display in a notebook. ```python %matplotlib inline from pylab import * figure(1) x = [1, 2, 3] plot(x, sin(x)) x = [0, 2, 4] plot(x, cos(x)) print("No conflict at beginning or end here.") figure(2) plot([1,2,3], [1,3,2]) ``` -------------------------------- ### Merge Ignore Configurations Source: https://github.com/jupyter/nbdime/blob/main/docs/source/config.md Configurations from different sections are merged. More specific paths override general ones. This example shows merging 'Diff' and 'GitDiff' ignore settings. ```default { "Diff": { "Ignore": { "/metadata": ["foo"], "/cells/*/metadata": ["tags"] } }, "GitDiff": { "Ignore": { "/cells/*/outputs": true, "/cells/*/metadata": ["collapsed", "autoscroll", "deletable", "editable"] } } } ``` -------------------------------- ### Python Syntax Error Example Source: https://github.com/jupyter/nbdime/blob/main/nbdime/tests/files/mixed-conflicts--3.ipynb Illustrates a Python SyntaxError due to invalid syntax. This snippet shows how an incorrect statement is flagged. ```python test 3 hello 3 more text 3 world 3 ``` ```text File "", line 1 test 3 ^ SyntaxError: invalid syntax ``` -------------------------------- ### Upgrade Playwright and Browsers Source: https://github.com/jupyter/nbdime/blob/main/ui-tests/README.md Updates the Playwright test runner package to the latest version and installs the corresponding browser binaries. ```sh cd ./ui-tests npm up "@playwright/test" npx playwright install ``` -------------------------------- ### Import Necessary Libraries Source: https://github.com/jupyter/nbdime/blob/main/ui-tests/data/merge_test3/left.ipynb Imports common Python libraries used for data manipulation, web requests, and file handling. Ensure these libraries are installed before running the code. ```python import pandas as pd import altair as alt import requests import zipfile import numpy as np ``` -------------------------------- ### Develop Jupyter Lab Extension Locally Source: https://github.com/jupyter/nbdime/blob/main/docs/source/installing.md Use this command to develop the Jupyter Lab extension locally. It's recommended to run this after a pip development install if you are working on the front-end code. ```bash jupyter labextension develop --overwrite . ``` -------------------------------- ### Run Python 3 Tests with Pytest Source: https://github.com/jupyter/nbdime/blob/main/docs/source/testing.md Explicitly run the Python test suite using the python3 interpreter. Use this if you have multiple Python versions installed and want to target Python 3. ```bash python3 -m pytest ``` -------------------------------- ### Download Large Files with Requests Source: https://github.com/jupyter/nbdime/blob/main/ui-tests/data/merge_test5/right.ipynb Use this snippet to download files from URLs in chunks. Ensure the 'requests' library is installed and the target directory exists. This method is suitable for large files as it avoids loading the entire file into memory. ```python # Download the data from the EPA website data_file_urls = [ 'https://aqs.epa.gov/aqsweb/airdata/daily_88101_2017.zip', 'https://aqs.epa.gov/aqsweb/airdata/daily_88101_2018.zip', ] # copied this example from https://stackoverflow.com/questions/16694907/download-large-file-in-python-with-requests for url in data_file_urls: local_filename = "data/{}".format(url.split('/')[-1]) with requests.get(url, stream=True) as t: t.raise_for_status() with open(local_filename, 'wb') as f: for chunk in t.iter_content(chunk_size=8192): f.write(chunk) ``` -------------------------------- ### Generate Plot with Matplotlib and NumPy Source: https://github.com/jupyter/nbdime/blob/main/examples/example6/left.ipynb This snippet generates a plot using Matplotlib and NumPy. Ensure these libraries are installed. ```python from matplotlib import pyplot as plt import numpy as np x = np.linspace(0, 2, 10) z = np.exp(x + 2) plt.plot(x, z, 'c') # this is an example ``` -------------------------------- ### Download Large Files with Requests Source: https://github.com/jupyter/nbdime/blob/main/ui-tests/data/merge_test5/left.ipynb Use this snippet to download large files from a list of URLs. It downloads files in chunks to manage memory efficiently and saves them locally. Ensure the `requests` library is installed. ```python # Download the data from the EPA website data_file_urls = [ 'https://aqs.epa.gov/aqsweb/airdata/daily_88101_2020.zip', 'https://aqs.epa.gov/aqsweb/airdata/daily_88101_2019.zip', 'https://aqs.epa.gov/aqsweb/airdata/daily_88101_2021.zip', 'https://aqs.epa.gov/aqsweb/airdata/daily_88101_2022.zip', ] # copied this example from https://stackoverflow.com/questions/16694907/download-large-file-in-python-with-requests for url in data_file_urls: local_filename = "data/{}".format(url.split('/')[-1]) with requests.get(url, stream=True) as r: r.raise_for_status() with open(local_filename, 'wb') as f: for chunk in r.iter_content(chunk_size=8192): f.write(chunk) ``` -------------------------------- ### Plot Exponential Function with Matplotlib Source: https://github.com/jupyter/nbdime/blob/main/ui-tests/data/merge_test1/right.ipynb Generates and plots an exponential function using NumPy and Matplotlib. Ensure NumPy and Matplotlib are installed. ```python import numpy as np import matplotlib.pyplot as plt x = np.arange(0, 2, 0.1) y = np.exp(2 * x) plt.plot(x,y) ``` -------------------------------- ### Display All Config Options Source: https://github.com/jupyter/nbdime/blob/main/docs/source/config.md Use this command to list all available configuration options and their current effective values. ```default nbdime --config ``` -------------------------------- ### Plot Exponential Curve with Matplotlib Source: https://github.com/jupyter/nbdime/blob/main/ui-tests/data/merge_test1/left.ipynb Generates data points for an exponential curve using NumPy and plots it using Matplotlib. Requires NumPy and Matplotlib to be installed. ```python import numpy as np import matplotlib.pyplot as plt x = np.arange(0, 2, 0.1) y = np.exp(x + 2) plt.plot(x,y) ``` -------------------------------- ### Apply Config via CLI Flag Source: https://github.com/jupyter/nbdime/blob/main/docs/source/config.md Demonstrates how to use the `--config` flag with specific nbdime CLI entry points to apply configuration. ```default nbdiff --config ``` ```default nbmerge --config ``` -------------------------------- ### Plot Exponential Curve with Matplotlib Source: https://github.com/jupyter/nbdime/blob/main/examples/example6/center.ipynb Generates data points for an exponential curve using NumPy and plots it using Matplotlib. Ensure Matplotlib and NumPy are installed. ```python from matplotlib import pyplot as plt import numpy as np x = np.arange(0, 2, 0.1) y1 = np.exp(x) plt.plot(x, y1, 'b') ``` -------------------------------- ### View Rich Web-Based Notebook Diffs Source: https://github.com/jupyter/nbdime/blob/main/docs/source/index.md Launch a web-based rendering of notebook differences using the nbdiff-web command. ```default nbdiff-web notebook_1.ipynb notebook_2.ipynb ``` -------------------------------- ### Build Python Package Source: https://github.com/jupyter/nbdime/blob/main/RELEASE.md Create a Python source package (.tar.gz) and a binary wheel package (.whl) in the dist/ directory. This command replaces the deprecated 'python setup.py sdist bdist_wheel'. ```bash python -m build ``` -------------------------------- ### Full Configuration Output Source: https://github.com/jupyter/nbdime/blob/main/docs/source/config.md The output of `nbdime --config` shows all configurable options across different nbdime components and their current settings. ```none All available config options, and their current values: NbDiff: Ignore: {} attachments: null color_words: false text_similarity_ignore_whitespace: true text_similarity_threshold: 0.3 details: null metadata: null outputs: null sources: null NbDiffWeb: Ignore: {} attachments: null base_url: "/" browser: null color_words: false text_similarity_ignore_whitespace: true text_similarity_threshold: 0.3 details: null ip: "127.0.0.1" metadata: null outputs: null persist: false port: 0 sources: null workdirectory: "" NbMerge: Ignore: {} attachments: null color_words: false text_similarity_ignore_whitespace: true text_similarity_threshold: 0.3 details: null ignore_transients: true input_strategy: null merge_strategy: "inline" metadata: null output_strategy: null outputs: null sources: null NbMergeWeb: Ignore: {} attachments: null base_url: "/" browser: null color_words: false text_similarity_ignore_whitespace: true text_similarity_threshold: 0.3 details: null ignore_transients: true input_strategy: null ip: "127.0.0.1" merge_strategy: "inline" metadata: null output_strategy: null outputs: null persist: false port: 0 sources: null workdirectory: "" NbShow: Ignore: {} attachments: null details: null metadata: null outputs: null sources: null Server: base_url: "/" browser: null ip: "127.0.0.1" persist: false port: 8888 workdirectory: "" Extension: Ignore: {} attachments: null color_words: false text_similarity_ignore_whitespace: true text_similarity_threshold: 0.3 details: null metadata: null outputs: null sources: null NbDiffDriver: Ignore: {} attachments: null color_words: false text_similarity_ignore_whitespace: true text_similarity_threshold: 0.3 details: null metadata: null outputs: null sources: null NbDiffTool: Ignore: {} attachments: null base_url: "/" browser: null color_words: false text_similarity_ignore_whitespace: true text_similarity_threshold: 0.3 details: null ip: "127.0.0.1" metadata: null outputs: null persist: false port: 0 sources: null workdirectory: "" NbMergeDriver: Ignore: {} attachments: null color_words: false text_similarity_ignore_whitespace: true text_similarity_threshold: 0.3 details: null ignore_transients: true input_strategy: null merge_strategy: "inline" metadata: null output_strategy: null outputs: null sources: null NbMergeTool: Ignore: {} attachments: null base_url: "/" browser: null color_words: false text_similarity_ignore_whitespace: true text_similarity_threshold: 0.3 details: null ignore_transients: true input_strategy: null ip: "127.0.0.1" merge_strategy: "inline" metadata: null output_strategy: null outputs: null persist: false port: 0 sources: null workdirectory: "" ``` -------------------------------- ### Define Squaring Function Source: https://github.com/jupyter/nbdime/blob/main/nbdime/tests/files/cellids--remote.ipynb Defines a simple Python function to square a number. This is a basic building block for subsequent examples. ```python def f(x): return x**2 ``` -------------------------------- ### Enable Git Integration Source: https://github.com/jupyter/nbdime/blob/main/docs/source/index.md Configure Git to use nbdime for improved diffing and merging of Jupyter notebooks. This command enables both drivers and tools globally. ```default nbdime config-git --enable --global ``` -------------------------------- ### Launch Web-Based Merge Tool Source: https://github.com/jupyter/nbdime/blob/main/docs/source/vcs.md Use nbdime's web-based GUI viewer for merge conflict resolution. This command can be aliased as `nbdime mergetool`. ```bash git mergetool --tool nbdime -- *.ipynb ``` -------------------------------- ### Enable Git Diff Driver Source: https://github.com/jupyter/nbdime/blob/main/docs/source/vcs.md Register the nbdime diff driver with Git. This command associates the driver with the `.ipynb` file extension. ```bash git-nbdiffdriver config --enable [--global | --system] ``` -------------------------------- ### Plot Exponential Function with Matplotlib Source: https://github.com/jupyter/nbdime/blob/main/ui-tests/data/diff_test1/center.ipynb Generates and plots the exponential function y = e^x using NumPy and Matplotlib. Ensure NumPy and Matplotlib are installed. ```python import numpy as np import matplotlib.pyplot as plt x = np.arange(0, 2, 0.1) y = np.exp(x) plt.plot(x,y) ``` -------------------------------- ### Enable nbdime Server Extension Source: https://github.com/jupyter/nbdime/blob/main/docs/source/extensions.md Enables the nbdime Python server extension. Use --sys-prefix for virtual environments, --user for the current user, or --system for all users. ```bash jupyter serverextension enable --py nbdime [--sys-prefix/--user/--system] ``` -------------------------------- ### Register Git Merge Driver via Command Line Source: https://github.com/jupyter/nbdime/blob/main/docs/source/vcs.md Enables the nbdime merge driver for .ipynb files using git. Use --global or --system flags to specify the configuration scope. ```bash git-nbmergedriver config --enable [--global | --system] ``` -------------------------------- ### Assign and Evaluate Variable (First Instance) Source: https://github.com/jupyter/nbdime/blob/main/nbdime/tests/files/cellids--remote.ipynb Assigns a value to a variable and then calls the squaring function. Demonstrates a basic computation flow. ```python x = 3 ``` ```python f(x) ``` ```text Result: 9 ``` -------------------------------- ### NPM Package Publishing Source: https://github.com/jupyter/nbdime/blob/main/RELEASE.md Log in to NPM and publish the frontend part of the extension as a public NPM package. Ensure you have an NPM account and are logged in. ```bash npm login npm publish --access public ``` -------------------------------- ### Plotting a Noisy Gaussian Curve with Matplotlib Source: https://github.com/jupyter/nbdime/blob/main/examples/example7/center.ipynb Generates and plots a Gaussian curve with added random noise. Requires NumPy and Matplotlib. Ensure these libraries are installed. ```python import numpy as np import matplotlib.pyplot as plt def gaussian(x, a, b, c): return a * np.exp(-b * (x-c)**2) def noisy_gaussian(): nx = 100 x = np.linspace(-5.0, 5.0, nx) y = gaussian(x, a=2.0, b=0.5, c=1.5) noise = np.random.normal(0.0, 0.2, nx) return x, y def plot(x, y): plt.plot(x, y, "r", label="Data") plt.legend() plt.ylim(-0.5, 2.5) plt.show() x, y = noisy_gaussian() plot(x, y) ``` -------------------------------- ### Manually Resolve Conflicts with nbmerge-web Source: https://github.com/jupyter/nbdime/blob/main/docs/source/cli.md Launch a web application for manually resolving notebook merge conflicts using nbmerge-web. Specify the output file with the --out option. ```bash nbmerge-web base.ipynb local.ipynb remote.ipynb --out merged.ipynb ``` -------------------------------- ### Launch Web-Based Merge Tool Source: https://github.com/jupyter/nbdime/blob/main/docs/source/index.md Open nbdime's web-based merge tool to visualize and resolve merge conflicts in Jupyter notebooks. This tool provides a user-friendly interface for conflict resolution. ```default nbdime mergetool ``` -------------------------------- ### Define and Call Addition Function in Python Source: https://github.com/jupyter/nbdime/blob/main/nbdime/tests/files/foo--2.ipynb Defines a simple Python function 'foo' that performs addition and then calls it with specific arguments. ```python def foo(x, y): return x + y foo(1, 2) ``` ```text 3 ``` -------------------------------- ### Execute and Plot Fitting Source: https://github.com/jupyter/nbdime/blob/main/examples/example7/left.ipynb Generates noisy Gaussian data, fits a 5th-order polynomial to it, and then plots the original data against the fitted curve. ```python x, y = noisy_gaussian() yfit = fit(x, y, n=5) # fit a 5th order polynomial to it plot(x, y, yfit) ``` -------------------------------- ### Run JavaScript/TypeScript Tests Source: https://github.com/jupyter/nbdime/blob/main/docs/source/testing.md Execute the JavaScript and TypeScript test suite using npm. This command is used for testing the frontend or Node.js related parts of the project. ```bash npm test ``` -------------------------------- ### Plotting Exponential and Linear Functions with Matplotlib Source: https://github.com/jupyter/nbdime/blob/main/examples/example6/right.ipynb This snippet generates two plots: an exponential curve and a linear curve, both using numpy for data generation and matplotlib for plotting. Ensure matplotlib and numpy are installed. ```python from matplotlib import pyplot as plt import numpy as np import math import pandas x = np.arange(0, 2, 0.1) y2 = np.exp(x) plt.plot(x, y2, 'b') y1 = y2 plt.plot(x, y1, 'g') # this is easy ``` -------------------------------- ### Output New Result (Text) Source: https://github.com/jupyter/nbdime/blob/main/nbdime/tests/files/src-and-output--1.ipynb Represents the textual output after x has been reassigned, showing the new value. ```text Result: 5 ``` -------------------------------- ### Generate, Fit, and Plot Data Source: https://github.com/jupyter/nbdime/blob/main/examples/example7/right.ipynb Orchestrates the process of generating noisy Gaussian data, fitting it with a 5th order polynomial, and then plotting the results. Assumes a `fit` function is available. ```python x, y = noisy_gaussian() yfit = fit(x, y, n=5) # fit a 5th order polynomial to it plot(x, y, yfit) ``` -------------------------------- ### Assign and Evaluate Variable (Second Instance) Source: https://github.com/jupyter/nbdime/blob/main/nbdime/tests/files/cellids--remote.ipynb Reassigns a value to the same variable and calls the squaring function again. Shows how variable reassignment affects the output. ```python x = 7 ``` ```python f(x) ``` ```text Result: 49 ``` -------------------------------- ### Placeholder Comment Source: https://github.com/jupyter/nbdime/blob/main/examples/example8/left.ipynb A simple placeholder comment. ```python # one ``` -------------------------------- ### Configure Ignored Paths Source: https://github.com/jupyter/nbdime/blob/main/docs/source/config.md Use the 'Ignore' key to specify paths to ignore. 'true'/'false' configure entire lists/maps, while lists specify keys to ignore within maps. ```default "Ignore": { "/cells/*/outputs": true, "/cells/*/attachments": false, "/cells/*/metadata": ["collapsed", "autoscroll", "deletable", "editable"] } ``` -------------------------------- ### Download and Unzip Data Files Source: https://github.com/jupyter/nbdime/blob/main/ui-tests/data/merge_test3/left.ipynb Downloads zip-compressed data files from a list of URLs and extracts their contents. This is useful for obtaining datasets that are too large to store directly in a repository. The code handles downloading in chunks to manage memory usage and then unzips the downloaded files. ```python # Download the data from the EPA website data_file_urls = [ 'https://aqs.epa.gov/aqsweb/airdata/daily_88101_2020.zip', 'https://aqs.epa.gov/aqsweb/airdata/daily_88101_2019.zip', 'https://aqs.epa.gov/aqsweb/airdata/daily_88101_2018.zip' ] # copied this example from https://stackoverflow.com/questions/16694907/download-large-file-in-python-with-requests for url in data_file_urls: local_filename = "data/{}".format(url.split('/')[-1]) with requests.get(url, stream=True) as r: r.raise_for_status() with open(local_filename, 'wb') as f: for chunk in r.iter_content(chunk_size=8192): f.write(chunk) # and unzip the files files_to_unzip = ["data/{}".format(url.split('/')[-1]) for url in data_file_urls] for f in files_to_unzip: with zipfile.ZipFile(f,"r") as zip_ref: zip_ref.extractall("data") ``` -------------------------------- ### Enable nbdime Jupyter Server Extension Source: https://github.com/jupyter/nbdime/blob/main/docs/source/installing.md Enable the nbdime server extension for Jupyter Lab or nbclassic. This command is necessary when developing the server extension. ```bash jupyter server extension enable nbdime ``` -------------------------------- ### Unzip Downloaded Files with Zipfile Source: https://github.com/jupyter/nbdime/blob/main/ui-tests/data/merge_test5/center.ipynb This snippet extracts the contents of downloaded zip files. Ensure the zip files are present in the specified directory before running. ```python # and unzip the files files_to_unzip = ["data/{}".format(url.split('/')[-1]) for url in data_file_urls] for f in files_to_unzip: with zipfile.ZipFile(f,"r") as zip_ref: zip_ref.extractall("data") ``` -------------------------------- ### Download and unzip data files Source: https://github.com/jupyter/nbdime/blob/main/ui-tests/data/merge_test3/center.ipynb Downloads data files from a list of URLs and extracts their contents. This is useful for obtaining data from remote sources and preparing it for analysis. Ensure the 'data' directory exists before running. ```python # Download the data from the EPA website data_file_urls = [ 'https://aqs.epa.gov/aqsweb/airdata/daily_88101_2020.zip', 'https://aqs.epa.gov/aqsweb/airdata/daily_88101_2019.zip', ] # copied this example from https://stackoverflow.com/questions/16694907/download-large-file-in-python-with-requests for url in data_file_urls: local_filename = "data/{}".format(url.split('/')[-1]) with requests.get(url, stream=True) as r: r.raise_for_status() with open(local_filename, 'wb') as f: for chunk in r.iter_content(chunk_size=8192): f.write(chunk) # and unzip the files files_to_unzip = ["data/{}".format(url.split('/')[-1]) for url in data_file_urls] for f in files_to_unzip: with zipfile.ZipFile(f,"r") as zip_ref: zip_ref.extractall("data") ``` -------------------------------- ### Register Git Merge Tool via Command Line Source: https://github.com/jupyter/nbdime/blob/main/docs/source/vcs.md Registers nbdime as a git merge tool. Use --global or --system flags for scope. The --set-default flag makes nbdime the default tool for all merge conflicts. ```bash git-nbmergetool config --enable [--global | --system] ``` ```bash git mergetool --tool=nbdime […​] ``` ```bash git-nbmergetool config --enable --set-default [--global | --system] ``` ```bash git mergetool […​] ``` -------------------------------- ### PyPI Token Map Configuration Source: https://github.com/jupyter/nbdime/blob/main/RELEASE.md Configure a secret named PYPI_TOKEN_MAP for advanced usage when releasing multiple repositories or packages within the same repository. This allows mapping specific repository paths to their corresponding tokens. ```text owner1/repo1,token1 owner2/repo2,token2 owner1/repo1/path/to/package1,token1 owner1/repo1/path/to/package2,token2 ``` -------------------------------- ### Run Python Tests with Pytest Source: https://github.com/jupyter/nbdime/blob/main/docs/source/testing.md Execute the Python test suite from the project root using pytest. This command runs tests with the default Python interpreter. ```bash pytest ``` -------------------------------- ### Manually Register Git Merge Driver Source: https://github.com/jupyter/nbdime/blob/main/docs/source/vcs.md Manually configures git to use nbdime for merging notebooks. This involves adding entries to .gitconfig and .gitattributes files. ```gitconfig [merge "jupyternotebook"] command = git-nbmergedriver merge %O %A %B %L %P ``` ```gitattributes *.ipynb merge=jupyternotebook ``` -------------------------------- ### Import Matplotlib and Enable Inline Plotting Source: https://github.com/jupyter/nbdime/blob/main/nbdime/tests/files/output-conflict--2.ipynb Imports necessary functions from matplotlib and configures the environment to display plots directly within the notebook. ```python from matplotlib.pylab import * %matplotlib inline ``` -------------------------------- ### Manual Git Diff Driver Registration Source: https://github.com/jupyter/nbdime/blob/main/docs/source/vcs.md Manually register the nbdime diff driver with Git by adding entries to `.gitconfig` and `.gitattributes` files. ```gitconfig [diff "jupyternotebook"] command = git-nbdiffdriver diff ``` ```gitconfig [diff "jupyternotebook"] command = git-nbdiffdriver webdiff [--ip IP] ``` ```gitattributes *.ipynb diff=jupyternotebook ``` -------------------------------- ### Generate and Plot Sine Wave Source: https://github.com/jupyter/nbdime/blob/main/nbdime/tests/files/output-conflict--2.ipynb Creates a sequence of x values, calculates the corresponding y values for a sine wave, and then plots the resulting curve. ```python x = linspace(0, end, 100) y = sin(x) plot(x, y) ``` -------------------------------- ### Initialize and Modify String Source: https://github.com/jupyter/nbdime/blob/main/ui-tests/data/merge_test6/center.ipynb Initializes a string variable and modifies it. This is the first cell in the initial commit. ```python # This is the first cell in the initial commit a = "hello the world" a ``` ```text Result: 'hello the world' ``` -------------------------------- ### Call a function and display result Source: https://github.com/jupyter/nbdime/blob/main/nbdime/tests/files/cellids--base.ipynb Calls the previously defined function 'f' with the variable 'x' and displays the computed result. ```python f(x) ``` -------------------------------- ### API Request: Compute Notebook Diff Source: https://github.com/jupyter/nbdime/blob/main/docs/source/restapi.md Use this endpoint to compute the difference between two Jupyter notebooks. Provide notebook paths as local filenames or URLs. ```json { "base": "filename.ipynb" | "http://your-domain/url/path", "remote": "filename.ipynb" | "http://your-domain/url/path" } ``` -------------------------------- ### Configure Mercurial Merge Tools Source: https://github.com/jupyter/nbdime/blob/main/docs/source/vcs.md Configures Mercurial to use nbdime for merging notebooks, including both a standard merge driver and a web-based GUI tool. It also sets merge patterns to use nbdime for .ipynb files. ```hgconfig [merge-tools] nbdime.priority = 2 nbdime.premerge = False nbdime.executable = hg-nbmerge nbdime.args = $base $local $other $output nbdimeweb.priority = 1 nbdimeweb.premerge = False nbdimeweb.executable = hg-nbmergeweb nbdimeweb.args = --log-level ERROR $base $local $other $output nbdimeweb.gui = True [merge-patterns] **.ipynb = nbdime ``` -------------------------------- ### Generate Playwright Tests Source: https://github.com/jupyter/nbdime/blob/main/ui-tests/README.md Launches the Playwright code generator to create new tests by interacting with the application. Ensure the server is running. ```sh cd ./ui-tests npm playwright codegen localhost:8888 ``` -------------------------------- ### Run Playwright Tests Source: https://github.com/jupyter/nbdime/blob/main/ui-tests/README.md Executes the Playwright integration tests. Test results are shown in the terminal, and a report is generated for failures. ```sh cd ./ui-tests npx playwright test ``` -------------------------------- ### Handle ZeroDivisionError in Python Source: https://github.com/jupyter/nbdime/blob/main/nbdime/tests/files/error--2.ipynb This snippet demonstrates a ZeroDivisionError that occurs when attempting to divide by zero. It shows the Python code that triggers the error and the resulting traceback. ```python print("the value is", 0/0+0) ``` ```text --------------------------------------------------------------------------- ZeroDivisionError Traceback (most recent call last) in () ----> 1 print("the value is", 0/0+0) ZeroDivisionError: division by zero ``` -------------------------------- ### Disable and Uninstall nbdime Notebook Extension Source: https://github.com/jupyter/nbdime/blob/main/docs/source/extensions.md Disables and uninstalls the nbdime frontend extension for classic Jupyter notebooks. Use --sys-prefix for virtual environments, --user for the current user, or --system for all users. ```bash jupyter nbextension disable --py nbdime [--sys-prefix/--user/--system] jupyter nbextension uninstall --py nbdime [--sys-prefix/--user/--system] ``` -------------------------------- ### Placeholder for 'five' Source: https://github.com/jupyter/nbdime/blob/main/examples/example4/center.ipynb This snippet appears to be a placeholder or incomplete code. Its functionality is not defined. ```python five ``` -------------------------------- ### API Response: Notebook Merge Decisions Source: https://github.com/jupyter/nbdime/blob/main/docs/source/restapi.md The response contains the base notebook and the merge decisions, as specified in the merge details documentation. ```json { "base": json_notebook, "merge_decisions": json_merge_decisions } ``` -------------------------------- ### Import Libraries for Data Handling Source: https://github.com/jupyter/nbdime/blob/main/ui-tests/data/merge_test3/right.ipynb Imports common Python libraries used for data manipulation and web requests. It's standard practice to alias pandas as 'pd' and superior as 'sup'. Requests is used for downloading data, and tarfile for de-compressing archives. ```python import pandas as pd # programmers like shortening names for things, so they usually import pandas as "pd" import superior as sup # again with the shortening of names import requests # we use it for downloading the data so we don't have to save it on GitHub (too big!) import tarfile # for de-compressing the files we download from the EPA ``` -------------------------------- ### Configure Git Integration Source: https://github.com/jupyter/nbdime/blob/main/docs/source/vcs.md Enable or disable nbdime integration with Git for the current project, globally, or system-wide. This command registers nbdime as a diff/merge driver and tool. ```bash nbdime config-git (--enable | --disable) [--global | --system] ``` -------------------------------- ### Clean Development Files Source: https://github.com/jupyter/nbdime/blob/main/RELEASE.md Clean up development files before building the Python package. This command removes temporary and build-related files. ```bash jlpm clean:all ``` -------------------------------- ### Disable nbdime Extensions Source: https://github.com/jupyter/nbdime/blob/main/docs/source/extensions.md Disables and uninstalls all nbdime extensions. Use --sys-prefix for virtual environments, --user for the current user, or --system for all users. ```bash nbdime extensions --disable [--sys-prefix/--user/--system] ``` -------------------------------- ### Manually Register Git Merge Tool Source: https://github.com/jupyter/nbdime/blob/main/docs/source/vcs.md Manually configures git to use nbdime as a merge tool. This involves adding entries to .gitconfig. ```gitconfig [mergetool "nbdime"] cmd = git-nbmergetool "$BASE" "$LOCAL" "$REMOTE" "$MERGED" ``` ```gitconfig [merge] tool = nbdime ``` -------------------------------- ### Plot Data and Fit Source: https://github.com/jupyter/nbdime/blob/main/examples/example7/left.ipynb Visualizes the original data points and the fitted curve using Matplotlib. Includes a legend and sets y-axis limits. ```python def plot(x, y, yfit): # this method is for plotting with fitting plt.plot(x, y, "r", label="Data") plt.plot(x, yfit, "b", label="Fit") plt.legend() plt.ylim(-0.5, 2.5) plt.show() ``` -------------------------------- ### Generate and Plot Sine Wave Data Source: https://github.com/jupyter/nbdime/blob/main/nbdime/tests/files/output-conflict--1.ipynb Creates x-values using linspace up to the defined 'end' and calculates corresponding y-values for a sine wave. The plot function then renders this data. ```python x = linspace(0, end, 10) y = sin(x) plot(x, y) ``` -------------------------------- ### Display Result of f(5) Source: https://github.com/jupyter/nbdime/blob/main/nbdime/tests/files/cellids--local.ipynb Shows the computed result of squaring 5. ```text Result: 25 ``` -------------------------------- ### Disable nbdime Extensions Source: https://github.com/jupyter/nbdime/blob/main/docs/source/installing.md Run this command to disable the nbdime extensions. Choose the appropriate flag (--sys-prefix, --user, or --system) to specify the scope of the disable operation. ```bash nbdime extensions --disable [--sys-prefix/--user/--system] ``` -------------------------------- ### Placeholder for 'six' Source: https://github.com/jupyter/nbdime/blob/main/examples/example4/center.ipynb This snippet appears to be a placeholder or incomplete code. Its functionality is not defined. ```python six ``` -------------------------------- ### Print Value of x (Python) Source: https://github.com/jupyter/nbdime/blob/main/nbdime/tests/files/src-and-output--1.ipynb Prints the current value of the variable x. Used to verify assignments. ```python x ``` -------------------------------- ### Resolve Mercurial Merge Conflicts with nbdime Source: https://github.com/jupyter/nbdime/blob/main/docs/source/vcs.md Demonstrates the typical workflow for resolving merge conflicts in Mercurial using the nbdime web tool after a merge conflict occurs on a notebook file. ```bash > hg merge merging ***.ipynb 0 files updated, 0 files merged, 0 files removed, 1 files unresolved use 'hg resolve' to retry unresolved file merges or 'hg update -C .' to abandon > hg resolve --tool nbdimeweb ``` -------------------------------- ### Handle ZeroDivisionError in Python Source: https://github.com/jupyter/nbdime/blob/main/nbdime/tests/files/error--1.ipynb This snippet demonstrates a ZeroDivisionError that occurs when attempting to divide by zero. It is useful for understanding runtime arithmetic errors. ```python print("the value is", 0/0) ``` ```text --------------------------------------------------------------------------- ZeroDivisionError Traceback (most recent call last) in () ----> 1 print("the value is", 0/0) ZeroDivisionError: division by zero ``` -------------------------------- ### New Print Statement Source: https://github.com/jupyter/nbdime/blob/main/ui-tests/data/merge_test6/right.ipynb Prints a new string to the console. This is the new last cell on master. ```python # This the new last cell on master print("What about Batman?") ``` -------------------------------- ### Merge Notebooks with nbmerge Source: https://github.com/jupyter/nbdime/blob/main/docs/source/cli.md Use nbmerge to merge three notebooks (base, local, and remote) into a single output file. This command automatically handles conflicts based on the configured merge strategy. ```bash nbmerge base.ipynb local.ipynb remote.ipynb > merged.ipynb ``` -------------------------------- ### Define Gaussian and Noisy Gaussian Functions Source: https://github.com/jupyter/nbdime/blob/main/examples/example8/left.ipynb Imports numpy and matplotlib. Defines a Gaussian function and a function to generate noisy Gaussian data. Use this for data generation and simulation. ```python import numpy as np import matplotlib.pyplot as plt %matplotlib inline %this is a comment def gaussian(x, a, b, c): return a * np.exp(-b * (x-c)**2) def noisy_gaussian(): # gaussian array y in interval -5 <= x <= 5 nx = 100 x = np.linspace(-5.0, 5.0, nx) y = gaussian(x, a=2.0, b=0.5, c=1.5) noise = np.random.normal(0.0, 0.2, nx) y += noise return x, y ``` -------------------------------- ### Remote Notebook Identifier (Second Instance) Source: https://github.com/jupyter/nbdime/blob/main/nbdime/tests/files/cellids--remote.ipynb Another representation of a remote notebook, this time with a unique ID. Used to test handling of multiple remote notebook references. ```python REMOTE #2 - with unique ID ``` -------------------------------- ### Define Function g and Call Source: https://github.com/jupyter/nbdime/blob/main/nbdime/tests/files/multi_cell_nb--remote.ipynb Defines a Python function 'g' that squares its input and adds 3.0, then calls it with the argument 7. The result is 52.0. ```python def g(z): return z**2 + 3.0 g(7) ``` -------------------------------- ### Initial Variable Assignment Source: https://github.com/jupyter/nbdime/blob/main/ui-tests/data/merge_test6/right.ipynb Assigns a string value to a variable. This is the first cell in the initial commit. ```python # This is the first cell in the initial commit a = "hello the world" a ``` -------------------------------- ### Compute Notebook Diff Source: https://github.com/jupyter/nbdime/blob/main/docs/source/restapi.md Computes the difference between two Jupyter notebooks. Input notebooks can be provided as local filenames or URLs. ```APIDOC ## POST /api/diff ### Description Computes the difference between two notebooks provided as filenames local to the server working directory, and/or as URLs. ### Method POST ### Endpoint /api/diff ### Request Body - **base** (string) - Required - Filename or URL of the base notebook. - **remote** (string) - Required - Filename or URL of the remote notebook. ### Request Example ```json { "base": "filename.ipynb" | "http://your-domain/url/path", "remote": "filename.ipynb" | "http://your-domain/url/path" } ``` ### Response #### Success Response (200) - **base** (json_notebook) - The base notebook object. - **diff** (json_diff_object) - The diff result in nbdime diff format. ``` -------------------------------- ### Set Variable x to 5 Source: https://github.com/jupyter/nbdime/blob/main/nbdime/tests/files/cellids--local.ipynb Assigns the integer value 5 to the variable x. ```python x = 5 ``` -------------------------------- ### Diff Notebooks in Terminal Source: https://github.com/jupyter/nbdime/blob/main/docs/source/index.md Use the nbdiff command to compare two Jupyter notebooks directly in your terminal. ```default nbdiff notebook_1.ipynb notebook_2.ipynb ``` -------------------------------- ### Bump Version Script Source: https://github.com/jupyter/nbdime/blob/main/RELEASE.md Use the custom script to bump the version of the Python package. Replace with 'major', 'minor', 'patch', 'next', 'alpha', etc. ```bash python scripts/bump_version.py ``` -------------------------------- ### API Request: Compute Notebook Merge Source: https://github.com/jupyter/nbdime/blob/main/docs/source/restapi.md Use this endpoint to compute the merge of three Jupyter notebooks (base, local, remote). Provide notebook paths as local filenames or URLs. ```json { "base": "filename.ipynb" | "http://your-domain/url/path", "local": "filename.ipynb" | "http://your-domain/url/path", "remote": "filename.ipynb" | "http://your-domain/url/path" } ``` -------------------------------- ### Download Data from EPA Website Source: https://github.com/jupyter/nbdime/blob/main/ui-tests/data/merge_test3/right.ipynb Downloads zip files containing air quality data from specified EPA URLs. This snippet uses the requests library to stream the download and save it locally. Ensure the 'data/' directory exists before running. ```python # Download the data from the EPA website data_file_urls = [ 'https://aqs.epa.gov/aqsweb/airdata/daily_88101_2017.zip', 'https://aqs.epa.gov/aqsweb/airdata/daily_88101_2018.zip', ] # copied this example from https://stackoverflow.com/questions/16694907/download-large-file-in-python-with-requests for url in data_file_urls: local_filename = "data/{}".format(url.split('/')[-1]) with requests.get(url, stream=True) as r: r.raise_for_status() with open(local_filename, 'r') as f: for chunk in r.iter_content(chunk_size=8192): f.write(chunk) ``` -------------------------------- ### Generate Sinusoidal Data Source: https://github.com/jupyter/nbdime/blob/main/examples/example9/center.ipynb Generates x and y values for a sine wave. Useful for creating periodic data patterns. ```python def sinus (): # Here you can see a sinus function x = np.linspace(-5.0, 5.0, 100) y = np.sin(x) return x, y ``` -------------------------------- ### Define and Call Multiplication Function in Python Source: https://github.com/jupyter/nbdime/blob/main/nbdime/tests/files/foo--2.ipynb Defines a simple Python function 'foe' that performs multiplication and then calls it with specific arguments. ```python def foe(x, y): return x * y foe(1, 2) ``` ```text 2 ```