Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix build test #193

Merged
merged 3 commits into from
Mar 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
161 changes: 161 additions & 0 deletions .github/workflows/_build-package.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
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: Checkout
uses: actions/checkout@v4

- 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 }}

- 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
61 changes: 20 additions & 41 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,52 +8,31 @@ defaults:
run:
shell: bash -l {0}

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: ${{ github.event_name == 'workflow_dispatch' }}
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
- name: Retrieve cached package
uses: actions/cache/restore@v3
id: cache-prolif
with:
script: |
core.setFailed("Versions are not tagged as a prerelease")

- name: Install python with pip
uses: actions/setup-python@v4
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 }}
79 changes: 16 additions & 63 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,20 @@ concurrency:
cancel-in-progress: true

jobs:
tests:
name: ${{ matrix.label }}
build:
name: Build
# only run once if internal PR
if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository
uses: ./.github/workflows/_build-package.yml
with:
check-prerelease: ${{ github.event_name == 'workflow_dispatch' }}
cache-package: true
upload-package: true
test-files: true
test-imports: true

unit-tests:
name: Test ${{ matrix.label }}
runs-on: ${{ matrix.os }}
# only run once if internal PR
if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository
Expand All @@ -42,7 +54,8 @@ jobs:
coverage: false

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

- name: Setup Conda
uses: conda-incubator/setup-miniconda@v2
Expand Down Expand Up @@ -74,16 +87,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 +99,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
3 changes: 3 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
graft tests

global-exclude *~ *.py[cod] *.so
2 changes: 1 addition & 1 deletion prolif/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "2.0.2"
__version__ = "2.0.3-rc1"
2 changes: 0 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,6 @@ include = ["prolif*"]
[tool.setuptools.package-data]
"prolif.data" = ["*"]
"prolif.data.vina" = ["*"]
"tests" = ["*"]
"tests.plotting" = ["*"]

[tool.setuptools.dynamic]
version = { attr = "prolif._version.__version__" }
Expand Down
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
Dismissed Show dismissed Hide dismissed

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
Loading