From b4d050fc85b1875dc74e1af10e6065858573aec7 Mon Sep 17 00:00:00 2001
From: Arthus <arthus@gfz-potsdam.de>
Date: Tue, 24 Nov 2020 11:09:58 +0100
Subject: [PATCH] New version plus testing restructure.

---
 .gitlab-ci.yml             |  2 +-
 .tests-shell.nix           | 50 ++++++++++++++++++++++++++++++++++
 install.sh                 |  5 ++--
 pymagglobal.nix            | 10 +++----
 pymagglobal/__init__.py    |  2 +-
 shell.nix                  |  6 +----
 tests/FieldTools/meta.yaml | 55 ++++++++++++++++++++++++++++++++++++++
 tests/nix/orthopoly.nix    | 31 +++++++++++++++++++++
 tests/nix/pyfield.nix      | 35 ++++++++++++++++++++++++
 9 files changed, 180 insertions(+), 16 deletions(-)
 create mode 100644 .tests-shell.nix
 create mode 100644 tests/FieldTools/meta.yaml
 create mode 100644 tests/nix/orthopoly.nix
 create mode 100644 tests/nix/pyfield.nix

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 7688414..3ab6952 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -4,7 +4,7 @@ build-job:
   stage: build
   script:
     - conda install conda-build
-    - conda build -c conda-forge FieldTools
+    - conda build -c conda-forge ./tests/FieldTools
     - conda build purge
     - conda build -c local -c conda-forge ./
     - conda build purge
diff --git a/.tests-shell.nix b/.tests-shell.nix
new file mode 100644
index 0000000..d4605a0
--- /dev/null
+++ b/.tests-shell.nix
@@ -0,0 +1,50 @@
+{ pkgs ? import
+    (builtins.fetchTarball {
+      name = "nixpkgs-20.09";
+      url = "https://github.com/NixOS/nixpkgs/archive/edb26126d98bc696f4f3e206583faa65d3d6e818.tar.gz";
+      sha256 = "1cl4ka4kk7kh3bl78g06dhiidazf65q8miyzaxi9930d6gwyzkci";
+    })
+    {
+      overlays = [
+        (self: super:
+
+          rec {
+            python37 = super.python37.override
+              {
+                packageOverrides = self: super: {
+
+                  matplotlib = super.matplotlib.overrideAttrs
+                    (oldAttrs: rec {
+                      version = "3.2.1";
+                      src = super.fetchPypi
+                        {
+                          inherit version;
+                          inherit (oldAttrs) pname;
+                          sha256 = "ffe2f9cdcea1086fc414e82f42271ecf1976700b8edd16ca9d376189c6d93aee";
+                        };
+                    });
+
+                  orthopoly = super.callPackage ./tests/nix/orthopoly.nix { };
+
+                  pyfield = super.callPackage ./tests/nix/pyfield.nix { };
+
+                  pymagglobal = super.callPackage ./pymagglobal.nix { };
+
+                };
+
+
+
+              };
+            python37Packages = python37.pkgs;
+          }
+
+
+
+        )
+      ];
+    }
+}:
+pkgs.mkShell {
+  buildInputs = with pkgs.python37Packages;
+    [ ipython pyfield pymagglobal cartopy matplotlib numpy scipy orthopoly ];
+}
diff --git a/install.sh b/install.sh
index 2f76479..0eed474 100644
--- a/install.sh
+++ b/install.sh
@@ -1,3 +1,2 @@
-conda build FieldTools
-conda build ./
-conda install pymagglobal -c local
+conda build -c conda-forge ./
+conda install pymagglobal -c local 
diff --git a/pymagglobal.nix b/pymagglobal.nix
index a6a51c5..cd3fd34 100644
--- a/pymagglobal.nix
+++ b/pymagglobal.nix
@@ -5,12 +5,11 @@
 , scipy
 , pandas
 , matplotlib
-, cartopy
-, pyfield }:
+, cartopy }:
 
 buildPythonPackage rec {
   pname = "pymagglobal";
-  version = "0.0.4";
+  version = "0.1.0;
   format = "other";
   src = ./.;
 
@@ -30,13 +29,12 @@ buildPythonPackage rec {
     pandas
     matplotlib
     cartopy
-    pyfield
   ];
 
   meta = with lib; {
-    description = "TODO";
+    description = "Python interface for global geomagnetic field models.";
     license = licenses.lgpl3;
-    maintainers = "Maximilian Schanner";
+    maintainers = [ maintainers.arthus ];
   };
 
 }
