homebrew-core/Formula/nbdime.rb

172 lines
6.0 KiB
Ruby

class Nbdime < Formula
include Language::Python::Virtualenv
desc "Jupyter Notebook Diff and Merge tools"
homepage "https://nbdime.readthedocs.io"
url "https://files.pythonhosted.org/packages/e1/36/28232d030c1b4a25116799f1aa3cd26208964f302daa324c314fd576820a/nbdime-3.1.1.tar.gz"
sha256 "67767320e971374f701a175aa59abd3a554723039d39fae908e72d16330d648b"
license "BSD-3-Clause"
bottle do
rebuild 1
sha256 cellar: :any_skip_relocation, arm64_monterey: "1553392c5720fd680644d4d617abebe012ece27b89c1fe96aeb9b7e968f5d896"
sha256 cellar: :any_skip_relocation, arm64_big_sur: "a33accd3f14e9c11a65be4c198cffbbd2f8e5275d4aa0359d1b5800528074540"
sha256 cellar: :any_skip_relocation, monterey: "e84db732813f0b699bed48ead024f4a98237e01afc1d27a5b2b920e5c036f6c7"
sha256 cellar: :any_skip_relocation, big_sur: "9a1c6227149374482850bd68647cdbc003fd937fadd00e87e525e630e38dd3b6"
sha256 cellar: :any_skip_relocation, catalina: "b84dcbdc0504a31ab8cb2c7ec1ad0a2f4bda29856d36488ca7e89d5f0d7c7d37"
sha256 cellar: :any_skip_relocation, x86_64_linux: "1c9299e7491f83c4970692f3a5a0626e7732be192473fe64a4ee7470fc68a5a9"
end
depends_on "ipython"
depends_on "jsonschema"
depends_on "jupyterlab"
depends_on "python@3.10"
depends_on "six"
resource "colorama" do
url "https://files.pythonhosted.org/packages/1f/bb/5d3246097ab77fa083a61bd8d3d527b7ae063c7d8e8671b1cf8c4ec10cbe/colorama-0.4.4.tar.gz"
sha256 "5941b2b48a20143d2267e95b1c2a7603ce057ee39fd88e7329b0c292aa16869b"
end
resource "gitdb" do
url "https://files.pythonhosted.org/packages/fc/44/64e02ef96f20b347385f0e9c03098659cb5a1285d36c3d17c56e534d80cf/gitdb-4.0.9.tar.gz"
sha256 "bac2fd45c0a1c9cf619e63a90d62bdc63892ef92387424b855792a6cabe789aa"
end
resource "GitPython" do
url "https://files.pythonhosted.org/packages/34/cc/aaa7a0d066ac9e94fbffa5fcf0738f5742dd7095bdde950bd582fca01f5a/GitPython-3.1.24.tar.gz"
sha256 "df83fdf5e684fef7c6ee2c02fc68a5ceb7e7e759d08b694088d0cacb4eba59e5"
end
resource "jupyter-server-mathjax" do
url "https://files.pythonhosted.org/packages/f1/6f/aaa531dfcfd5b2179184beccf246401db7fe6d860a77993daf471fc14594/jupyter_server_mathjax-0.2.3.tar.gz"
sha256 "564e8d1272019c6771208f577b5f9f2b3afb02b9e2bff3b34c042cef8ed84451"
end
resource "ptyprocess" do
url "https://files.pythonhosted.org/packages/20/e5/16ff212c1e452235a90aeb09066144d0c5a6a8c0834397e03f5224495c4e/ptyprocess-0.7.0.tar.gz"
sha256 "5c5d0a3b48ceee0b48485e0c26037c0acd7d29765ca3fbb5cb3831d347423220"
end
resource "requests-unixsocket" do
url "https://files.pythonhosted.org/packages/4d/ce/78b651fe0adbd4227578fa432d1bde03b4f4945a70c81e252a2b6a2d895f/requests-unixsocket-0.2.0.tar.gz"
sha256 "9e5c1a20afc3cf786197ae59c79bcdb0e7565f218f27df5f891307ee8817c1ea"
end
resource "smmap" do
url "https://files.pythonhosted.org/packages/21/2d/39c6c57032f786f1965022563eec60623bb3e1409ade6ad834ff703724f3/smmap-5.0.0.tar.gz"
sha256 "c840e62059cd3be204b0c9c9f74be2c09d5648eddd4580d9314c3ecde0b30936"
end
resource "testpath" do
url "https://files.pythonhosted.org/packages/dd/bf/245f32010f761aaeff132278e91e0d0ae1c360d6f3708a11790fdc1410d2/testpath-0.5.0.tar.gz"
sha256 "1acf7a0bcd3004ae8357409fc33751e16d37ccc650921da1094a86581ad1e417"
end
def python3
"python3.10"
end
def install
inreplace "pyproject.toml",
'requires = ["jupyterlab~=3.0", "setuptools>=40.8.0", "wheel"]',
'requires = ["setuptools>=40.8.0", "wheel"]'
virtualenv_install_with_resources
site_packages = Language::Python.site_packages(python3)
%w[jupyterlab ipython jsonschema].each do |package_name|
package = Formula[package_name].opt_libexec
(libexec/site_packages/"homebrew-#{package_name}.pth").write package/site_packages
end
end
test do
(testpath/"old.ipynb").write <<~EOS
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"print(\\\"Hello World!\\\")"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 2",
"language": "python",
"name": "python2"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.10"
}
},
"nbformat": 4,
"nbformat_minor": 1
}
EOS
(testpath/"new.ipynb").write <<~EOS
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Hello World!\\n"
]
}
],
"source": [
"print(\\\"Hello World!\\\")"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 2",
"language": "python",
"name": "python2"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.10"
}
},
"nbformat": 4,
"nbformat_minor": 1
}
EOS
# sadly no special exit code if files are the same
diff_output = shell_output("#{bin}/nbdiff --no-color old.ipynb new.ipynb")
assert_match "nbdiff old.ipynb new.ipynb", diff_output
assert_match(/--- old.ipynb \d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}.\d{6}/, diff_output)
assert_match(/\+\+\+ new.ipynb \d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}.\d{6}/, diff_output)
end
end