From e218af21ab0b62abcb50c98594d502b57711c9ae Mon Sep 17 00:00:00 2001
From: Drew Risinger <drewrisinger@users.noreply.github.com>
Date: Fri, 10 Apr 2020 17:36:03 -0400
Subject: [PATCH] python3Packages.retworkx: init at 0.3.3

Replacement for networkx in qiskit-terra.
---
 .../python-modules/retworkx/default.nix       | 59 +++++++++++++++++++
 pkgs/top-level/python-packages.nix            |  2 +
 2 files changed, 61 insertions(+)
 create mode 100644 pkgs/development/python-modules/retworkx/default.nix

diff --git a/pkgs/development/python-modules/retworkx/default.nix b/pkgs/development/python-modules/retworkx/default.nix
new file mode 100644
index 000000000000..531edab27467
--- /dev/null
+++ b/pkgs/development/python-modules/retworkx/default.nix
@@ -0,0 +1,59 @@
+{ lib
+, buildPythonPackage
+, pythonOlder
+, pythonAtLeast
+, isPy37
+, isPy38
+, fetchFromGitHub
+, fetchPypi
+  # Check inputs
+, pytestCheckHook
+}:
+
+let
+  rx-version = "0.3.3";
+  wheel-args = if isPy37 then
+      { python = "cp37"; sha256 = "1gbz7sh9i4h41xs9c40lixfdigmvfykkgxgzwsrs8v0smx20dczy"; }
+    else if isPy38 then
+      { python = "cp38"; sha256 = "09xxgp4ac4q6mfkj6lsqqfrzz1cb02vxy7wlv0bq3z2hd0jcanxk"; }
+    else throw "python version & hash not included. Override attribute `wheel-args` with version & hash at https://pypi.org/project/retworkx";
+
+  github-source = fetchFromGitHub {
+    owner = "Qiskit";
+    repo = "retworkx";
+    rev = rx-version;
+    sha256 = "160w5vkzrl5rzcrdwhjq820i5lmc527m6hg0kxx0k6n2bz9qn26g";
+  };
+in
+buildPythonPackage rec {
+  pname = "retworkx";
+  version = rx-version;
+  format = "wheel";
+
+  disabled = pythonOlder "3.5" || pythonAtLeast "3.9"; # compiled versions only included for 3.5 <= py <= 3.8
+
+  src = fetchPypi {
+    inherit pname version format;
+    inherit (wheel-args) python sha256;
+    abi = if pythonOlder "3.8" then "${wheel-args.python}m" else wheel-args.python;
+    platform = "manylinux2010_x86_64"; # i686, aarch64, and ppc64 also available, restricting to x86 for simplicity
+  };
+
+  pythonImportsCheck = [ "retworkx" ];
+
+  checkInputs = [ pytestCheckHook ];
+  preCheck = ''
+    pushd $(mktemp -d)
+    cp -r ${github-source}/$sourceRoot/tests .
+  '';
+  postCheck = "popd";
+
+  meta = with lib; {
+    description = "A python graph library implemented in Rust.";
+    homepage = "https://retworkx.readthedocs.io/en/latest/index.html";
+    downloadPage = "https://github.com/Qiskit/retworkx/releases";
+    license = licenses.asl20;
+    maintainers = with maintainers; [ drewrisinger ];
+    platforms = platforms.x86_64;
+  };
+}
diff --git a/pkgs/top-level/python-packages.nix b/pkgs/top-level/python-packages.nix
index 2cb35333656c..ddb4136f3672 100644
--- a/pkgs/top-level/python-packages.nix
+++ b/pkgs/top-level/python-packages.nix
@@ -5526,6 +5526,8 @@ in {
 
   readchar = callPackage ../development/python-modules/readchar { };
 
+  retworkx = callPackage ../development/python-modules/retworkx { };
+
   rivet = disabledIf isPy3k (toPythonModule (pkgs.rivet.override {
     python2 = python;
   }));