Commit da1b9b42 authored by Maximilian Schanner's avatar Maximilian Schanner
Browse files

Merge branch 'pypi' into 'master'

Pypi

See merge request arthus/pymagglobal!10
parents d86a7c53 16c1ab99
# SPDX-FileCopyrightText: 2020 Helmholtz Centre Potsdam - GFZ German Research Centre for Geosciences, Germany (https://www.gfz-potsdam.de/)
#
# SPDX-License-Identifier: CC0-1.0
image: continuumio/miniconda3
image: debian:testing
stages:
- build
......@@ -10,36 +6,45 @@ stages:
- sqa
- deploy
debian-job:
stage: test
image: debian:testing
build-job:
stage: build
script:
- apt-get update -y -qq
- apt-get install -y -qq python3-matplotlib python3-cartopy python3-scipy python3-packaging python3-dev python3-setuptools python3-numpy
- python3 setup.py install
- python3 tests/run_tests.py
- apt-get install -y -qq python3 sphinx python3-sphinx-argparse
- sphinx-build -b html docs public
- apt-get install -y -qq python3-dev python3-pip
- pip install twine setuptools wheel
- python3 setup.py sdist bdist_wheel
- apt-get install -y -qq curl
# get the current package id
- "export ID=$(curl --request GET --header 'PRIVATE-TOKEN: 4xrVmceN2LRhSuF-HSbn' 'https://gitext.gfz-potsdam.de/api/v4/projects/1055/packages' | grep -P '(?<=.id.:)(\\d+)' -o )"
# remove the package, as we want a new build even if the version number did not change
- 'curl --request DELETE --header "PRIVATE-TOKEN: ${API_ACCES_TOKEN}" "https://gitext.gfz-potsdam.de/api/v4/projects/${CI_PROJECT_ID}/packages/$ID"'
# upload
- TWINE_PASSWORD=${CI_JOB_TOKEN} TWINE_USERNAME=gitlab-ci-token python3 -m twine upload --repository-url https://gitext.gfz-potsdam.de/api/v4/projects/${CI_PROJECT_ID}/packages/pypi dist/* --verbose
only:
- master
build-job:
stage: build
test-conda:
stage: test
image: continuumio/miniconda3
script:
- conda install conda-build
- conda build meta.yaml
- conda build purge
# To some reason setting CONDA_BLD_PATH=conda_bld does not work
- mv /opt/conda/conda-bld ./conda_bld
artifacts:
paths:
- conda_bld
- conda install cartopy
- pip install pymagglobal --extra-index-url https://public:5mz_iyigu-WE3HySBH1J@gitext.gfz-potsdam.de/api/v4/projects/1055/packages/pypi/simple
- python3 tests/run_tests.py
- pip uninstall -y pymagglobal
- pip install pymagglobal[tests] --extra-index-url https://public:5mz_iyigu-WE3HySBH1J@gitext.gfz-potsdam.de/api/v4/projects/1055/packages/pypi/simple
- python3 tests/run_tests.py
test-job:
stage: test
script:
- export CONDA_BLD_PATH=conda_bld # Received packages as artifacts
- conda install -c local pymagglobal packaging
- python tests/run_tests.py
- apt-get update -y -qq
- apt-get install -y -qq python3-dev python3-pip python3-cartopy
- pip install pymagglobal --extra-index-url https://public:5mz_iyigu-WE3HySBH1J@gitext.gfz-potsdam.de/api/v4/projects/1055/packages/pypi/simple
- python3 tests/run_tests.py
- pip uninstall -y pymagglobal
- pip install pymagglobal[tests] --extra-index-url https://public:5mz_iyigu-WE3HySBH1J@gitext.gfz-potsdam.de/api/v4/projects/1055/packages/pypi/simple
- python3 tests/run_tests.py
artifacts:
paths:
- ./docs/pic_mst.png
......@@ -51,8 +56,10 @@ test-job:
pages:
stage: deploy
script:
- export CONDA_BLD_PATH=conda_bld # Received packages as artifacts
- conda install -c local -c conda-forge pymagglobal sphinx sphinx-argparse
- apt-get update -y -qq
- apt-get install -y -qq python3-dev python3-pip python3-cartopy
- pip install pymagglobal --extra-index-url https://public:5mz_iyigu-WE3HySBH1J@gitext.gfz-potsdam.de/api/v4/projects/1055/packages/pypi/simple
- apt-get install -y -qq python3 sphinx python3-sphinx-argparse
- sphinx-build -b html docs public
artifacts:
paths:
......
......@@ -26,6 +26,23 @@ Once installed, `pymagglobal` can be imported and its routines used to access th
## Citation
TODO
## Installation
> **Note:** pymagglobal depends on [cartopy](https://scitools.org.uk/cartopy). You have to install it, before running the install command.
> This should also help if you receive `ImportError: NumPy 1.10+ is required to install cartopy.`
`pymagglobal` is distributed via the PyPI registry of this repository. It can be installed using
```console
$ pip install pymagglobal --extra-index-url https://public:5mz_iyigu-WE3HySBH1J@gitext.gfz-potsdam.de/api/v4/projects/1055/packages/pypi/simple
```
Since [conda](https://docs.conda.io/) version 4.6, conda and pip get along well. So you can also run `pip install ...` from inside your conda environment.
Another way to use `pymagglobal` is via nix-shell. With [nix](https://nixos.org/download.html) installed, simply run
```console
$ nix-shell
```
from within the `pymagglobal` root directory. You may also use the nix-expression [pymagglobal.nix] to include `pymagglobal` in your own environments.
## Documentation
Check out the extended documention [here](http://arthus.gitext-pages.gfz-potsdam.de/pymagglobal). From the command line, you can use `pymagglobal` to get various results from the models. For example,
```console
......@@ -53,9 +70,13 @@ When using `python` you can import the pymagglobal package and access the models
```python
import pymagglobal
```
We can first use `built_in_models`, to access a dictionary of available models:
```python
models = built_in_models()
```
Using the function `file2splines` you can get a spline object, representing the model. For example, to get a spline object for gufm1, use
```python
gufm1_splines = pymagglobal.file2splines(pymagglobal.models['gufm1'])
gufm1_splines = pymagglobal.file2splines(models['gufm1'])
```
This object can be evaluated to get the coefficients for a specific epoch
```python
......@@ -70,7 +91,7 @@ gufm1_dipoles = pymagglobal.dipole_series(times, gufm1_splines)
```
Additionally, pymagglobal provides a `Model` class, which is set up with a path and a name:
```python
gufm1 = pymagglobal.Model('gufm1', pymagglobal.models['gufm1'])
gufm1 = pymagglobal.Model('gufm1', models['gufm1'])
```
The object now contains several quantities of interest, for example the minimal and maximal time for which the model is valid
```python
......@@ -80,64 +101,6 @@ The object now contains several quantities of interest, for example the minimal
1990.0
```
## Installation
`pymagglobal` is built and installed using [conda](https://www.anaconda.com/).
1. Clone the repository
```console
$ git clone https://gitext.gfz-potsdam.de/arthus/pymagglobal.git
```
In the following `<pymagglobal>` refers to the path you cloned the `pymagglobal` repository into.
1. Download and install [Miniconda](https://conda.io/miniconda.html) for Python 3
By default, the installation directory `<conda>` is `~/miniconda3/`.
If you do not allow conda to modify your `bash.rc`, `conda` has to be replaced by `<conda>/bin/conda`. This may cause `install.sh` to fail.
You may want to create a fresh environment for pymagglobal. This is done using
```console
$ conda create --name Your_Environment
```
followed by
```console
$ conda activate Your_Environment
```
Careful: With tcshell, you have to use activate.csh.
1. Install `conda-build`
```console
$ conda install conda-build
```
With `conda-build` installed, you may go to `<pymagglobal>` and run
```console
$ bash install.sh
```
which will do the next steps for you. If `install.sh` fails or you want to do the steps by hand:
Build pymagglobal
Navigate to `<pymagglobal>` and build pymagglobal
```console
$ conda build meta.yaml
```
Install pymagglobal
```console
$ conda install pymagglobal -c local
```
This will make `pymagglobal` available as a python package, i.e. you can use
```python
import pymagglobal
```
as well as register a shell command in your local environmet, so that you can run
```console
$ pymagglobal --help
```
Another way to use `pymagglobal` is via nix-shell. With [nix](https://nixos.org/download.html) installed, simply run
```console
$ nix-shell
```
from within the `pymagglobal` root directory. You may also use the nix-expression [pymagglobal.nix] to include `pymagglobal` in your own environments.
## Testing
To test your `pymagglobal` installation, run
......
# pymagglobal
# pymagglobal is a python interface for global geomagnetic field models.
#
# SPDX-FileCopyrightText: 2020 Helmholtz Centre Potsdam - GFZ German Research Centre for Geosciences, Germany (https://www.gfz-potsdam.de/)
#
# SPDX-License-Identifier: GPL-3.0-or-later
#
# This Program was developed within the context of the following
# publicly funded projects or measures:
# - DFG (German Research Foundation), grant 388291411
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, Version 3 or later.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You can find a copy of the license in the LICENSES folder.
# If not, see <http://www.gnu.org/licenses/>.
conda build -c conda-forge meta.yaml
conda install pymagglobal -c local
# pymagglobal
# pymagglobal is a python interface for global geomagnetic field models.
#
# SPDX-FileCopyrightText: 2020 Helmholtz Centre Potsdam - GFZ German Research Centre for Geosciences, Germany (https://www.gfz-potsdam.de/)
#
# SPDX-License-Identifier: CC0-1.0
# SPDX-License-Identifier: GPL-3.0-or-later
#
# This Program was developed within the context of the following
# publicly funded projects or measures:
# - DFG (German Research Foundation), grant 388291411
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, Version 3 or later.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You can find a copy of the license in the LICENSES folder.
# If not, see <http://www.gnu.org/licenses/>.
package:
name: pymagglobal
version: {{ load_setup_py_data().version }}
channels:
- conda-forge
- local
source:
path: ./
build:
script: python setup.py install
requirements:
build:
- python
- setuptools
run:
- python
- numpy
- scipy
- matplotlib
- cartopy
test:
imports:
- pymagglobal
about:
license: GPLv3
......@@ -78,8 +78,10 @@ class ListModelsAction(argparse.Action):
help=help)
def __call__(self, parser, namespace, values, option_string=None):
models_list = list(_models.keys())
models_list.sort(key=str.lower)
print(f'Currently available models are:')
for it in _models.keys():
for it in models_list:
print(it)
print(f'Visit https://gitext.gfz-potsdam.de/arthus/pymagglobal/'
f'-/tree/master/pymagglobal/dat for detailed information.')
......
......@@ -52,7 +52,8 @@ def built_in_models() -> dict:
datdir = os.path.join(here, 'dat/')
models = {}
for it in os.listdir(datdir):
if os.path.isfile(os.path.join(datdir, it)) and 'README' not in it:
if os.path.isfile(os.path.join(datdir, it)) and 'license' not in it \
and 'README' not in it:
models[it] = os.path.join(datdir, it)
return models
......
......@@ -24,7 +24,7 @@
import os
import codecs
from setuptools import setup
import setuptools
# https://packaging.python.org/guides/single-sourcing-package-version/
......@@ -42,6 +42,8 @@ def get_version(rel_path):
else:
raise RuntimeError("Unable to find version string.")
with open("README.md", "r") as fh:
long_description = fh.read()
name = 'pymagglobal'
version = get_version('pymagglobal/__init__.py')
......@@ -50,7 +52,7 @@ copyright = f'2020 Helmholtz Centre Potsdam GFZ, ' \
+ f'German Research Centre for Geosciences, Potsdam, Germany'
setup(
setuptools.setup(
name=name,
version=version,
author='Schanner, M. A. and Mauerberger, S. and Korte, M.',
......@@ -58,8 +60,14 @@ setup(
packages=['pymagglobal'],
license='GPL v3',
description=description,
long_description=description,
install_requires=[],
long_description=long_description,
install_requires=[
'numpy>=1.18',
'scipy>=1.5.2',
'matplotlib>=2.2.5',
'cartopy>=0.17'
],
extras_require={'tests': ['orthopoly>=0.7' 'packaging']},
package_data={'pymagglobal': ['dat/*']},
include_package_data=True,
entry_points={'console_scripts': [f'pymagglobal = '
......
# pymagglobal
# pymagglobal is a python interface for global geomagnetic field models.
#
# SPDX-FileCopyrightText: 2020 Helmholtz Centre Potsdam - GFZ German Research Centre for Geosciences, Germany (https://www.gfz-potsdam.de/)
#
# SPDX-License-Identifier: CC0-1.0
# SPDX-License-Identifier: GPL-3.0-or-later
#
# This Program was developed within the context of the following
# publicly funded projects or measures:
# - DFG (German Research Foundation), grant 388291411
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, Version 3 or later.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You can find a copy of the license in the LICENSES folder.
# If not, see <http://www.gnu.org/licenses/>.
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
......@@ -23,7 +23,6 @@
import unittest
from pathlib import Path
from packaging.version import Version
import pymagglobal
......@@ -34,10 +33,13 @@ from pymagglobal import *
class ParserTestPackage(unittest.TestCase):
'''Unit-tests for the package i.e. __init__.py'''
def test_version(self):
'''Check if pymagglobal.__version__ conforms PEP 440'''
version = Version(pymagglobal.__version__)
try:
def test_version(self):
from packaging.version import Version
'''Check if pymagglobal.__version__ conforms PEP 440'''
version = Version(pymagglobal.__version__)
except ImportError:
print("Skipped version test, as the packaging package is not available.")
def test_models(self):
'''Check if built-in model-files exist'''
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment