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

Python 2.7 #49

Merged
merged 7 commits into from
Feb 10, 2023
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
6 changes: 5 additions & 1 deletion .github/workflows/qiita-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ jobs:
main:
runs-on: ubuntu-latest

strategy:
matrix:
python-version: ["2.7", "3.9"]

services:
postgres:
# Docker Hub image
Expand Down Expand Up @@ -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 .
Expand Down
27 changes: 17 additions & 10 deletions qiita_client/qiita_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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])
Expand All @@ -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()

Expand All @@ -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:
Expand All @@ -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)

Expand Down
4 changes: 4 additions & 0 deletions qiita_client/tests/test_qiita_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down