Skip to content

Commit

Permalink
investigate
Browse files Browse the repository at this point in the history
  • Loading branch information
cbouy committed Mar 10, 2024
1 parent 492b303 commit d4b5b15
Show file tree
Hide file tree
Showing 4 changed files with 205 additions and 99 deletions.
160 changes: 160 additions & 0 deletions .github/workflows/_build-package.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
name: build-package
on:
workflow_call:
inputs:
check-prerelease:
default: false
required: false
type: boolean
test-files:
default: true
required: false
type: boolean
test-imports:
default: false
required: false
type: boolean
cache-package:
default: true
required: false
type: boolean
upload-package:
default: false
required: false
type: boolean

defaults:
run:
shell: bash -l {0}

jobs:
build:
name: Build ProLIF package
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Get prerelease version tags
if: inputs.check-prerelease
id: prerelease-check
run: |
py_dirty_tag=$(awk '/__version__ = "[[:digit:]+]\.[[:digit:]+]\.[[:digit:]+]\-.+"/ {print $3}' ./prolif/_version.py)
py_is_pre=$(test -z "$py_dirty_tag" && echo "false" || echo "true")
echo "py=$py_is_pre" >> $GITHUB_OUTPUT
- name: Fail if prerelease is not correctly versioned
if: (inputs.check-prerelease) && !( steps.prerelease-check.outputs.py )
uses: actions/github-script@v3
with:
script: |
core.setFailed("Version is not tagged as a prerelease")
- name: Install python with pip
uses: actions/setup-python@v4
with:
python-version: "3.10"
cache: "pip"

