From a63e80407da46ba7d71bb395a13cf65dd468607f Mon Sep 17 00:00:00 2001
From: Martin Weinelt <hexa@darmstadt.ccc.de>
Date: Sat, 17 Apr 2021 14:10:26 +0200
Subject: [PATCH] python3Packages.clevercsv: init at 0.6.7

Co-Authored-By: Joerg Thalheim <joerg@thalheim.io>
---
 .../python-modules/clevercsv/default.nix      | 60 +++++++++++++++++++
 pkgs/top-level/all-packages.nix               |  2 +
 pkgs/top-level/python-packages.nix            |  2 +
 3 files changed, 64 insertions(+)
 create mode 100644 pkgs/development/python-modules/clevercsv/default.nix

diff --git a/pkgs/development/python-modules/clevercsv/default.nix b/pkgs/development/python-modules/clevercsv/default.nix
new file mode 100644
index 000000000000..36944b5dbec4
--- /dev/null
+++ b/pkgs/development/python-modules/clevercsv/default.nix
@@ -0,0 +1,60 @@
+{ lib
+, buildPythonPackage
+, fetchFromGitHub
+, chardet
+, cleo
+, clikit
+, pandas
+, regex
+, tabview
+, python
+}:
+
+buildPythonPackage rec {
+  pname = "clevercsv";
+  version = "0.6.7";
+  format = "setuptools";
+
+  src = fetchFromGitHub {
+    owner = "alan-turing-institute";
+    repo = "CleverCSV";
+    rev = "v${version}";
+    sha256 = "0j3959bji48pkp0vnk7yls5l75ywjl77jdkvzs62n5mi5lky88p9";
+  };
+
+  propagatedBuildInputs = [
+    chardet
+    cleo
+    clikit
+    pandas
+    regex
+    tabview
+  ];
+
+  pythonImportsCheck = [
+    "clevercsv"
+    "clevercsv.cparser"
+  ];
+
+  checkPhase = ''
+    # by linking the installed version the tests also have access to compiled native libraries
+    rm -r clevercsv
+    ln -s $out/${python.sitePackages}/clevercsv/ clevercsv
+    # their ci only runs unit tests, there are also integration and fuzzing tests
+    ${python.interpreter} -m unittest discover -v -f -s ./tests/test_unit
+  '';
+
+  meta = with lib; {
+    description = "CleverCSV is a Python package for handling messy CSV files";
+    longDescription = ''
+       CleverCSV is a Python package for handling messy CSV files. It provides
+       a drop-in replacement for the builtin CSV module with improved dialect
+       detection, and comes with a handy command line application for working
+       with CSV files.
+    '';
+    homepage = "https://github.com/alan-turing-institute/CleverCSV";
+    changelog = "https://github.com/alan-turing-institute/CleverCSV/blob/master/CHANGELOG.md";
+    license = licenses.mit;
+    maintainers = with maintainers; [ hexa ];
+  };
+}
diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix
index 7499fb7dbd3d..8dae2f8c1db0 100644
--- a/pkgs/top-level/all-packages.nix
+++ b/pkgs/top-level/all-packages.nix
@@ -2017,6 +2017,8 @@ in
 
   clasp = callPackage ../tools/misc/clasp { };
 
+  clevercsv = with python3Packages; toPythonApplication clevercsv;
+
   clevis = callPackage ../tools/security/clevis {
     asciidoc = asciidoc-full;
   };
diff --git a/pkgs/top-level/python-packages.nix b/pkgs/top-level/python-packages.nix
index d25569ecd266..32425fc76f22 100644
--- a/pkgs/top-level/python-packages.nix
+++ b/pkgs/top-level/python-packages.nix
@@ -1343,6 +1343,8 @@ in {
 
   cleo = callPackage ../development/python-modules/cleo { };
 
+  clevercsv = callPackage ../development/python-modules/clevercsv { };
+
   clf = callPackage ../development/python-modules/clf { };
 
   click = callPackage ../development/python-modules/click { };