Skip to content

Commit

Permalink
Merge pull request #356 from michellab/feature-web
Browse files Browse the repository at this point in the history
Feature web (a.k.a. BioSimSpace 2023.0.0) [ci skip]
  • Loading branch information
lohedges committed Sep 26, 2022
2 parents c3a1715 + c39cfdb commit 0fc24e0
Show file tree
Hide file tree
Showing 167 changed files with 5,047 additions and 869 deletions.
100 changes: 75 additions & 25 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,41 @@ on:
pull_request:
branches: [ devel ]

# Note that push and pull-request builds are automatically
# now skipped by GitHub if
# [skip ci], [ci skip], [no ci], [skip actions], or [actions skip]
# are in the commit message. We don't need to check for this ourselves.

jobs:
build:
name: build (${{ matrix.python-version }}, ${{ matrix.os }})
runs-on: ${{ matrix.os }}
if: "!contains(github.event.head_commit.message, 'ci skip')"
name: build (${{ matrix.python-version }}, ${{ matrix.platform.name }})
runs-on: ${{ matrix.platform.os }}
strategy:
max-parallel: 6
max-parallel: 9
fail-fast: false
matrix:
os: ["ubuntu-latest", "macos-latest"]
python-version: ["3.7", "3.8", "3.9"]
platform:
- {
name: "windows",
os: "windows-latest",
shell: "pwsh"
}
- {
name: "linux",
os: "ubuntu-latest",
shell: "bash -l {0}"
}
- {
name: "macos",
os: "macos-latest",
shell: "bash -l {0}"
}
environment:
name: biosimspace-build
defaults:
run:
shell: ${{ matrix.platform.shell }}
env:
SIRE_DONT_PHONEHOME: 1
SIRE_SILENT_PHONEHOME: 1
Expand All @@ -31,35 +53,62 @@ jobs:
miniforge-version: latest
miniforge-variant: Mambaforge
use-mamba: true
- name: Clone repositories
run: |
git clone https://github.com/michellab/Sire
git clone https://github.com/michellab/BioSimSpace
- name: Checkout the head branch if a pull request
run: |
cd BioSimSpace
git checkout "$HEAD_BRANCH"
env:
HEAD_BRANCH: ${{ github.head_ref }}
#
- name: Clone the devel branch (push to devel)
run: git clone https://github.com/michellab/BioSimSpace
if: github.event_name != 'pull_request'
#
- name: Clone the feature branch (pull request to devel)
run: git clone -b ${{ github.head_ref }} --single-branch https://github.com/michellab/BioSimSpace
if: github.event_name == 'pull_request'
#
- name: Setup Conda
shell: bash -l {0}
run: mamba install -y -c conda-forge boa anaconda-client
run: mamba install -y -c conda-forge boa anaconda-client pip-requirements-parser
#
- name: Update Conda recipe
run: BioSimSpace/actions/update_recipe.sh
run: python ${{ github.workspace }}/BioSimSpace/actions/update_recipe.py
#
- name: Prepare build location
run: mkdir ${{ github.workspace }}/build
#
- name: Build Conda package using mamba build
run: conda mambabuild --croot ${{ github.workspace }}/build -c conda-forge -c michellab ${{ github.workspace }}/BioSimSpace/recipes/biosimspace
if: matrix.platform.name != 'windows' || matrix.python-version != '3.7'
#
- name: Build Conda package using conda build
run: conda build --croot ${{ github.workspace }}/build -c conda-forge -c michellab ${{ github.workspace }}/BioSimSpace/recipes/biosimspace
if: matrix.platform.name == 'windows' && matrix.python-version == '3.7'
#
- name: Collect failed artifacts
run:
python ${{ github.workspace }}/BioSimSpace/actions/collect_failed.py
env:
BSS_SRC_DIR: ${{ github.workspace }}/BioSimSpace
SIRE_SRC_DIR: ${{ github.workspace }}/Sire
- name: Build Conda package
shell: bash -l {0}
run: conda mambabuild -c conda-forge -c michellab/label/dev BioSimSpace/recipes/biosimspace
BUILD_DIR: ${{ github.workspace }}/build
if: ${{ failure() }}
#
- uses: actions/upload-artifact@v2
with:
name: build-${{ matrix.platform.name }}-${{matrix.python-version}}-${{ github.sha }}
path: ${{ github.workspace }}/build/*/biosimspace-*.tar.bz2
retention-days: 10
if: ${{ success() }}
#
- uses: actions/upload-artifact@v2
with:
name: failed-${{ matrix.platform.name }}-${{matrix.python-version}}-${{ github.sha }}
path: ${{ github.workspace }}/build/failed.tar.bz2
retention-days: 1
if: ${{ failure() }}
#
- name: Upload Conda package
shell: bash -l {0}
run: BioSimSpace/actions/upload_package.sh
run: python ${{ github.workspace }}/BioSimSpace/actions/upload_package.py
env:
SRC_DIR: ${{ github.workspace }}/BioSimSpace
ANACONDA_TOKEN: ${{ secrets.ANACONDA_TOKEN }}
if: github.event_name != 'pull_request'
#
- name: Build documentation
shell: bash -l {0}
run: |
Expand All @@ -73,7 +122,8 @@ jobs:
env:
PYTHON_VERSION: ${{ matrix.python-version }}
SRC_DIR: ${{ github.workspace }}/BioSimSpace
if: github.event_name == 'push' && matrix.python-version == 3.7 && matrix.os == 'ubuntu-latest'
if: github.event_name == 'push' && matrix.python-version == 3.7 && matrix.platform.name == 'linux'
#
- name: Update website
run: |
git clone https://github.com/michellab/BioSimSpaceWebsite
Expand All @@ -89,4 +139,4 @@ jobs:
env:
EMAIL: ${{ secrets.EMAIL }}
WEBSITE_TOKEN: ${{ secrets.WEBSITE_TOKEN }}
if: github.event_name == 'push' && matrix.python-version == 3.7 && matrix.os == 'ubuntu-latest'
if: github.event_name == 'push' && matrix.python-version == 3.7 && matrix.platform.name == 'linux'
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ output.yaml

# Trajectory artifacts.
*_offsets.npz
*.lock

# Scratch space.
.idea/

# VSCode config
.vscode/

# Conda recipe (it is auto-generated)
recipes/biosimspace/meta.yaml
21 changes: 7 additions & 14 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -121,32 +121,25 @@ Alternatively, to install BioSimSpace from source:
(Before starting, you'll need a working `Git <https://git-scm.com>`__ installation.)

BioSimSpace is built on top of the `Sire <https://github.com/michellab/Sire>`__
molecular simulation framework. To download and install Sire:

.. code-block:: bash
git clone https://github.com/michellab/Sire
cd Sire
./compile_sire.sh
Assuming the default installation path, this will install Sire into ``$HOME/sire.app``.

(Note that the installation is slow and can take in excess of an hour.)
molecular simulation framework. To download and install Sire, follow the
instructions `here <https://github.com/michellab/Sire#installation>`__, making
sure that BioSimSpace's dependencies are installed into the Sire conda
environment at the point at which Sire is installed.

Next you will need to download BioSimSpace and install it into your Sire
application. (The following assumes the default Sire installation path.)
Conda environment.

.. code-block:: bash
git clone https://github.com/michellab/BioSimSpace
cd BioSimSpace/python
$HOME/sire.app/bin/python setup.py install
python setup.py install
Once finished, you can test the installation by running:

.. code-block:: bash
$HOME/sire.app/bin/ipython
python
Then try importing the BioSimSpace package:

Expand Down
45 changes: 45 additions & 0 deletions actions/collect_failed.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@

# Script that collects as much as it can from a failed conda build so that it can
# be stored as a GitHub Actions artifact for download and further debugging

import os
import sys
import glob
import tarfile

if "BUILD_DIR" not in os.environ:
try:
os.environ["BUILD_DIR"] = sys.argv[1]
except Exception:
print("You need to supply BUILD_DIR")
sys.exit(-1)

build_dir = os.environ["BUILD_DIR"]

# We want to bzip up the last 'sire-*' and all 'broken-*' directories in build_dir
work_dirs = glob.glob(os.path.join(build_dir, "biosimspace_*", "work", "build"))
broken_dirs = glob.glob(os.path.join(build_dir, "broke*"))

if len(work_dirs) > 0:
work_dirs = [work_dirs[-1]]

zipdirs = work_dirs + broken_dirs

output_filename = os.path.join(build_dir, "failed.tar.bz2")

print(f"Zipping up {zipdirs} to {output_filename}")

def filter_function(tarinfo):
filename = tarinfo.name
#print(filename)
if filename.find('.git') != -1:
#print("excluded!")
return None
else:
return tarinfo

with tarfile.open(output_filename, "w:bz2") as tar:
for dir in zipdirs:
tar.add(dir, arcname=os.path.basename(dir), filter=filter_function)

print("Complete :-)")
47 changes: 47 additions & 0 deletions actions/parse_requirements.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@


def parse_requirements(filename):
"""Parse the requirements and return (in conda notation)
the requirements for this system
"""
try:
from pip_requirements_parser import RequirementsFile
except ImportError as e:
print("\n\n[ERROR] ** You need to install pip-requirements-parser")
print("Run `conda install pip-requirements-parser\n\n")
raise e

from pkg_resources import evaluate_marker

reqs = RequirementsFile.from_file(filename).to_dict()["requirements"]

deps = {}

for req in reqs:
name = req["name"]
specifier = req["specifier"]
marker = req["marker"]

if len(specifier) == 0:
specifier = ""
else:
specifier = specifier[0]

if marker is not None:
# check to see if this line fits this platform
include = evaluate_marker(marker)
else:
include = True

if include:
deps[name] = specifier

reqs = list(deps.keys())
reqs.sort()

result = []

for req in reqs:
result.append(f"{req}{deps[req]}")

return result
71 changes: 71 additions & 0 deletions actions/update_recipe.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@

import sys
import os
import subprocess

script = os.path.abspath(sys.argv[0])

# we want to import the 'get_requirements' package from this directory
sys.path.insert(0, os.path.dirname(script))

from parse_requirements import parse_requirements

# go up one directories to get the source directory
# (this script is in BioSimSpace/actions/)
srcdir = os.path.dirname(os.path.dirname(script))

condadir = os.path.join(srcdir, "recipes", "biosimspace")

print(f"conda recipe in {condadir}")

# Store the name of the recipe and template YAML files.
recipe = os.path.join(condadir, "meta.yaml")
template = os.path.join(condadir, "template.yaml")

# Now parse all of the requirements
run_reqs = parse_requirements(os.path.join(srcdir, "requirements.txt"))
print(run_reqs)
build_reqs = parse_requirements(os.path.join(srcdir, "requirements_build.txt"))
print(build_reqs)


def run_cmd(cmd):
p = subprocess.Popen(cmd.split(), stdout=subprocess.PIPE)
return str(p.stdout.read().decode("utf-8")).lstrip().rstrip()

gitdir = os.path.join(srcdir, ".git")

# Get the BSS branch.
branch = run_cmd(f"git --git-dir={gitdir} --work-tree={srcdir} rev-parse --abbrev-ref HEAD")
print(branch)

lines = open(template, "r").readlines()


def dep_lines(deps):
lines = []

for dep in deps:
lines.append(f" - {dep}\n")

return "".join(lines)


run_reqs = dep_lines(run_reqs)

if len(build_reqs) > 0:
build_reqs = f" build:\n{dep_lines(build_reqs)}"
else:
build_reqs = ""


with open(recipe, "w") as FILE:
for line in lines:
if line.find("BSS_BUILD_REQUIREMENTS") != -1:
line = build_reqs
elif line.find("BSS_RUN_REQUIREMENTS") != -1:
line = run_reqs
else:
line = line.replace("BSS_BRANCH", branch)

FILE.write(line)
Loading

0 comments on commit 0fc24e0

Please sign in to comment.