- name: Install dependencies for packaging
run: |
pip install setuptools wheel build virtualenv
- name: Check python installation
run: |
which python
python --version
pip --version
pip list
- name: Build package
run: |
python -m build .
- name: List output
run: |
ls -lah dist/*
- name: List .tar.gz content
run: |
tar -ztvf dist/prolif-*.tar.gz
- name: Ensure tests and data included in source dist
if: inputs.test-files
run: |
tar -ztvf dist/prolif-*.tar.gz | grep -E 'prolif-.+/tests/.+' || exit 1
tar -ztvf dist/prolif-*.tar.gz | grep -E 'prolif-.+/tests/conftest.py' || exit 1
tar -ztvf dist/prolif-*.tar.gz | grep -E 'prolif-.+/tests/plotting/.+' || exit 1
tar -ztvf dist/prolif-*.tar.gz | grep -E 'prolif-.+/data/.+' || exit 1
tar -ztvf dist/prolif-*.tar.gz | grep -E 'prolif-.+/data/vina/.+' || exit 1
- name: Cache package
if: inputs.cache-package
uses: actions/cache/save@v3
with:
path: |
dist/prolif-*.whl
dist/prolif-*.tar.gz
key: prolif-${{ runner.os }}-${{ github.sha }}

- name: Expose package as artifact
if: inputs.upload-package
uses: actions/upload-artifact@v4
with:
name: prolif-package
path: |
dist/prolif-*.whl
dist/prolif-*.tar.gz
if-no-files-found: error
retention-days: 20

test-build:
name: Test ProLIF build
runs-on: ubuntu-latest
needs: [build]
if: (inputs.test-imports) && (inputs.cache-package)

steps:
- name: Install python with pip
uses: actions/setup-python@v4
with:
python-version: "3.10"
cache: "pip"

- name: Install requirements
run: |
pip install rdkit
- name: Retrieve cached package
uses: actions/cache/restore@v3
id: cache-prolif
with:
path: |
dist/prolif-*.whl
dist/prolif-*.tar.gz
key: prolif-${{ runner.os }}-${{ github.sha }}

- uses: actions/checkout@v4

- name: Install from tar.gz
run: |
pip install dist/prolif-*.tar.gz
- name: Test tar.gz install
working-directory: scripts/
run: |
python test_build.py
- name: Remove previous ProLIF install
run: |
pip uninstall -y prolif
- name: Install from wheel
run: |
pip install dist/prolif-*.whl
- name: Test wheel install
working-directory: scripts/
run: |
python test_build.py
58 changes: 20 additions & 38 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,48 +12,30 @@ env:
IS_PRERELEASE: ${{ github.event_name == 'workflow_dispatch' }}

jobs:
build-n-publish:
name: Build and publish to PyPI
build:
name: Build package
uses: ./.github/workflows/_build-package.yml
with:
check-prerelease: ${{ env.IS_PRERELEASE }}
cache-package: true
upload-package: true
test-files: true
test-imports: true

publish:
name: Publish to PyPI
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Get prerelease version tags
if: env.IS_PRERELEASE == 'true'
run: |
py_dirty_tag=$(awk '/__version__ = "[[:digit:]+]\.[[:digit:]+]\.[[:digit:]+]\-.+"/ {print $3}' ./prolif/_version.py)
py_is_pre=$(test -z "$py_dirty_tag" && echo "false" || echo "true")
echo "py_is_pre=$py_is_pre" >> $GITHUB_ENV
- name: Fail if prerelease is not correctly versioned
if: ( env.IS_PRERELEASE == 'true' ) && !( env.py_is_pre )
uses: actions/github-script@v3
with:
script: |
core.setFailed("Versions are not tagged as a prerelease")
- name: Install python with pip
uses: actions/setup-python@v4
- name: Retrieve cached package
uses: actions/cache/restore@v3
id: cache-prolif
with:
python-version: 3.8

- name: Install dependencies for packaging
run: |
pip install build
- name: Check python installation
run: |
which python
python --version
pip --version
pip list
- name: Build package
run: |
python -m build
path: |
dist/prolif-*.whl
dist/prolif-*.tar.gz
key: prolif-${{ runner.os }}-${{ github.sha }}

- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_TOKEN }}
password: ${{ secrets.PYPI_TOKEN }}
72 changes: 11 additions & 61 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,17 @@ concurrency:
cancel-in-progress: true

jobs:
tests:
build:
name: Build package and test build
uses: ./.github/workflows/_build-package.yml
with:
check-prerelease: ${{ env.IS_PRERELEASE }}
cache-package: true
upload-package: true
test-files: true
test-imports: true

unit-tests:
name: ${{ matrix.label }}
runs-on: ${{ matrix.os }}
# only run once if internal PR
Expand Down Expand Up @@ -74,16 +84,6 @@ jobs:
pip install .[dev]
pip list
- name: Build
run: |
python -m build
- name: Ensure tests and data included in source dist
run: |
tar -ztvf dist/prolif-*.tar.gz | grep -E 'prolif-.+/tests/.+' || exit 1
tar -ztvf dist/prolif-*.tar.gz | grep -E 'prolif-.+/data/.+' || exit 1
tar -ztvf dist/prolif-*.tar.gz | grep -E 'prolif-.+/data/vina/.+' || exit 1
- name: Run tests
run: |
pytest --color=yes --disable-pytest-warnings --cov=prolif --cov-report=xml tests/
Expand All @@ -96,53 +96,3 @@ jobs:
fail_ci_if_error: true
verbose: true
token: ${{ secrets.CODECOV_TOKEN }}

- name: Build
run: |
python -m build
- name: Remove previous ProLIF install
run: |
pip uninstall -y prolif
- name: Install from tar.gz
run: |
pip install dist/prolif-*.tar.gz
- name: Test tar.gz install
working-directory: /
run: |
python <<EOF
from pathlib import Path
from contextlib import suppress
import prolif
print(prolif.__version__)
from prolif.plotting.network import LigNetwork
assert Path(prolif.datafiles.TOP).is_file()
with suppress(ImportError, ModuleNotFoundError):
import tests
assert next(Path(tests.__file__).parent.glob("test_fingerprint.py"), None) is None
EOF
- name: Remove previous ProLIF install
run: |
pip uninstall -y prolif
- name: Install from wheel
run: |
pip install dist/prolif-*.whl
- name: Test wheel install
working-directory: /
run: |
python <<EOF
from pathlib import Path
from contextlib import suppress
import prolif
print(prolif.__version__)
from prolif.plotting.network import LigNetwork
assert Path(prolif.datafiles.TOP).is_file()
with suppress(ImportError, ModuleNotFoundError):
import tests
assert next(Path(tests.__file__).parent.glob("test_fingerprint.py"), None) is None
EOF
14 changes: 14 additions & 0 deletions scripts/test_build.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from contextlib import suppress
from pathlib import Path

import prolif
from prolif.plotting.network import LigNetwork

Check notice

Code scanning / CodeQL

Unused import Note test

Import of 'LigNetwork' is not used.

print(prolif.__version__)

assert Path(prolif.datafiles.TOP).is_file()

with suppress(ImportError, ModuleNotFoundError):
import tests

assert next(Path(tests.__file__).parent.glob("test_fingerprint.py"), None) is None

0 comments on commit d4b5b15

Please sign in to comment.