diff --git a/.github/workflows/qiita-ci.yml b/.github/workflows/qiita-ci.yml index c210eea..50cda0d 100644 --- a/.github/workflows/qiita-ci.yml +++ b/.github/workflows/qiita-ci.yml @@ -9,6 +9,10 @@ jobs: main: runs-on: ubuntu-latest + strategy: + matrix: + python-version: ["2.7", "3.9"] + services: postgres: # Docker Hub image @@ -73,7 +77,7 @@ jobs: - name: Install Qiita plugins shell: bash -l {0} run: | - conda create --yes -n qiita_client python=3.9 pip nose flake8 coverage + conda create --yes -n qiita_client python=${{ matrix.python-version }} pip nose flake8 coverage conda activate qiita_client pip --quiet install . diff --git a/qiita_client/qiita_client.py b/qiita_client/qiita_client.py index 00e6e29..881cf5a 100644 --- a/qiita_client/qiita_client.py +++ b/qiita_client/qiita_client.py @@ -12,7 +12,12 @@ import pandas as pd from json import dumps from random import randint -from itertools import zip_longest + +try: + from itertools import zip_longest +except ImportError: + from itertools import izip_longest as zip_longest + from os.path import basename from .exceptions import (QiitaClientError, NotFoundError, BadRequestError, @@ -590,8 +595,9 @@ def artifact_and_preparation_files(self, artifact_id, if artifact_info['analysis'] is not None: raise RuntimeError( - f'Artifact {artifact_id} is an analysis artifact, this method ' - 'is meant to work with artifacts linked to a preparation.') + 'Artifact ' + str(artifact_id) + ' is an analysis artifact, ' + 'this method is meant to work with artifacts linked to ' + 'a preparation.') prep_info = self.get('/qiita_db/prep_template/%s/' % artifact_info['prep_information'][0]) @@ -615,8 +621,9 @@ def _process_files_per_sample_fastq(self, files, prep_info, revs = sorted( files['raw_reverse_seqs'], key=lambda x: x['filepath']) if len(fwds) != len(revs): - raise ValueError(f'The fwd ({len(fwds)}) and rev ({len(revs)})' - ' files should be of the same length') + raise ValueError('The fwd (' + str(len(fwds)) + ') and rev (' + + str(len(revs)) + ') files should be of the ' + 'same length') run_prefixes = prep_info['run_prefix'].to_dict() @@ -635,15 +642,15 @@ def _process_files_per_sample_fastq(self, files, prep_info, run_prefix = rp sample_name = sn elif fwd_fn.startswith(rp) and run_prefix is not None: - raise ValueError( - f'Multiple run prefixes match this fwd read: {fwd_fn}') + raise ValueError('Multiple run prefixes match this fwd ' + 'read: %s' % fwd_fn) if run_prefix is None: raise ValueError( - f'No run prefix matching this fwd read: {fwd_fn}') + 'No run prefix matching this fwd read: %s' % fwd_fn) if run_prefix in used_prefixes: raise ValueError( - f'Run prefix matches multiple fwd reads: {run_prefix}') + 'Run prefix matches multiple fwd reads: %s' % run_prefix) used_prefixes.append(run_prefix) if rev is not None: @@ -655,7 +662,7 @@ def _process_files_per_sample_fastq(self, files, prep_info, if not rev_fn.startswith(run_prefix): raise ValueError( 'Reverse read does not match run prefix. run_prefix: ' - f'{run_prefix}; files: {fwd_fn} / {rev_fn}') + '%s; files: %s / %s') % (run_prefix, fwd_fn, rev_fn) used_prefixes.append(run_prefix) diff --git a/qiita_client/tests/test_qiita_client.py b/qiita_client/tests/test_qiita_client.py index 6d85afa..cfc6ec2 100644 --- a/qiita_client/tests/test_qiita_client.py +++ b/qiita_client/tests/test_qiita_client.py @@ -101,6 +101,10 @@ def setUp(self): CLIENT_SECRET, server_cert=self.server_cert) self.clean_up_files = [] + # making assertRaisesRegex compatible with Python 2.7 and 3.9 + if not hasattr(self, 'assertRaisesRegex'): + setattr(self, 'assertRaisesRegex', self.assertRaisesRegexp) + def tearDown(self): for fp in self.clean_up_files: if exists(fp):