From fb44b4e21cd55c4132c744a8973f8949bfd4a61f Mon Sep 17 00:00:00 2001 From: Stefan Janssen Date: Wed, 27 Aug 2025 17:51:22 +0200 Subject: [PATCH 1/4] Migrate to py310 (#14) * extend tests to py3.10 * try to import current module OR (for older py versions) from deprecated location * use pytest instead of nose * change flag * add classifiers for py3.9 and py3.10 * trigger tests for even more recent py versions * add classifiers * also test old py versions * Update qiita-plugin-ci.yml * Update qiita-plugin-ci.yml * Update qiita-plugin-ci.yml --- .github/workflows/qiita-plugin-ci.yml | 12 +++++++----- qiita_files/parse/workflow.py | 5 ++++- setup.py | 4 ++++ 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/.github/workflows/qiita-plugin-ci.yml b/.github/workflows/qiita-plugin-ci.yml index 7c2ed51..b88f397 100644 --- a/.github/workflows/qiita-plugin-ci.yml +++ b/.github/workflows/qiita-plugin-ci.yml @@ -9,7 +9,9 @@ jobs: # derived from https://github.com/actions/example-services/blob/master/.github/workflows/postgres-service.yml main: runs-on: ubuntu-latest - + strategy: + matrix: + python-version: ["3.5", "3.6", "3.9", "3.10", "3.11", "3.12"] steps: # Downloads a copy of the code in your repository before running CI tests - name: Check out repository code @@ -19,21 +21,21 @@ jobs: uses: conda-incubator/setup-miniconda@v2 with: auto-update-conda: true - python-version: 3.9 + python-version: ${{ matrix.python-version }} - name: Basic dependencies install shell: bash -l {0} run: | - conda create --yes -n qiita-files python=3.9 h5py pandas scipy numpy + conda create --yes -n qiita-files python=${{ matrix.python-version }} h5py pandas scipy numpy conda activate qiita-files pip install . - pip install sphinx sphinx-bootstrap-theme nose-timer codecov Click + pip install sphinx sphinx-bootstrap-theme pytest-cov codecov Click - name: Main tests shell: bash -l {0} run: | conda activate qiita-files - nosetests --with-doctest --with-coverage --cover-package=qiita_files + pytest --doctest-modules --cov=qiita_files `if (( $(echo "${{ matrix.python-version }} > 3.6" | bc -l) )); then echo "--cov-report=lcov"; else echo ""; fi` lint: runs-on: ubuntu-latest diff --git a/qiita_files/parse/workflow.py b/qiita_files/parse/workflow.py index c1baf16..744e3c8 100644 --- a/qiita_files/parse/workflow.py +++ b/qiita_files/parse/workflow.py @@ -9,7 +9,10 @@ from copy import deepcopy from time import time from functools import update_wrapper -from collections import Iterable +try: + from collections.abc import Iterable +except ImportError: + from collections import Iterable from types import MethodType diff --git a/setup.py b/setup.py index 2f398e5..2580547 100644 --- a/setup.py +++ b/setup.py @@ -20,6 +20,10 @@ Programming Language :: Python Programming Language :: Python :: 3.5 Programming Language :: Python :: 3.6 + Programming Language :: Python :: 3.9 + Programming Language :: Python :: 3.10 + Programming Language :: Python :: 3.11 + Programming Language :: Python :: 3.12 Programming Language :: Python :: Implementation :: CPython Operating System :: POSIX :: Linux Operating System :: MacOS :: MacOS X From 0702747277608257d722ad60afdda5f4010d1d16 Mon Sep 17 00:00:00 2001 From: Stefan Janssen Date: Thu, 28 Aug 2025 11:29:46 +0200 Subject: [PATCH 2/4] extend tests to py2.7 --- .github/workflows/qiita-plugin-ci.yml | 2 +- setup.py | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/qiita-plugin-ci.yml b/.github/workflows/qiita-plugin-ci.yml index b88f397..693b780 100644 --- a/.github/workflows/qiita-plugin-ci.yml +++ b/.github/workflows/qiita-plugin-ci.yml @@ -11,7 +11,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: ["3.5", "3.6", "3.9", "3.10", "3.11", "3.12"] + python-version: ["2.7", "3.5", "3.6", "3.9", "3.10", "3.11", "3.12"] steps: # Downloads a copy of the code in your repository before running CI tests - name: Check out repository code diff --git a/setup.py b/setup.py index 2580547..cd49f1b 100644 --- a/setup.py +++ b/setup.py @@ -18,6 +18,7 @@ Topic :: Software Development :: Libraries :: Application Frameworks Topic :: Software Development :: Libraries :: Python Modules Programming Language :: Python + Programming Language :: Python :: 2.7 Programming Language :: Python :: 3.5 Programming Language :: Python :: 3.6 Programming Language :: Python :: 3.9 From 98955d907952e348f85a296459a65dcfd9d4fdeb Mon Sep 17 00:00:00 2001 From: Stefan Janssen Date: Thu, 28 Aug 2025 16:57:47 +0200 Subject: [PATCH 3/4] extend tests to py2.7 (#15) * extend tests to py2.7 * also remove --cov for old py27 * fix import for py27 * try to fix syntax for py27 * some additional work to function with old python 2.7 and also slightly more modern python 3.x * more elegant conversion * remove leftover * make import StringIO compatible --- .github/workflows/qiita-plugin-ci.yml | 4 +-- qiita_files/parse/fastq.py | 5 ++- qiita_files/parse/tests/test_fastq.py | 12 +++---- qiita_files/parse/tests/test_iterator.py | 40 ++++++++++++------------ qiita_files/tests/test_util.py | 9 ++++-- setup.py | 1 + 6 files changed, 40 insertions(+), 31 deletions(-) diff --git a/.github/workflows/qiita-plugin-ci.yml b/.github/workflows/qiita-plugin-ci.yml index b88f397..952def6 100644 --- a/.github/workflows/qiita-plugin-ci.yml +++ b/.github/workflows/qiita-plugin-ci.yml @@ -11,7 +11,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: ["3.5", "3.6", "3.9", "3.10", "3.11", "3.12"] + python-version: ["2.7", "3.5", "3.6", "3.9", "3.10", "3.11", "3.12"] steps: # Downloads a copy of the code in your repository before running CI tests - name: Check out repository code @@ -35,7 +35,7 @@ jobs: shell: bash -l {0} run: | conda activate qiita-files - pytest --doctest-modules --cov=qiita_files `if (( $(echo "${{ matrix.python-version }} > 3.6" | bc -l) )); then echo "--cov-report=lcov"; else echo ""; fi` + pytest --doctest-modules `if (( $(echo "${{ matrix.python-version }} > 3.6" | bc -l) )); then echo "--cov-report=lcov --cov=qiita_files"; else echo ""; fi` lint: runs-on: ubuntu-latest diff --git a/qiita_files/parse/fastq.py b/qiita_files/parse/fastq.py index 3626da4..1b4d2a9 100644 --- a/qiita_files/parse/fastq.py +++ b/qiita_files/parse/fastq.py @@ -8,7 +8,10 @@ import numpy as np from qiita_files.util import open_file -from itertools import zip_longest +try: + from itertools import zip_longest +except ImportError: + from itertools import izip_longest as zip_longest def _ascii_to_phred(s, offset): diff --git a/qiita_files/parse/tests/test_fastq.py b/qiita_files/parse/tests/test_fastq.py index a331260..57c1849 100644 --- a/qiita_files/parse/tests/test_fastq.py +++ b/qiita_files/parse/tests/test_fastq.py @@ -155,7 +155,7 @@ class ParseFastqTestsInputIsFileNames(FileData, ParseFastqTests, TestCase): } -FASTQ_EXAMPLE = rb"""@GAPC_0015:6:1:1259:10413#0/1 +FASTQ_EXAMPLE = r"""@GAPC_0015:6:1:1259:10413#0/1 AACACCAAACTTCTCCACCACGTGAGCTACAAAAG +GAPC_0015:6:1:1259:10413#0/1 ````Y^T]`]c^cabcacc`^Lb^ccYT\T\Y\WF @@ -194,10 +194,10 @@ class ParseFastqTestsInputIsFileNames(FileData, ParseFastqTests, TestCase): @GAPC_0015:6:1:1317:3403#0/1 TTGTTTCCACTTGGTTGATTTCACCCCTGAGTTTG +GAPC_0015:6:1:1317:3403#0/1 -\\\ZTYTSaLbb``\_UZ_bbcc`cc^[ac\a\Tc""" +\\\ZTYTSaLbb``\_UZ_bbcc`cc^[ac\a\Tc""".encode("utf-8") -FASTQ_EXAMPLE_2 = rb"""@GAPC_0017:6:1:1259:10413#0/1 +FASTQ_EXAMPLE_2 = r"""@GAPC_0017:6:1:1259:10413#0/1 AACACCAAACTTCTCCACCACGTGAGCTACAAAAG +GAPC_0015:6:1:1259:10413#0/1 ````Y^T]`]c^cabcacc`^Lb^ccYT\T\Y\WF @@ -205,15 +205,15 @@ class ParseFastqTestsInputIsFileNames(FileData, ParseFastqTests, TestCase): TATGTATATATAACATATACATATATACATACATA +GAPC_0015:6:1:1283:11957#0/1 ]KZ[PY]_[YY^```ac^\\`bT``c`\aT``bbb -""" +""".encode("utf-8") -FASTQ_EXAMPLE_3 = rb"""@GAPC_0017:6:1:1259:10413#0/1 +FASTQ_EXAMPLE_3 = r"""@GAPC_0017:6:1:1259:10413#0/1 AACACCAAACTTCTCCACCACGTGAGCTACAAAAG +GAPC_0015:6:1:1259:10413#0/1 ````Y^T]`]c^cabcacc`^Lb^ccYT\T\Y\WF @GAPC_0015:6:1:1283:11957#0/1 -""" +""".encode("utf-8") if __name__ == "__main__": diff --git a/qiita_files/parse/tests/test_iterator.py b/qiita_files/parse/tests/test_iterator.py index 6795fe8..3dda430 100644 --- a/qiita_files/parse/tests/test_iterator.py +++ b/qiita_files/parse/tests/test_iterator.py @@ -276,47 +276,47 @@ def test_fastq_gen(self): self.assertEqual(obs3, exp3) -fasta1 = rb""">1 +fasta1 = r""">1 aattggcc >2 aattaatt -""" +""".encode("utf-8") -fasta2 = rb""">3 +fasta2 = r""">3 atat -""" +""".encode("utf-8") -fasta3 = rb""">4 +fasta3 = r""">4 attatt >5 ggccc -""" +""".encode("utf-8") -qual1 = rb""">1 +qual1 = r""">1 1 2 3 4 5 6 7 8 >2 8 7 6 5 4 3 2 1 -""" +""".encode("utf-8") -qual2 = rb""">3 +qual2 = r""">3 1 2 3 4 -""" +""".encode("utf-8") -qual3 = rb""">4 +qual3 = r""">4 1 2 3 4 5 6 >5 1 2 3 4 5 -""" +""".encode("utf-8") -qual_bad_val = rb""">3 +qual_bad_val = r""">3 1 2 -""" +""".encode("utf-8") -qual_bad_id = rb""">asdasd +qual_bad_id = r""">asdasd 1 2 3 4 -""" +""".encode("utf-8") -fastq1 = rb"""@1 +fastq1 = r"""@1 atat + ABCD @@ -324,13 +324,13 @@ def test_fastq_gen(self): atgc + BCDE -""" +""".encode("utf-8") -fastq2 = rb"""@3 +fastq2 = r"""@3 taa + EFG -""" +""".encode("utf-8") if __name__ == '__main__': diff --git a/qiita_files/tests/test_util.py b/qiita_files/tests/test_util.py index daf256f..4a600f2 100644 --- a/qiita_files/tests/test_util.py +++ b/qiita_files/tests/test_util.py @@ -8,11 +8,16 @@ # ----------------------------------------------------------------------------- import os +import sys from unittest import TestCase, main import tempfile import h5py -from io import StringIO, BytesIO +if sys.version_info[0] == 2: + from StringIO import StringIO +else: + from io import StringIO +from io import BytesIO from qiita_files.util import (open_file, _is_string_or_bytes) @@ -25,7 +30,7 @@ class TestFilePathOpening(TestCase): """Tests adapted from scikit-bio's skbio.io.util tests""" def test_is_string_or_bytes(self): self.assertTrue(_is_string_or_bytes('foo')) - self.assertTrue(_is_string_or_bytes(u'foo')) + self.assertTrue(_is_string_or_bytes(u'foo'.encode("utf-8"))) self.assertTrue(_is_string_or_bytes(b'foo')) self.assertFalse(_is_string_or_bytes(StringIO('bar'))) self.assertFalse(_is_string_or_bytes([1])) diff --git a/setup.py b/setup.py index 2580547..cd49f1b 100644 --- a/setup.py +++ b/setup.py @@ -18,6 +18,7 @@ Topic :: Software Development :: Libraries :: Application Frameworks Topic :: Software Development :: Libraries :: Python Modules Programming Language :: Python + Programming Language :: Python :: 2.7 Programming Language :: Python :: 3.5 Programming Language :: Python :: 3.6 Programming Language :: Python :: 3.9 From 57274a16c3b251c162a6ae8fa5d8722d1af2746a Mon Sep 17 00:00:00 2001 From: Stefan Janssen Date: Fri, 29 Aug 2025 10:20:07 +0200 Subject: [PATCH 4/4] conditional check, based on h5py version number --- qiita_files/util.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/qiita_files/util.py b/qiita_files/util.py index a17b5e6..80620e1 100644 --- a/qiita_files/util.py +++ b/qiita_files/util.py @@ -10,10 +10,13 @@ import h5py - -# not present in all 2.x series -if hasattr(h5py.get_config(), 'default_file_mode'): - h5py.get_config().default_file_mode = 'r' +# deprecated sind h5py 3.3, +# see https://docs.h5py.org/en/stable/whatsnew/3.6.html +h5py_version = list(map(int, h5py.__version__.split('.'))) +if h5py_version < [3, 3, 0]: + # not present in all 2.x series + if hasattr(h5py.get_config(), 'default_file_mode'): + h5py.get_config().default_file_mode = 'r' def _is_string_or_bytes(s):