From 3f65d524661ea5a478593e0d1ece27bf03b49cf7 Mon Sep 17 00:00:00 2001 From: Christian Fernandez Date: Mon, 25 May 2020 19:44:26 +0200 Subject: [PATCH 1/6] DEV: modified setup to use setup tools --- .gitignore | 5 +++++ requirements.in | 3 --- requirements.txt | 8 -------- setup.py | 7 +++---- tests/test_import.py | 5 +++++ 5 files changed, 13 insertions(+), 15 deletions(-) delete mode 100644 requirements.in delete mode 100644 requirements.txt create mode 100644 tests/test_import.py 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/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 + From 0a6c19efdbf4058f191bdb06a6ba84cdb6f25034 Mon Sep 17 00:00:00 2001 From: Christian Fernandez Date: Mon, 25 May 2020 19:45:01 +0200 Subject: [PATCH 2/6] DEV: conda build recipe and travis setup --- .travis.yml | 39 ++++++++++++++++++++++++++ recipe/conda_upload.sh | 63 ++++++++++++++++++++++++++++++++++++++++++ recipe/meta.yaml | 50 +++++++++++++++++++++++++++++++++ 3 files changed, 152 insertions(+) create mode 100644 .travis.yml create mode 100644 recipe/conda_upload.sh create mode 100644 recipe/meta.yaml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..178d4f0 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,39 @@ +language: python + +python: + - "3.7" # we built a noarch (so in principle any recent version of python work) + +# limit git clone depth to 10 commits +git: + depth: 10 + +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 py38 python=3.8 pytest numpy scipy + - conda activate py38 + - pip install . + - pytest + - conda create -n py36 python=3.6 pytest numpy scipy + - conda activate py36 + - pip install . + - pytest + - conda create -n py37 python=3.7 pytest numpy scipy + - conda activate py37 + - pip install . + - pytest + +after_success: + - conda activate py37 + - conda install conda-build anaconda-client + - bash recipe/conda_upload.sh diff --git a/recipe/conda_upload.sh b/recipe/conda_upload.sh new file mode 100644 index 0000000..aac8678 --- /dev/null +++ b/recipe/conda_upload.sh @@ -0,0 +1,63 @@ +#!/usr/bin/env bash + +## adapted on https://gist.github.com/zshaheen/fe76d1507839ed6fbfbccef6b9c13ed9 + +PKG_NAME=brukeropusreader +ANACONDA_USER=spectrocat +OS=noarch ## OS=$TRAVIS_OS_NAME-64 +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 " + +if [[ $TRAVIS_BRANCH == "master" ]]; then + ## we build the current master repository (i.e.the last development version) + export DEVSTRING="dev" + 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" +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" +fi + +exit $? \ No newline at end of file diff --git a/recipe/meta.yaml b/recipe/meta.yaml new file mode 100644 index 0000000..24e9b86 --- /dev/null +++ b/recipe/meta.yaml @@ -0,0 +1,50 @@ +{% 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: + - {{ compiler('cxx') }} + - python + host: + - python + - numpy + - pip + - scipy + run: + - python + - numpy + - scipy + test: + - python {{ python }} + +test: + script_env: + - VERSION + - CONDA_BLD_PATH + imports: + - brukeropusreader + +about: + home: "https://github.com/qedsoftware/brukeropusreader" + license: GPLv3 + license_family: GPL3 + summary: "Bruker OPUS File Reader" + +extra: + recipe-maintainers: + - fernandezc From cff41859530cb68ab777bacf2ffe340598a4f72a Mon Sep 17 00:00:00 2001 From: Christian Fernandez Date: Mon, 25 May 2020 20:13:53 +0200 Subject: [PATCH 3/6] FIX: uncommenting important step! --- recipe/conda_upload.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/recipe/conda_upload.sh b/recipe/conda_upload.sh index aac8678..76f3f62 100644 --- a/recipe/conda_upload.sh +++ b/recipe/conda_upload.sh @@ -39,11 +39,11 @@ if [[ $TRAVIS_BRANCH == "master" ]]; then echo "***************************************************************************************************************" echo "--> BUILDING $CONDA_BLD_PATH/$OS/$PKG_NAME-$VERSION-$DEVSTRING.tar.bz2" echo "***************************************************************************************************************" - ##conda build . + 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" + anaconda -t "$CONDA_UPLOAD_TOKEN" upload --force -u $ANACONDA_USER -l dev "$CONDA_BLD_PATH/$OS/$PKG_NAME-$VERSION-$DEVSTRING.tar.bz2" fi if [[ $TRAVIS_BRANCH == $TRAVIS_TAG ]]; then @@ -53,11 +53,11 @@ if [[ $TRAVIS_BRANCH == $TRAVIS_TAG ]]; then echo "***************************************************************************************************************" echo "--> BUILDING $CONDA_BLD_PATH/$OS/$PKG_NAME-$VERSION-$DEVSTRING.tar.bz2" echo "***************************************************************************************************************" - ##conda build . + 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" + anaconda -t "$CONDA_UPLOAD_TOKEN" upload --force -u $ANACONDA_USER "$CONDA_BLD_PATH/$OS/$PKG_NAME-$VERSION-$DEVSTRING.tar.bz2" fi exit $? \ No newline at end of file From 6f08be0fca494ca85daf386370fc1ec4993f5eb8 Mon Sep 17 00:00:00 2001 From: Christian Fernandez Date: Mon, 25 May 2020 20:23:40 +0200 Subject: [PATCH 4/6] FIX: another error corrected (USER!) --- recipe/conda_upload.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/recipe/conda_upload.sh b/recipe/conda_upload.sh index 76f3f62..5309ed7 100644 --- a/recipe/conda_upload.sh +++ b/recipe/conda_upload.sh @@ -21,7 +21,7 @@ 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 [[ $USER != "travis" ]]; then ## if we are in local TRAVIS_BRANCH=$(git rev-parse --abbrev-ref HEAD) if [[ $TRAVIS_BRANCH == $LAST_TAG ]]; then @@ -30,7 +30,7 @@ if [[ $user != "travis" ]]; then ## else this run by TravisCI (this are env variables) fi -echo "user: $USER current branch: $TRAVIS_BRANCH " +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) From e09562131907c8ebda6123b8086e6deed296964d Mon Sep 17 00:00:00 2001 From: atravert Date: Thu, 28 May 2020 09:37:34 +0200 Subject: [PATCH 5/6] FIX wrong setting of wavenumbers axis --- brukeropusreader/opus_data.py | 4 ++-- example.py | 7 +++++-- 2 files changed, 7 insertions(+), 4 deletions(-) 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") From 9b1fd2030bdae843628126ab03b1027bf8108c3a Mon Sep 17 00:00:00 2001 From: Christian Fernandez Date: Thu, 28 May 2020 18:57:59 +0200 Subject: [PATCH 6/6] FIX: problem regarding travis build and anaconda upload --- .travis.yml | 21 +++++++-------------- recipe/conda_upload.sh | 34 +++++++++++++++++++++++++++++++--- recipe/meta.yaml | 6 ++++-- 3 files changed, 42 insertions(+), 19 deletions(-) diff --git a/.travis.yml b/.travis.yml index 178d4f0..351efe6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,11 +1,11 @@ language: python python: - - "3.7" # we built a noarch (so in principle any recent version of python work) + - "3.7" -# limit git clone depth to 10 commits +# limit git clone depth to 50 commits git: - depth: 10 + depth: 50 install: - sudo apt-get update @@ -20,20 +20,13 @@ install: - conda config --set channel_priority strict script: - - conda create -n py38 python=3.8 pytest numpy scipy - - conda activate py38 - - pip install . - - pytest - - conda create -n py36 python=3.6 pytest numpy scipy - - conda activate py36 - - pip install . - - pytest - - conda create -n py37 python=3.7 pytest numpy scipy - - conda activate py37 + - 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 py37 + - conda activate py$TRAVIS_PYTHON_VERSION - conda install conda-build anaconda-client - bash recipe/conda_upload.sh diff --git a/recipe/conda_upload.sh b/recipe/conda_upload.sh index 5309ed7..f3842df 100644 --- a/recipe/conda_upload.sh +++ b/recipe/conda_upload.sh @@ -3,8 +3,7 @@ ## adapted on https://gist.github.com/zshaheen/fe76d1507839ed6fbfbccef6b9c13ed9 PKG_NAME=brukeropusreader -ANACONDA_USER=spectrocat -OS=noarch ## OS=$TRAVIS_OS_NAME-64 +OS=noarch conda config --set anaconda_upload no ## TAG @@ -34,7 +33,7 @@ echo "user: $USER current branch: $TRAVIS_BRANCH last_tag: $LAST_TAG next_tag: if [[ $TRAVIS_BRANCH == "master" ]]; then ## we build the current master repository (i.e.the last development version) - export DEVSTRING="dev" + export DEVSTRING="latest" export VERSION="$NEXT_TAG" echo "***************************************************************************************************************" echo "--> BUILDING $CONDA_BLD_PATH/$OS/$PKG_NAME-$VERSION-$DEVSTRING.tar.bz2" @@ -44,6 +43,7 @@ if [[ $TRAVIS_BRANCH == "master" ]]; then 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 @@ -58,6 +58,34 @@ if [[ $TRAVIS_BRANCH == $TRAVIS_TAG ]]; then 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 index 24e9b86..ce2c322 100644 --- a/recipe/meta.yaml +++ b/recipe/meta.yaml @@ -18,7 +18,6 @@ build: requirements: build: - - {{ compiler('cxx') }} - python host: - python @@ -31,6 +30,7 @@ requirements: - scipy test: - python {{ python }} + - pytest test: script_env: @@ -40,10 +40,12 @@ test: - brukeropusreader about: - home: "https://github.com/qedsoftware/brukeropusreader" + 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: