Skip to content

Commit

Permalink
Merge pull request #152 from biosimulators/poetry-build
Browse files Browse the repository at this point in the history
Poetry build
  • Loading branch information
jcschaff authored Sep 17, 2024
2 parents 8324de3 + 18df340 commit 65c9127
Show file tree
Hide file tree
Showing 12 changed files with 5,507 additions and 195 deletions.
1 change: 1 addition & 0 deletions .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ exclude =
tests/*
docs-src/*
build/*
.venv/
42 changes: 42 additions & 0 deletions .github/actions/setup-poetry-env/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: "setup-poetry-env"
description: "Composite action to setup the Python and poetry environment."

inputs:
python-version:
required: false
description: "The python version to use"
default: "3.11"

runs:
using: "composite"
steps:
- name: Set up python
uses: actions/setup-python@v5
with:
python-version: ${{ inputs.python-version }}

- name: Install Poetry
env:
POETRY_VERSION: "1.7.1"
run: curl -sSL https://install.python-poetry.org | python - -y
shell: bash

- name: Add Poetry to Path
run: echo "$HOME/.local/bin" >> $GITHUB_PATH
shell: bash

- name: Configure Poetry virtual environment in project
run: poetry config virtualenvs.in-project true
shell: bash

- name: Load cached venv
id: cached-poetry-dependencies
uses: actions/cache@v4
with:
path: .venv
key: venv-${{ runner.os }}-${{ inputs.python-version }}-${{ hashFiles('poetry.lock') }}

- name: Install dependencies
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
run: poetry install --no-interaction --with bngl,cellml,lems,neuroml,sbml,simularium,escher,containers,logging,rba,smoldyn
shell: bash
118 changes: 33 additions & 85 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
getVersionNumber:
name: Get version number
if: "startsWith(github.ref, 'refs/tags/') && !contains(github.event.head_commit.message, '[skip ci]') && github.actor != 'allcontributors'"
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
outputs:
version: ${{ steps.get-version-number.outputs.version }}
steps:
Expand All @@ -21,33 +21,22 @@ jobs:
echo "version=$version" >> $GITHUB_OUTPUT
build:
name: Lint, test, and compile documentation
name: Lint, test, and compile docs (python ${{ matrix.python-version }})
if: "!contains(github.event.head_commit.message, '[skip ci]') && github.actor != 'allcontributors'"
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
strategy:
matrix:
python-version: [ "3.10" ]
fail-fast: false
defaults:
run:
shell: bash
steps:
- name: Checkout repository
uses: actions/checkout@v2
uses: actions/checkout@v4
with:
fetch-depth: 1

- name: Install Python
uses: actions/setup-python@v2
with:
python-version: '3.9.9' # no particular microversion of 3.9 is required; 3.9.8 behaves oddly in GitHub actions

- name: Setup pip cache
uses: actions/cache@v2
with:
path: /opt/hostedtoolcache/Python
key: ${{ runner.os }}-pip-${{ hashFiles('requirements.txt') }}-${{ hashFiles('requirements.optional.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Install pip and setuptools
run: |
python -m pip install --upgrade pip==23.0.1
python -m pip install --upgrade setuptools
- name: Install Java # for pyNeuroML
uses: actions/setup-java@v2
with:
Expand All @@ -69,32 +58,21 @@ jobs:
singularity-version: 3.7.1

# install package
- name: Install the package
run: |
python -m pip install git+https://github.com/biosimulators/RBApy.git#egg=rbapy
python -m pip install .[all]
# lint
- name: Install flake8
run: python -m pip install flake8
- name: Set up the environment
uses: ./.github/actions/setup-poetry-env
with:
python-version: ${{ matrix.python-version }}

- name: Lint the package
run: python -m flake8

# test and upload coverage report to Codecov
- name: Install pytest
run: python -m pip install pytest pytest-cov

- name: Install the requirements for the tests
run: python -m pip install .[tests]
run: poetry run python -m flake8

- name: Run the tests
uses: GabrielBB/xvfb-action@v1
env:
MPLBACKEND: PDF
# BIOSIMULATORS_API_ENDPOINT: https://api.biosimulators.dev/ # uncomment to execute tests with the dev deployment
with:
run: python -m pytest tests/ --cov=./biosimulators_utils --cov-report=xml
run: poetry run python -m pytest tests/ --cov=./biosimulators_utils --cov-report=xml

- name: Upload the coverage report to Codecov
uses: codecov/codecov-action@v2
Expand All @@ -105,21 +83,21 @@ jobs:

# compile documentation
- name: Install the requirements for compiling the documentation
run: python -m pip install -r docs-src/requirements.txt
run: poetry install --with docs

- name: Compile the documentation
run: |
sphinx-apidoc . setup.py --output-dir docs-src/source --force --module-first --no-toc
poetry run sphinx-apidoc . setup.py --output-dir docs-src/source --force --module-first --no-toc
mkdir -p docs-src/_static
sphinx-build docs-src docs
poetry run sphinx-build docs-src docs
release:
name: Release a new version
needs: [getVersionNumber, build]
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v4
with:
fetch-depth: 1
ref: dev
Expand All @@ -130,44 +108,21 @@ jobs:
git config --local user.name "biosimulatorsdaemon"
git config pull.rebase false
- name: Install Python
uses: actions/setup-python@v2
- name: Set up the environment
uses: ./.github/actions/setup-poetry-env
with:
python-version: '3.9'

- name: Setup pip cache
uses: actions/cache@v2
with:
path: /opt/hostedtoolcache/Python
key: ${{ runner.os }}-pip-${{ hashFiles('requirements.txt') }}-${{ hashFiles('requirements.optional.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Install pip and setuptools
run: |
python -m pip install pip==20.3.4
python -m pip install --upgrade setuptools
# install package
- name: Install the package
run: python -m pip install .[all]
python-version: ${{ matrix.python-version }}

# update Identifiers.org namespaces
- name: Update Identifiers.org namespaces
run: python -c "from biosimulators_utils.utils.identifiers_org import get_identifiers_org_namespaces; get_identifiers_org_namespaces(reload=True);"

- name: Install pytest
run: python -m pip install pytest

- name: Install the requirements for the tests
run: python -m pip install .[tests]
run: poetry run python -c "from biosimulators_utils.utils.identifiers_org import get_identifiers_org_namespaces; get_identifiers_org_namespaces(reload=True);"

- name: Test the updated Identifiers.org namespaces
uses: GabrielBB/xvfb-action@v1
env:
MPLBACKEND: PDF
with:
run: python -m pytest tests/utils/test_identifiers_org_utils.py
run: poetry run python -m pytest tests/utils/test_identifiers_org_utils.py

- id: commit-identifiers-namespaces
name: Commit the Identifiers.org namespaces
Expand All @@ -187,13 +142,13 @@ jobs:
# compile and push documentation
- name: Install the requirements for compiling the documentation
run: python -m pip install -r docs-src/requirements.txt
run: poetry install --with docs

- name: Compile the documentation
run: |
sphinx-apidoc . setup.py --output-dir docs-src/source --force --module-first --no-toc
poetry run sphinx-apidoc . setup.py --output-dir docs-src/source --force --module-first --no-toc
mkdir -p docs-src/_static
sphinx-build docs-src docs
poetry run sphinx-build docs-src docs
- id: commit-docs
name: Commit the compiled documentation
Expand Down Expand Up @@ -228,19 +183,12 @@ jobs:
release_name: Release ${{ needs.getVersionNumber.outputs.version }}

# Create PyPI release
- name: Install twine
run: |
python -m pip install wheel twine
- name: Create packages to upload to PyPI
run: |
python setup.py sdist
python setup.py bdist_wheel
poetry build
- name: Upload packages to PyPI
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }}
POETRY_PYPI_TOKEN_PYPI: ${{ secrets.PYPI_TOKEN }}
run: |
twine upload dist/*
poetry publish --no-interaction --username __token__ --password $POETRY_PYPI_TOKEN_PYPI
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@ docs/.buildinfo
docs/.doctrees/
docs/_raw_sources/
docs/_sources/

.python-version
17 changes: 13 additions & 4 deletions biosimulators_utils/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,20 @@ def convert_docker_image_to_singularity(docker_image_url: str, singularity_filen
Returns:
:obj:`str`: path where Singularity image was saved
"""
cmd: list[str] = ['singularity', 'build']

# We need to break the command up into two parts: a docker pull using only docker,
# Then a singularity build from the pulled (now local) image. This is due to docker
# API version error that appear to be coming from singularity's client.
# Unless we upgrade a major version, this is our solution.
if ':' not in docker_image_url:
docker_image_url += ':latest'

intermediate_archive_name = "docker_image_to_test.tar"
cmd1: list[str] = ['docker', 'image', 'save', docker_image_url, "-o", intermediate_archive_name]
subprocess.check_call(cmd1)

cmd2: list[str] = ['singularity', 'build']

if not singularity_filename:
singularity_filename: str = os.path.join(
os.path.expanduser('~'), '.biosimulators-utils', 'singularity',
Expand All @@ -132,11 +141,11 @@ def convert_docker_image_to_singularity(docker_image_url: str, singularity_filen
if not os.path.isdir(os.path.dirname(singularity_filename)):
os.makedirs(os.path.dirname(singularity_filename))

cmd.append(singularity_filename)
cmd2.append(singularity_filename)

cmd.append('docker-daemon://' + docker_image_url)
cmd2.append('docker-archive:' + intermediate_archive_name)

if not os.path.isfile(singularity_filename):
subprocess.check_call(cmd)
subprocess.check_call(cmd2)

return singularity_filename
3 changes: 0 additions & 3 deletions docs-src/requirements.txt

This file was deleted.

Loading

0 comments on commit 65c9127

Please sign in to comment.