Skip to content

Commit

Permalink
Patch v0.13.2 (#191)
Browse files Browse the repository at this point in the history
* Enable code analysis by GitHub's CodeQL (#186)

* examples: fix rendering of RST code-blocks in notebooks (#179) (#184)

* Fix call to pipwin executable during PyPI installation (#187)

* `snlls`: Fix violation of boundaries due to float-point round-off errors  (#188)

* docs: fix automated example plots in the models reference (#190)

* VERSION: bump to v0.13.2

* Implement automated PyPI and Anaconda build and publish workflow (#185)

* Update CHANGELOG for v0.13.2
  • Loading branch information
luisfabib authored Jul 2, 2021
1 parent 12219df commit dd71314
Show file tree
Hide file tree
Showing 21 changed files with 329 additions and 59 deletions.
11 changes: 11 additions & 0 deletions .github/actions/conda_build_publish_package/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM continuumio/miniconda3:4.7.10

LABEL "repository"="https://github.com/m0nhawk/conda-package-publish-action"
LABEL "maintainer"="Andrew Prokhorenkov <andrew.prokhorenkov@gmail.com>"

RUN conda install -y anaconda-client conda-build


COPY entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]
63 changes: 63 additions & 0 deletions .github/actions/conda_build_publish_package/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Build and Publish Anaconda Package

A Github Action to publish your software package to an Anaconda repository.

### Example workflow to publish to conda every time you make a new release

```yaml
name: publish_conda

on:
release:
types: [published]

jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: publish-to-conda
uses: maxibor/conda-package-publish-action@v1.1
with:
subDir: 'conda'
AnacondaToken: ${{ secrets.ANACONDA_TOKEN }}
platforms: 'win-64 osx-64 linux-64'
python: '3.6 3.8'
```
### Example project structure
```
.
├── LICENSE
├── README.md
├── myproject
│   ├── __init__.py
│   └── myproject.py
├── conda
│   ├── build.sh
│   └── meta.yaml
├── .github
│   └── workflows
│   └── publish_conda.yml
├── .gitignore
```
### Inputs

The action takes the following

- `AnacondaToken` - Anaconda access Token (see below)

- `subDir` - (Optional) Sub-directory with conda recipe. Default: `.`

- `platforms` - (Optional) Platforms to build and publish. Default: `win-64 osx-64 linux-64`.

- `python` - (Optional) Python versions to build and publish. Default: `3.8`.

### ANACONDA_TOKEN

1. Get an Anaconda token (with read and write API access) at `anaconda.org/USERNAME/settings/access`
2. Add it to the Secrets of the Github repository as `ANACONDA_TOKEN`

### Build Channels
By Default, this Github Action will search for conda build dependancies (on top of the standard channels) in `conda-forge` and `bioconda`
21 changes: 21 additions & 0 deletions .github/actions/conda_build_publish_package/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: 'Publish Conda package to Anaconda.org'
description: 'Build and Publish conda package to Anaconda'
author: 'Andrew Prokhorenkov, modified by Maxime Borry, modified by Luis Fabregas'
branding:
icon: 'package'
color: 'purple'
inputs:
subDir:
description: 'Sub-directory with conda recipe'
default: '.'
AnacondaToken:
description: 'Anaconda access Token'
platforms:
description: 'Platforms to build and publish [osx linux win]'
default: 'win-64 osx-64 linux-64'
python:
description: 'Python version to build and publish'
default: '3.8'
runs:
using: 'docker'
image: 'Dockerfile'
50 changes: 50 additions & 0 deletions .github/actions/conda_build_publish_package/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/bin/bash

set -ex
set -o pipefail

go_to_build_dir() {
if [ ! -z $INPUT_SUBDIR ]; then
cd $INPUT_SUBDIR
fi
}

check_if_meta_yaml_file_exists() {
if [ ! -f meta.yaml ]; then
echo "meta.yaml must exist in the directory that is being packaged and published."
exit 1
fi
}

build_package(){

IFS=' ' read -ra PYTHON <<< "$INPUT_PYTHON"
IFS=' ' read -ra PLATFORMS <<< "$INPUT_PLATFORMS"

for python in "${PYTHON[@]}"; do
conda build -c conda-forge -c bioconda --output-folder . --python $python .
done
for platform in "${PLATFORMS[@]}"; do
for filename in /$platform/*.tar.bz2; do
conda convert -p $platform linux-64/*.tar.bz2
done
done
}

upload_package(){

IFS=' ' read -ra PLATFORMS <<< "$INPUT_PLATFORMS"

export ANACONDA_API_TOKEN=$INPUT_ANACONDATOKEN

for platform in "${PLATFORMS[@]}"; do
for filename in ./"$platform"/*.tar.bz2; do
anaconda upload $filename
done
done
}

go_to_build_dir
check_if_meta_yaml_file_exists
build_package
upload_package
57 changes: 57 additions & 0 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: "CodeQL"

on:
push:
branches: [ main, release/v0.13.0 ]
pull_request:
# The branches below must be a subset of the branches above
branches: [ main ]
schedule:
- cron: '33 11 * * 0'

jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write

strategy:
fail-fast: false
matrix:
language: [ 'python' ]

steps:
- name: Checkout repository
uses: actions/checkout@v2

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v1
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.
# queries: ./path/to/local/query, your-org/your-repo/queries@main

# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v1

# ℹ️ Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl

# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
# and modify them (or add more) to build your code if your project
# uses a compiled language

#- run: |
# make bootstrap
# make release

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v1
57 changes: 57 additions & 0 deletions .github/workflows/package_upload.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: Build & Upload Python Package

on:
release:
types: [published]

jobs:

pypi-build-n-publish:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v1
- name: Set up Python 3.8
uses: actions/setup-python@v1
with:
python-version: 3.8
- name: Install dependencies
run: |
apt-get install python3-pip -y
python -m pip install setuptools --user
python -m pip install build --user
python -m pip install twine --user
python -m pip install conda --user
- name: PyPI - Build and publish
run: |
python setup.py sdist
python -m twine upload dist/*
- name: Publish distribution to PyPI
uses: pypa/gh-action-pypi-publish@master
with:
password: ${{ secrets.PYPI_API_TOKEN }}

conda-build-n-publish:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v1
- name: Set up Python 3.8
uses: actions/setup-python@v1
with:
python-version: 3.8
- name: Get DeerLab version
run: echo "DEERLAB_VERSION=$(cat VERSION)" >> $GITHUB_ENV
- name: Update version in Conda metadata
uses: jacobtomlinson/gha-find-replace@master
with:
find: "VERSION"
replace: ${{env.DEERLAB_VERSION}}
include: "conda.recipe/meta.yaml"
- name: Build & Publish to Anaconda
uses: ./.github/actions/conda_build_publish_package
with:
subdir: 'conda.recipe'
anacondatoken: ${{ secrets.ANACONDA_TOKEN }}
platforms: 'osx-64 linux-32 linux-64 win-32 win-64'
python: '3.6 3.7 3.8 3.9'
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@

Release v0.13.2 - July 2021
---------------------------------

#### Overall changes

- Fixed an error appearing during installation in Windows systems. If during installation a ``python`` executable alias was not created, the call to the ``pipwin`` manager returned an error and the installation failed to download and install Numpy, SciPy and cvxopt. ([#187](https://github.com/JeschkeLab/DeerLab/pull/187)).
- Fixed the rendering of certain code-blocks in the documentation examples which were appearing as plain text ([#179](https://github.com/JeschkeLab/DeerLab/issues/179), [#184](https://github.com/JeschkeLab/DeerLab/pull/184)).
- Fixed the execution and rendering of the model examples in the documentation ([#189](https://github.com/JeschkeLab/DeerLab/issues/189), [#190](https://github.com/JeschkeLab/DeerLab/pull/190)).
- Fixed a bug in ``snlls`` where one of the linear least-squares solvers can return results that violate the boundary conditions due to float-point round-off errors ([#177](https://github.com/JeschkeLab/DeerLab/issues/177), [#188](https://github.com/JeschkeLab/DeerLab/pull/188)).


Release v0.13.1 - May 2021
---------------------------------

Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v0.13.1
v0.13.2
1 change: 1 addition & 0 deletions conda.recipe/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
$PYTHON setup.py install # Python command to install the script.
6 changes: 2 additions & 4 deletions conda.recipe/meta.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
{% set version = "v0.13.0" %}

package:
name: deerlab
version: {{ version }}
version: VERSION

source:
git_rev: {{ version }}
git_rev: VERSION
git_url: https://github.com/JeschkeLab/DeerLab.git

requirements:
Expand Down
3 changes: 1 addition & 2 deletions deerlab/dd_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ def docstr_example(fcnstr):
import numpy as np
model = dl.{fcnstr}
r = np.linspace(2,5,400)
info = model()
par0 = info['Start']
par0 = model.start
P = model(r,par0)
plt.figure(figsize=[6,3])
plt.plot(r,P)
Expand Down
10 changes: 6 additions & 4 deletions deerlab/snlls.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,9 @@ def snlls(y, Amodel, par0, lb=None, ub=None, lbl=None, ubl=None, nnlsSolver='cvx
elif nnlsSolver == 'cvx':
linSolver = lambda AtA, Aty: cvxnnls(AtA, Aty, tol=lin_tol, maxiter=lin_maxiter)
parseResult = lambda result: result

# Ensure correct formatting and shield against float-point errors
validateResult = lambda result: np.maximum(lbl,np.minimum(ubl,np.atleast_1d(result)))
# ----------------------------------------------------------

# Containers for alpha-update checks
Expand All @@ -319,9 +322,9 @@ def linear_problem(A,optimize_alpha,alpha):

# Solve the linear least-squares problem
result = linSolver(AtA, Aty)
linfit = parseResult(result)
linfit = np.atleast_1d(linfit)
result = parseResult(result)
linfit = validateResult(result)

return linfit, alpha
#===========================================================================

Expand Down Expand Up @@ -566,4 +569,3 @@ def _plot(subsets,y,yfit,show):
plt.close()
return fig
# ===========================================================================================

2 changes: 1 addition & 1 deletion deerlab/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ def Jacobian(fcn, x0, lb, ub):
"""
J = opt._numdiff.approx_derivative(fcn,x0,method='2-point',bounds=(lb,ub))
J = np.atleast_2d(J)
J = np.atleast_2d(J)
return J
#===============================================================================

Expand Down
12 changes: 6 additions & 6 deletions examples/basic/ex_bootstrapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
import deerlab as dl

# %% [markdown]
# Uncomment and use the following lines if you have experimental data:
#
# t,Vexp = dl.deerload('my\path\4pdeer_data.DTA')
# Vexp = dl.correctphase(Vexp)
# t = dl.correctzerotime(Vexp,t)
#
# Uncomment and use the following lines if you have experimental data::
#
# t,Vexp = dl.deerload('my\path\4pdeer_data.DTA')
# Vexp = dl.correctphase(Vexp)
# t = dl.correctzerotime(Vexp,t)
#

# %% [markdown]
# In this example we will use simulated data instead:
Expand Down
12 changes: 6 additions & 6 deletions examples/basic/ex_fitting_4pdeer.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
# Load and pre-process data
# ---------------------------
#
# Uncomment and use the following lines if you have experimental data:
#
# t, Vexp = dl.deerload('my\path\4pdeer_data.DTA')
# Vexp = dl.correctphase(Vexp)
# t = dl.correctzerotime(Vexp,t)
#
# Uncomment and use the following lines if you have experimental data::
#
# t, Vexp = dl.deerload('my\path\4pdeer_data.DTA')
# Vexp = dl.correctphase(Vexp)
# t = dl.correctzerotime(Vexp,t)
#
# In this example we will use simulated data instead.

# %% [markdown]
Expand Down
Loading

0 comments on commit dd71314

Please sign in to comment.