Skip to content

Commit

Permalink
Merge pull request #661 from padix-key/py-version
Browse files Browse the repository at this point in the history
Support Python 3.13
  • Loading branch information
padix-key authored Oct 14, 2024
2 parents 231eefe + 37ecd28 commit 204c25a
Show file tree
Hide file tree
Showing 11 changed files with 110 additions and 64 deletions.
77 changes: 45 additions & 32 deletions .github/workflows/test_and_deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ concurrency:
cancel-in-progress: true

env:
CIBW_BUILD: cp310-* cp311-* cp312-*
CIBW_BUILD: cp310-* cp311-* cp312-* cp313-*
CIBW_TEST_EXTRAS: test
CIBW_TEST_COMMAND: >
pytest {project}
Expand All @@ -42,7 +42,8 @@ jobs:
with:
python-version: "3.12"
- name: Install ruff
run: pip install ruff==0.5.2
# Keep in sync with the ruff version in pyproject.toml
run: pip install ruff==0.6.9
- name: Check code formatting
run: ruff format --diff
- name: Lint code base
Expand All @@ -58,7 +59,7 @@ jobs:
- uses: actions/checkout@v4
- name: Install cibuildwheel
# MAKE SURE THIS STAYS IN SYNC WITH THE LOWER GHA cibuildwheel
run: pipx install cibuildwheel==2.19.1
run: pipx install cibuildwheel==2.20.0
- id: set-matrix
run: |
MATRIX=$(
Expand Down Expand Up @@ -102,7 +103,7 @@ jobs:

- name: Build & (optionally) test wheels
# MAKE SURE THIS STAYS IN SYNC WITH THE UPPER pipx call to cibuildwheel
uses: pypa/cibuildwheel@v2.19.1
uses: pypa/cibuildwheel@v2.20.0
with:
only: ${{ matrix.dist }}

Expand All @@ -112,6 +113,19 @@ jobs:
path: ./wheelhouse/*.whl


make-sdist:
name: Build source distribution
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Build source distribution
run: pipx run build --sdist
- uses: actions/upload-artifact@v4
with:
name: release-sdist
path: dist//*.tar.gz


test-interfaces:
name: Test interfaces to databases and applications

Expand All @@ -124,12 +138,16 @@ jobs:
- uses: actions/checkout@v4
- uses: conda-incubator/setup-miniconda@v3
with:
mamba-version: "*"
environment-file: environment.yml
miniforge-version: latest
- name: Build distribution
run: pip wheel --no-deps -w dist .
- name: Install distribution
run: pip install .//dist//*.whl
- name: "TEMP: Skip DSSP tests"
# TEMP: Omit DSSP tests for now until conda-forge DSSP is functional
# (https://github.com/conda-forge/dssp-feedstock/pull/4)
run: mamba uninstall dssp
- name: Run tests
# Running NCBI BLAST and SRA takes too long
# The tests on the NCBI Entrez database are not reliable enough
Expand All @@ -143,53 +161,48 @@ jobs:
tests//test_modname.py
tests//database
tests//application
# Use the built distribution for other downstream jobs to reduce build time
- uses: actions/upload-artifact@v4
with:
name: internal-build
path: ./dist/*.whl


test-muscle5:
name: Test interface to Muscle 5

runs-on: ubuntu-latest
needs:
- test-interfaces
defaults:
run:
shell: bash -l {0}

steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
name: internal-build
path: dist
- uses: conda-incubator/setup-miniconda@v3
with:
activate-environment: biotite-dev
miniforge-variant: Mambaforge
python-version: "3.10"
channels: conda-forge,defaults
miniforge-version: latest
python-version: "3.12"
- name: Install Muscle 5
run: conda install -c bioconda "muscle=5"
- name: Build distribution
run: pip wheel -w dist .
- name: Install distribution
- name: Install distribution and pytest
run: pip install .//dist//*.whl pytest
- name: Test Muscle 5 interface
run: pytest --durations=50 tests//application//test_msa.py


make-sdist:
name: Build source distribution
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Build source distribution
run: pipx run build --sdist
- uses: actions/upload-artifact@v4
with:
name: release-sdist
path: dist//*.tar.gz


make-ccd:
name: Compile the CCD subset for structure.info from the wwPDB CCD

runs-on: ubuntu-latest
needs:
- test-and-build
- test-interfaces
defaults:
run:
shell: bash -l {0}
Expand All @@ -198,7 +211,7 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
name: release-cp312-manylinux_x86_64
name: internal-build
path: dist
- uses: actions/setup-python@v3
with:
Expand All @@ -223,7 +236,7 @@ jobs:

runs-on: ubuntu-20.04
needs:
- test-and-build
- test-interfaces
defaults:
run:
shell: bash -l {0}
Expand All @@ -238,12 +251,12 @@ jobs:
fetch-tags: true
- uses: actions/download-artifact@v4
with:
name: release-cp311-manylinux_x86_64
name: internal-build
path: dist
- uses: conda-incubator/setup-miniconda@v2
- uses: conda-incubator/setup-miniconda@v3
with:
environment-file: environment.yml
miniforge-variant: Mambaforge
miniforge-version: latest
- name: Install distribution
run: pip install dist//*.whl
- name: Build base documentation
Expand Down Expand Up @@ -272,12 +285,12 @@ jobs:
runs-on: ubuntu-latest
if: github.event_name != 'release'
needs:
- test-and-build
- test-interfaces
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
name: release-cp312-manylinux_x86_64
name: internal-build
path: dist
- uses: actions/setup-python@v3
with:
Expand Down
7 changes: 3 additions & 4 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@ name: biotite-dev
channels:
- anaconda
- conda-forge
- salilab
- bioconda

dependencies:
- python =3.11
- python =3.12
# Package building
- cython >=3.0
- pip >=10.0
Expand All @@ -27,11 +26,11 @@ dependencies:
- pytest >=7.0
- pytest-codspeed >=2.0
# Code style
- ruff =0.5.2
- ruff =0.6.9 # Keep in sync with the ruff version in pyproject.toml
# Interfaced software in biotite.application (can also be installed separately)
- autodock-vina
- clustalo
- dssp
- dssp =4
- mafft
- muscle =3
- sra-tools
Expand Down
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ test = [
"pytest",
"pytest-codspeed",
]
lint = [
"ruff == 0.6.9"
]

[project.urls]
homepage = "https://www.biotite-python.org"
Expand Down
16 changes: 13 additions & 3 deletions src/biotite/application/dssp/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
__author__ = "Patrick Kunzmann"
__all__ = ["DsspApp"]

from subprocess import SubprocessError
from tempfile import NamedTemporaryFile
import numpy as np
from biotite.application.application import AppState, requires_state
from biotite.application.localapp import LocalApp, cleanup_tempfile
from biotite.application.localapp import LocalApp, cleanup_tempfile, get_version
from biotite.structure.io.pdbx.cif import CIFFile
from biotite.structure.io.pdbx.convert import set_structure

Expand Down Expand Up @@ -72,7 +73,13 @@ def __init__(self, atom_array, bin_path="mkdssp"):
self._array.set_annotation(
"occupancy", np.ones(self._array.array_length(), dtype=float)
)

try:
# The parameters have changed in version 4
self._new_cli = get_version(bin_path)[0] >= 4
except SubprocessError:
# In older versions, the no version is returned with `--version`
# -> a SubprocessError is raised
self._new_cli = False
self._in_file = NamedTemporaryFile("w", suffix=".cif", delete=False)
self._out_file = NamedTemporaryFile("r", suffix=".dssp", delete=False)

Expand All @@ -81,7 +88,10 @@ def run(self):
set_structure(in_file, self._array)
in_file.write(self._in_file)
self._in_file.flush()
self.set_arguments(["-i", self._in_file.name, "-o", self._out_file.name])
if self._new_cli:
self.set_arguments([self._in_file.name, self._out_file.name])
else:
self.set_arguments(["-i", self._in_file.name, "-o", self._out_file.name])
super().run()

def evaluate(self):
Expand Down
34 changes: 34 additions & 0 deletions src/biotite/application/localapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@

import abc
import copy
import re
import subprocess
from os import chdir, getcwd, remove
from pathlib import Path
from subprocess import PIPE, Popen, SubprocessError, TimeoutExpired
from biotite.application.application import (
Application,
Expand Down Expand Up @@ -306,3 +309,34 @@ def cleanup_tempfile(temp_file):
except FileNotFoundError:
# File was already deleted, e.g. due to `TemporaryFile(delete=True)`
pass


def get_version(bin_path, version_option="--version"):
"""
Get the version of a locally installed application.
Parameters
----------
bin_path : str or Path
Path of the application.
version_option : str, optional
The command line option to get the version.
Returns
-------
major, minor : int
The major and minor version number.
"""
output = subprocess.run(
[bin_path, version_option], capture_output=True, text=True
).stdout
# Find matches for version string containing major and minor version
match = re.search(r"\d+\.\d+", output)
if match is None:
raise subprocess.SubprocessError(
f"Could not determine '{Path(bin_path).name}' version "
f"from the string '{output}'"
)
version_string = match.group(0)
splitted = version_string.split(".")
return int(splitted[0]), int(splitted[1])
17 changes: 2 additions & 15 deletions src/biotite/application/muscle/app3.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@
__all__ = ["MuscleApp"]

import numbers
import re
import subprocess
import warnings
from collections.abc import Sequence
from tempfile import NamedTemporaryFile
from biotite.application.application import AppState, VersionError, requires_state
from biotite.application.localapp import cleanup_tempfile
from biotite.application.localapp import cleanup_tempfile, get_version
from biotite.application.msaapp import MSAApp
from biotite.sequence.phylo.tree import Tree

Expand Down Expand Up @@ -54,7 +52,7 @@ class MuscleApp(MSAApp):
"""

def __init__(self, sequences, bin_path="muscle", matrix=None):
major_version = get_version(bin_path)[0]
major_version = get_version(bin_path, "-version")[0]
if major_version != 3:
raise VersionError(f"Muscle 3 is required, got version {major_version}")

Expand Down Expand Up @@ -227,14 +225,3 @@ def align(cls, sequences, bin_path=None, matrix=None, gap_penalty=None):
app.start()
app.join()
return app.get_alignment()


def get_version(bin_path="muscle"):
output = subprocess.run([bin_path, "-version"], capture_output=True, text=True)
# Find matches for version string containing major and minor version
match = re.search(r"\d+\.\d+", output.stdout)
if match is None:
raise subprocess.SubprocessError("Could not determine Muscle version")
version_string = match.group(0)
splitted = version_string.split(".")
return int(splitted[0]), int(splitted[1])
4 changes: 2 additions & 2 deletions src/biotite/application/muscle/app5.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
__all__ = ["Muscle5App"]

from biotite.application.application import AppState, VersionError, requires_state
from biotite.application.localapp import get_version
from biotite.application.msaapp import MSAApp
from biotite.application.muscle.app3 import get_version


class Muscle5App(MSAApp):
Expand Down Expand Up @@ -49,7 +49,7 @@ class Muscle5App(MSAApp):
"""

def __init__(self, sequences, bin_path="muscle"):
major_version = get_version(bin_path)[0]
major_version = get_version(bin_path, "-version")[0]
if major_version < 5:
raise VersionError(
f"At least Muscle 5 is required, got version {major_version}"
Expand Down
8 changes: 4 additions & 4 deletions src/biotite/database/rcsb/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,9 @@ class BasicQuery(SingleQuery):
Examples
--------
>>> query = BasicQuery("tc5b")
>>> query = BasicQuery("Miniprotein Construct")
>>> print(sorted(search(query)))
['1L2Y', '8ANG', '8ANH', '8ANI', '8ANM', '8QWW']
['1L2Y']
"""

def __init__(self, term):
Expand Down Expand Up @@ -346,9 +346,9 @@ class SequenceQuery(SingleQuery):
--------
>>> sequence = "NLYIQWLKDGGPSSGRPPPS"
>>> query = SequenceQuery(sequence, scope="protein", min_identity=0.8)
>>> query = SequenceQuery(sequence, scope="protein", min_identity=0.95)
>>> print(sorted(search(query)))
['1L2Y', '1RIJ', '2JOF', '2LDJ', '2LL5', '2MJ9', '3UC7', '3UC8']
['1L2Y', '2LDJ', '9G22', '9G2N', '9G2O', '9G31', '9G32', '9GDL', '9GDN', '9GDT', '9GDU', '9GE1']
"""

def __init__(self, sequence, scope, min_identity=0.0, max_expect_value=10000000.0):
Expand Down
Loading

0 comments on commit 204c25a

Please sign in to comment.