##
##  python-math.spec -- OpenPKG RPM Package Specification
##  Copyright (c) 2000-2025 OpenPKG Project <http://openpkg.org/>
##
##  Permission to use, copy, modify, and distribute this software for
##  any purpose with or without fee is hereby granted, provided that
##  the above copyright notice and this permission notice appear in all
##  copies.
##
##  THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
##  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
##  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
##  IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR
##  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
##  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
##  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
##  USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
##  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
##  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
##  OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
##  SUCH DAMAGE.
##

#   package versions
%define       V_python        3.14
%define       V_pythran       0.18.0
%define       V_gast          0.6.0
%define       V_beniget       0.4.1
%define       V_numpy         2.3.4
%define       V_scipy         1.16.2
%define       V_scikit        1.5.0
%define       V_theano        1.0.5
%define       V_pandas        2.3.3

#   package information
Name:         python-math
Summary:      Python Modules for Mathematics
URL:          http://www.python.org/
Vendor:       Python Community
Packager:     OpenPKG Project
Distribution: OpenPKG Community
Class:        BASE
Group:        Language
License:      GPL
Version:      %{V_python}
Release:      20251015

#   list of sources
Source0:      https://files.pythonhosted.org/packages/source/n/numpy/numpy-%{V_numpy}.tar.gz
Source1:      https://files.pythonhosted.org/packages/source/p/pythran/pythran-%{V_pythran}.tar.gz
Source2:      https://files.pythonhosted.org/packages/source/g/gast/gast-%{V_gast}.tar.gz
Source3:      https://files.pythonhosted.org/packages/source/b/beniget/beniget-%{V_beniget}.tar.gz
Source4:      https://files.pythonhosted.org/packages/source/s/scipy/scipy-%{V_scipy}.tar.gz
Source5:      https://files.pythonhosted.org/packages/source/s/scikit_learn/scikit_learn-%{V_scikit}.tar.gz
Source6:      https://files.pythonhosted.org/packages/source/T/Theano/Theano-%{V_theano}.tar.gz
Source7:      https://files.pythonhosted.org/packages/source/p/pandas/pandas-%{V_pandas}.tar.gz

#   build information
BuildPreReq:  OpenPKG, openpkg >= 20160101
PreReq:       OpenPKG, openpkg >= 20160101
BuildPreReq:  gcc, gcc::with_fortran = yes
PreReq:       gcc, gcc::with_fortran = yes
BuildPreReq:  python >= %{V_python}, python-sys, python-parse
PreReq:       python >= %{V_python}, python-sys, python-parse
BuildPreReq:  openblas
PreReq:       openblas

%description
    This is a set of Python extension modules for mathematics.

%track
    prog python-math:pythran = {
        version   = %{V_pythran}
        url       = https://pypi.python.org/pypi/pythran
        regex     = pythran-(__VER__)\.tar\.gz
    }
    prog python-math:gast = {
        version   = %{V_gast}
        url       = https://pypi.python.org/pypi/gast
        regex     = gast-(__VER__)\.tar\.gz
    }
    prog python-math:beniget = {
        version   = %{V_beniget}
        url       = https://pypi.python.org/pypi/beniget
        regex     = beniget-(__VER__)\.tar\.gz
    }
    prog python-math:numpy = {
        version   = %{V_numpy}
        url       = https://pypi.python.org/pypi/numpy
        regex     = numpy-(__VER__)\.tar\.gz
    }
    prog python-math:scipy = {
        version   = %{V_scipy}
        url       = https://pypi.python.org/pypi/scipy
        regex     = scipy-(__VER__)\.tar\.gz
    }
    prog python-math:scikit = {
        version   = %{V_scikit}
        url       = https://pypi.python.org/pypi/scikit-learn
        regex     = scikit-learn-(__VER__)\.tar\.gz
    }
    prog python-math:theano = {
        version   = %{V_theano}
        url       = https://pypi.python.org/pypi/Theano
        regex     = Theano-(__VER__)\.tar\.gz
    }
    prog python-math:pandas = {
        version   = %{V_pandas}
        url       = https://pypi.python.org/pypi/pandas
        regex     = pandas-(__VER__)\.tar\.gz
    }

%prep
    %setup -q -c
    %setup -q -T -D -a 1
    %setup -q -T -D -a 2
    %setup -q -T -D -a 3
    %setup -q -T -D -a 4
    %setup -q -T -D -a 5
    %setup -q -T -D -a 6
    %setup -q -T -D -a 7

%build

%install
    export PYTHONPATH=$RPM_BUILD_ROOT%{l_prefix}/lib/python%{V_python}/site-packages
    ( echo "#!/bin/sh"
      echo "exec %{l_prefix}/bin/gcc \"\$@\" -lgfortran -lquadmath -lm"
    ) >gcc
    chmod a+x gcc
    PATH=`pwd`:$PATH
    HOME=`pwd`
    ( cd pythran-%{V_pythran}
      %{l_prefix}/bin/python \
          setup.py install \
          --root=$RPM_BUILD_ROOT \
          --prefix=%{l_prefix}
    ) || exit $?
    ( cd gast-%{V_gast}
      %{l_prefix}/bin/python \
          setup.py install \
          --root=$RPM_BUILD_ROOT \
          --prefix=%{l_prefix}
    ) || exit $?
    ( cd beniget-%{V_beniget}
      %{l_prefix}/bin/python \
          setup.py install \
          --root=$RPM_BUILD_ROOT \
          --prefix=%{l_prefix}
    ) || exit $?
    ( cd numpy-%{V_numpy}
        ( echo "[openblas]"
          echo "library_dirs = %{l_prefix}/lib"
          echo "include_dirs = %{l_prefix}/include"
          echo "runtime_library_dirs = %{l_prefix}/lib"
          echo "extra_link_args = -lgfortran -lquadmath -lm"
          echo "search_static_first = true"
        ) >site.cfg
        HOME=`pwd` %{l_prefix}/bin/python \
            -m pip install \
            --root=$RPM_BUILD_ROOT \
            --prefix=%{l_prefix} \
            --ignore-installed \
            --no-deps \
            .
    ) || exit $?
    #   (   cd scipy-%{V_scipy}
    #       rm -f "scipy/io/tests/data/Transparent Busy.ani"
    #       HOME=`pwd` %{l_prefix}/bin/python \
    #           -m pip install \
    #           --root=$RPM_BUILD_ROOT \
    #           --prefix=%{l_prefix} \
    #           --ignore-installed \
    #           --no-deps \
    #           .
    #   ) || exit $?
    #   (   cd scikit-learn-%{V_scikit}
    #       %{l_prefix}/bin/python \
    #           setup.py install \
    #           --root=$RPM_BUILD_ROOT \
    #           --prefix=%{l_prefix}
    #   ) || exit $?
    #   (   cd Theano-%{V_theano}
    #       %{l_prefix}/bin/python \
    #           setup.py install \
    #           --root=$RPM_BUILD_ROOT \
    #           --prefix=%{l_prefix}
    #       chmod 644 $RPM_BUILD_ROOT%{l_prefix}/lib/python*/site-packages/Theano-*.egg-info/PKG-INFO
    #   ) || exit $?
    #   (   cd pandas-%{V_pandas}
    #       HOME=`pwd` %{l_prefix}/bin/python \
    #           -m pip install \
    #           --root=$RPM_BUILD_ROOT \
    #           --prefix=%{l_prefix} \
    #           --ignore-installed \
    #           --no-deps \
    #           .
    #   ) || exit $?
    %{l_rpmtool} files -v -ofiles -r$RPM_BUILD_ROOT %{l_files_std}

%files -f files

%clean

