diff --git a/.gitignore b/.gitignore index b26a5b8..d25ee08 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,7 @@ *.pyc *.csv + +# dir +.idea/ +conda-bld/ +*.egg-info/ diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..351efe6 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,32 @@ +language: python + +python: + - "3.7" + +# limit git clone depth to 50 commits +git: + depth: 50 + +install: + - sudo apt-get update + - wget https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh -O miniconda.sh + - bash miniconda.sh -b -p $HOME/miniconda + - source "$HOME/miniconda/etc/profile.d/conda.sh" + - hash -r + - conda config --set always_yes yes --set changeps1 no + - conda update -q conda + - conda config --add channels conda-forge + - conda config --add channels spectrocat + - conda config --set channel_priority strict + +script: + - conda create -n py$TRAVIS_PYTHON_VERSION python=$TRAVIS_PYTHON_VERSION pytest numpy scipy + - conda activate py$TRAVIS_PYTHON_VERSION + - conda update pytest + - pip install . + - pytest + +after_success: + - conda activate py$TRAVIS_PYTHON_VERSION + - conda install conda-build anaconda-client + - bash recipe/conda_upload.sh diff --git a/brukeropusreader/opus_data.py b/brukeropusreader/opus_data.py index 0793c33..b6a4a11 100644 --- a/brukeropusreader/opus_data.py +++ b/brukeropusreader/opus_data.py @@ -7,8 +7,8 @@ class OpusData(dict): param_key = f"{spec_name} Data Parameter" fxv = self[param_key]["FXV"] lxv = self[param_key]["LXV"] - # NPT and REAL NUMBER OF POINTS may differ - npt = self[spec_name].shape[0] + # the number of points here is OK. It is "AB" that can return more values (equals to zero) + npt = self[param_key]["NPT"] x_no_unit = np.linspace(fxv, lxv, npt) if wavenums: return x_no_unit diff --git a/example.py b/example.py index b7bb895..2a6f6e4 100644 --- a/example.py +++ b/example.py @@ -11,14 +11,17 @@ def main(path_to_file): print(f"Data fields: " f"{list(opus_data.keys())}") ab_x = opus_data.get_range("AB") + # the "AB" data can contain more null values at the end (at least 1) + # so the getting useful data requires slicing the array: + abs = opus_data["AB"][0:len(ab_x)] print(f"Absorption spectrum range: " f"{ab_x[0]} {ab_x[-1]}") - print(f"Absorption elements num: " f'{len(opus_data["AB"])}') + print(f"Absorption elements num: " f'{len(abs)}') try: import matplotlib.pyplot as plt print("Plotting AB") - plt.plot(opus_data.get_range("AB"), opus_data["AB"]) + plt.plot(opus_data.get_range("AB"), abs) plt.show() print("Plotting interpolated AB") diff --git a/recipe/conda_upload.sh b/recipe/conda_upload.sh new file mode 100644 index 0000000..f3842df --- /dev/null +++ b/recipe/conda_upload.sh @@ -0,0 +1,91 @@ +#!/usr/bin/env bash + +## adapted on https://gist.github.com/zshaheen/fe76d1507839ed6fbfbccef6b9c13ed9 + +PKG_NAME=brukeropusreader +OS=noarch +conda config --set anaconda_upload no + +## TAG +TAG=$(git describe --tags) +IFS=$"-" +read -ra arr <<< "$TAG" +LAST_TAG="${arr[0]}" +IFS=$"." +read -ra tag <<< "$LAST_TAG" +NEXT_TAG="${tag[0]}.${tag[1]}.`expr ${tag[2]} + 1`" +NUMBER="${arr[1]}" + +export CONDA_BLD_PATH="$HOME/conda-bld" +mkdir -p "$CONDA_BLD_PATH" + +## Here we will choose depending on the way this script is run +if [[ $USER != "travis" ]]; then + ## if we are in local + TRAVIS_BRANCH=$(git rev-parse --abbrev-ref HEAD) + if [[ $TRAVIS_BRANCH == $LAST_TAG ]]; then + TRAVIS_TAG=$LAST_TAG + fi + ## else this run by TravisCI (this are env variables) +fi + +echo "user: $USER current branch: $TRAVIS_BRANCH last_tag: $LAST_TAG next_tag: $NEXT_TAG" + +if [[ $TRAVIS_BRANCH == "master" ]]; then + ## we build the current master repository (i.e.the last development version) + export DEVSTRING="latest" + export VERSION="$NEXT_TAG" + echo "***************************************************************************************************************" + echo "--> BUILDING $CONDA_BLD_PATH/$OS/$PKG_NAME-$VERSION-$DEVSTRING.tar.bz2" + echo "***************************************************************************************************************" + conda build . + echo "***************************************************************************************************************" + echo "--> UPLOADING $CONDA_BLD_PATH/$OS/$PKG_NAME-$VERSION-$DEVSTRING.tar.bz2 to anaconda repository" + echo "***************************************************************************************************************" + anaconda -t "$CONDA_UPLOAD_TOKEN" upload --force -u $ANACONDA_USER -l dev "$CONDA_BLD_PATH/$OS/$PKG_NAME-$VERSION-$DEVSTRING.tar.bz2" + exit $? +fi + +if [[ $TRAVIS_BRANCH == $TRAVIS_TAG ]]; then + ## this is a "stable" release + export DEVSTRING="stable" + export VERSION="$LAST_TAG" + echo "***************************************************************************************************************" + echo "--> BUILDING $CONDA_BLD_PATH/$OS/$PKG_NAME-$VERSION-$DEVSTRING.tar.bz2" + echo "***************************************************************************************************************" + conda build . + echo "***************************************************************************************************************" + echo "--> UPLOADING $CONDA_BLD_PATH/$OS/$PKG_NAME-$VERSION-$DEVSTRING.tar.bz2 to
anaconda repository" + echo "***************************************************************************************************************" + anaconda -t "$CONDA_UPLOAD_TOKEN" upload --force -u $ANACONDA_USER "$CONDA_BLD_PATH/$OS/$PKG_NAME-$VERSION-$DEVSTRING.tar.bz2" + exit $? +fi + +if [ ! $NUMBER ] +then + NUMBER="0" +fi + +if [[ $TRAVIS_BRANCH == "develop" ]]; then + ## we build the current develop repository (for testing purpose) + export DEVSTRING="test$NUMBER" + export VERSION="$NEXT_TAG" + echo "***************************************************************************************************************" + echo "--> BUILDING $CONDA_BLD_PATH/$OS/$PKG_NAME-$VERSION-$DEVSTRING.tar.bz2" + echo "***************************************************************************************************************" + conda build . + echo "***************************************************************************************************************" + echo "--> UPLOADING $CONDA_BLD_PATH/$OS/$PKG_NAME-$VERSION-$DEVSTRING.tar.bz2 to anaconda repository" + echo "***************************************************************************************************************" + anaconda -t "$CONDA_UPLOAD_TOKEN" upload --force -u $ANACONDA_USER -l test "$CONDA_BLD_PATH/$OS/$PKG_NAME-$VERSION-$DEVSTRING.tar.bz2" + exit $? +fi + +## this is a local "dev" release not yet merged with develop (will not be uploaded) +export DEVSTRING="test$NUMBER" +export VERSION="$NEXT_TAG" +echo "***************************************************************************************************************" +echo "--> BUILDING $CONDA_BLD_PATH/$OS/$PKG_NAME-$VERSION-$DEVSTRING.tar.bz2" +echo "***************************************************************************************************************" +conda build . +exit $? \ No newline at end of file diff --git a/recipe/meta.yaml b/recipe/meta.yaml new file mode 100644 index 0000000..ce2c322 --- /dev/null +++ b/recipe/meta.yaml @@ -0,0 +1,52 @@ +{% set name = "brukeropusreader" %} +{% set version = environ['VERSION'] %} + +package: + name: "{{ name|lower }}" + version: "{{ version }}" + +source: + path: ../ + +build: + script_env: + - VERSION + - CONDA_BLD_PATH + string: {{ environ['DEVSTRING'] }} + noarch: python + script: "{{ PYTHON }} -m pip install . -vv" + +requirements: + build: + - python + host: + - python + - numpy + - pip + - scipy + run: + - python + - numpy + - scipy + test: + - python {{ python }} + - pytest + +test: + script_env: + - VERSION + - CONDA_BLD_PATH + imports: + - brukeropusreader + +about: + home: "https://github.com/spectrochempy/brukeropusreader" + license: GPLv3 + license_family: GPL3 + summary: "Bruker OPUS File Reader" + doc_url: "https://github.com/spectrochempy/brukeropusreader" + dev_url: "https://github.com/spectrochempy/brukeropusreader" + +extra: + recipe-maintainers: + - fernandezc diff --git a/requirements.in b/requirements.in deleted file mode 100644 index 95f2ebc..0000000 --- a/requirements.in +++ /dev/null @@ -1,3 +0,0 @@ -numpy -scipy - diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index 613b2c4..0000000 --- a/requirements.txt +++ /dev/null @@ -1,8 +0,0 @@ -# -# This file is autogenerated by pip-compile -# To update, run: -# -# pip-compile --output-file=requirements.txt requirements.in -# -numpy==1.16.1 -scipy==1.2.1 diff --git a/setup.py b/setup.py index 0a397fd..b205b4b 100644 --- a/setup.py +++ b/setup.py @@ -1,14 +1,13 @@ -from distutils.core import setup - +from setuptools import setup setup( name="brukeropusreader", - version="1.3.4", + use_scm_version=True, description="Bruker OPUS File Reader", author="QED", author_email="brukeropusreader-dev@qed.ai", packages=["brukeropusreader"], - install_requires=["numpy>=1.13.3", "scipy>=0.19.1"], + # install_requires=["numpy>=1.13.3", "scipy>=0.19.1"], license="GPLv3", url="https://github.com/qedsoftware/brukeropusreader", ) diff --git a/tests/test_import.py b/tests/test_import.py new file mode 100644 index 0000000..c00b53d --- /dev/null +++ b/tests/test_import.py @@ -0,0 +1,5 @@ +def test_import(): + import brukeropusreader as bor + l = dir(bor) + assert 'opus_reader' in l +