diff --git a/pymagglobal/__init__.py b/pymagglobal/__init__.py
index ba17d7b..c3f8811 100644
--- a/pymagglobal/__init__.py
+++ b/pymagglobal/__init__.py
@@ -30,4 +30,4 @@ models = built_in_models()
 listing names and paths to the included models.
 '''
 
-__version__ = '0.0.5'
+__version__ = '0.1.0'
diff --git a/shell.nix b/shell.nix
index feef84b..f5122e6 100644
--- a/shell.nix
+++ b/shell.nix
@@ -24,10 +24,6 @@
                         };
                     });
 
-                  orthopoly = super.callPackage ./orthopoly.nix { };
-
-                  pyfield = super.callPackage ./FieldTools/pyfield.nix { };
-
                   pymagglobal = super.callPackage ./pymagglobal.nix { };
 
                 };
@@ -46,5 +42,5 @@
 }:
 pkgs.mkShell {
   buildInputs = with pkgs.python37Packages;
-    [ ipython pyfield pymagglobal cartopy matplotlib numpy scipy orthopoly ];
+    [ pymagglobal cartopy matplotlib numpy scipy ];
 }
diff --git a/tests/FieldTools/meta.yaml b/tests/FieldTools/meta.yaml
new file mode 100644
index 0000000..0072713
--- /dev/null
+++ b/tests/FieldTools/meta.yaml
@@ -0,0 +1,55 @@
+
+package:
+  name: pyfield
+  version: 0.1.3i  # Does not math the tarball's version
+  # FIXME "0.1.2 interim-2" is invalid as a version string
+  # TODO Use templating with jinja to grab the version number e.g.
+  #version: {{ load_setup_py_data().version }} for the latest version
+  # or as an alternative for specific version
+  #{% set version = "0.1.3i" %}
+  #version: {{ version }}
+  # and also use it for the download
+  #url: .../fieldtools-{{ version }}.tar.gz
+
+
+source:
+  # Get a tarball from GFZ data services
+  url: ftp://datapub.gfz-potsdam.de/download/10.5880.FIDGEO.2019.033/fieldtools-i2.tar.gz
+  sha256: b297d853f30abdca968af2e3f52a5f62f0991485b23590897b7149c7171f3127
+
+build:
+  # Not quite sure about $PYTHON; Docs are just using bare 'python'
+  script:
+    - export CPPFLAGS='-Wno-deprecated'
+    - $PYTHON setup.py build
+    - $PYTHON setup.py install
+
+requirements:
+  build:
+    - {{ compiler('cxx') }}>=9.3  # XXX Versioning scheme only compatible with GCC
+    - swig
+    - numpy  # setup.py relies on numpy
+    - pkg-config
+    - eigen
+
+  host:
+    - python
+    - setuptools
+    - numpy
+    - eigen  # Not sure if required
+
+  run:
+    - python
+    - numpy
+    - eigen  # Not sure if required
+
+test:
+  commands:
+    - $PYTHON -c 'import pyfield;     import doctest; doctest.testmod(pyfield)'
+    - $PYTHON -c 'import pyfieldcore; import doctest; doctest.testmod(pyfieldcore)'
+  imports:
+    - pyfield
+
+about:
+    license: GPLv3
+    license_file: LICENSE
diff --git a/tests/nix/orthopoly.nix b/tests/nix/orthopoly.nix
new file mode 100644
index 0000000..9c1d81c
--- /dev/null
+++ b/tests/nix/orthopoly.nix
@@ -0,0 +1,31 @@
+# SPDX-FileCopyrightText: 2020 Helmholtz Centre Potsdam - GFZ German Research Centre for Geosciences, Germany (https://www.gfz-potsdam.de/)
+#
+# SPDX-License-Identifier: CC0-1.0
+
+{ buildPythonPackage
+, lib
+, fetchPypi
+, numpy
+, scipy
+}:
+
+buildPythonPackage rec {
+  pname = "orthopoly";
+  version = "0.7";
+
+  src = fetchPypi {
+    inherit pname version;
+    sha256 = "1hn9pz3xhld6ymam4jnj25axg9bzvjp0zlqv11icd5y9fj8jxvhd";
+  };
+
+  propagatedBuildInputs = [ numpy scipy ];
+
+  pythonImportsCheck = [ "orthopoly" ];
+
+  meta = with lib; {
+    description = "This is a package for using sets of orthogonal functions/polynomials.";
+    license = licenses.mit;
+    homepage = "https://github.com/wordsworthgroup/orthopoly";
+    maintainers = [ maintainers.arthus ];
+  };
+}
diff --git a/tests/nix/pyfield.nix b/tests/nix/pyfield.nix
new file mode 100644
index 0000000..31efcfd
--- /dev/null
+++ b/tests/nix/pyfield.nix
@@ -0,0 +1,35 @@
+{ python, buildPythonPackage, lib , numpy, pkg-config, eigen, swig, openmpi, gcc, setuptools}:
+
+buildPythonPackage rec {
+  pname = "pyfield";
+  version = "0.1.3";
+  format = "other";
+  src = builtins.fetchTarball {
+    url = "ftp://datapub.gfz-potsdam.de/download/10.5880.FIDGEO.2019.033/fieldtools-i2.tar.gz";
+    sha256 = "0ybszbd9jqv7ky1v3b5lb462w4gfki3p4hwgav9zsnyfsndgdr6f";
+  };
+
+  buildPhase = "${python.interpreter} ./setup.py build";
+  installPhase = ''${python.interpreter} ./setup.py install --prefix="$out"'';
+
+  nativeBuildInputs = [
+    pkg-config
+    swig
+    gcc
+  ];
+
+  propagatedBuildInputs = [
+    numpy
+    eigen
+    openmpi
+    setuptools
+  ];
+
+  meta = with lib; {
+    description = "Toolbox for manipulating vector fields on the sphere";
+    license = licenses.lgpl3;
+    homepage = "http://doi.org/10.5880/fidgeo.2019.033";
+    maintainers = "Hannes Matuschek";
+  };
+
+}
-- 
GitLab