From 9cca418f43cf5fdb9450fa2e9ab331509dd9e96d Mon Sep 17 00:00:00 2001 From: Alexandre Detiste Date: Sun, 7 Jan 2024 17:10:12 +0100 Subject: [PATCH 1/2] remove old Python 2 hybridation --- .coveragerc | 2 -- dev-requirements.txt | 2 -- pyfaidx/__init__.py | 45 ++++++++++------------------- pyproject.toml | 1 - tests/test_Fasta_synchronization.py | 5 +--- tests/test_feature_indexing.py | 11 ++----- 6 files changed, 19 insertions(+), 47 deletions(-) diff --git a/.coveragerc b/.coveragerc index bd72b98..fc13813 100644 --- a/.coveragerc +++ b/.coveragerc @@ -5,8 +5,6 @@ omit = */lib_pypy/_*.py */site-packages/ordereddict.py */site-packages/nose/* - */site-packages/six/* - */unittest2/* [paths] source = diff --git a/dev-requirements.txt b/dev-requirements.txt index 8d41dbe..4815685 100644 --- a/dev-requirements.txt +++ b/dev-requirements.txt @@ -1,8 +1,6 @@ -six pytest pytest-cov setuptools -mock cython # pysam requests diff --git a/pyfaidx/__init__.py b/pyfaidx/__init__.py index 2971d3a..03030aa 100644 --- a/pyfaidx/__init__.py +++ b/pyfaidx/__init__.py @@ -3,8 +3,6 @@ Fasta file -> Faidx -> Fasta -> FastaRecord -> Sequence """ -from __future__ import division - import datetime import os import re @@ -13,7 +11,7 @@ import shutil import warnings from collections import namedtuple -from itertools import islice +from itertools import islice, zip_longest from math import ceil from os.path import getmtime from tempfile import TemporaryFile @@ -24,13 +22,7 @@ except ImportError: #python < 3.8 from importlib_metadata import version -from six import PY2, PY3, integer_types, string_types -from six.moves import zip_longest - -try: - from collections import OrderedDict -except ImportError: #python 2.6 - from ordereddict import OrderedDict +from collections import OrderedDict try: import fsspec @@ -39,9 +31,6 @@ __version__ = version("pyfaidx") -if sys.version_info > (3, ): - buffer = memoryview - dna_bases = re.compile(r'([ACTGNactgnYRWSKMDVHBXyrwskmdvhbx]+)') class KeyFunctionError(ValueError): @@ -99,8 +88,8 @@ def __init__(self, name='', seq='', start=None, end=None, comp=False): self.start = start self.end = end self.comp = comp - assert isinstance(name, string_types) - assert isinstance(seq, string_types) + assert isinstance(name, str) + assert isinstance(seq, str) def __getitem__(self, n): """ Returns a sliced version of Sequence @@ -180,7 +169,7 @@ def __getitem__(self, n): end = self_start + slice_stop + correction_factor return self.__class__(self.name, self.seq[n], start, end, self.comp) - elif isinstance(n, integer_types): + elif isinstance(n, int): if n < 0: n = len(self) + n if self.start: @@ -455,7 +444,7 @@ def __init__(self, try: key_fn_test = self.key_function( "TestingReturnType of_key_function") - if not isinstance(key_fn_test, string_types): + if not isinstance(key_fn_test, str): raise KeyFunctionError( "key_function argument should return a string, not {0}". format(type(key_fn_test))) @@ -482,9 +471,9 @@ def __init__(self, self.lock = Lock() self.buffer = dict((('seq', None), ('name', None), ('start', None), ('end', None))) - if not read_ahead or isinstance(read_ahead, integer_types): + if not read_ahead or isinstance(read_ahead, int): self.read_ahead = read_ahead - elif not isinstance(read_ahead, integer_types): + elif not isinstance(read_ahead, int): raise ValueError("read_ahead value must be int, not {0}".format( type(read_ahead))) @@ -923,7 +912,7 @@ def __getitem__(self, n): start = len(self) + start return self._fa.get_seq(self.name, start + 1, stop)[::step] - elif isinstance(n, integer_types): + elif isinstance(n, int): if n < 0: n = len(self) + n return self._fa.get_seq(self.name, n + 1, n + 1) @@ -1034,7 +1023,7 @@ def __array_interface__(self): 'shape': (len(self), ), 'typestr': '|S1', 'version': 3, - 'data': buffer(str(self).encode('ascii')) + 'data': memoryview(str(self).encode('ascii')) } @@ -1065,7 +1054,7 @@ def __setitem__(self, n, value): start = len(self) + start self._fa.faidx.to_file(self.name, start + 1, stop, value) - elif isinstance(n, integer_types): + elif isinstance(n, int): if n < 0: n = len(self) + n return self._fa.faidx.to_file(self.name, n + 1, n + 1, value) @@ -1126,7 +1115,7 @@ def __contains__(self, rname): def __getitem__(self, rname): """Return a chromosome by its name, or its numerical index.""" - if isinstance(rname, integer_types): + if isinstance(rname, int): rname = next(islice(self.records.keys(), rname, None)) try: return self.records[rname] @@ -1353,13 +1342,9 @@ def getmtime_fsspec(path, fs): chr(x) for x in range(256) if chr(x) not in complement_map[0]) invalid_characters_string = ''.join(invalid_characters_set) -if PY3: - complement_table = str.maketrans(complement_map[0], complement_map[1], - invalid_characters_string) - translate_arguments = (complement_table, ) -elif PY2: - complement_table = string.maketrans(complement_map[0], complement_map[1]) - translate_arguments = (complement_table, invalid_characters_string) +complement_table = str.maketrans(complement_map[0], complement_map[1], + invalid_characters_string) +translate_arguments = (complement_table, ) def complement(seq): diff --git a/pyproject.toml b/pyproject.toml index 1a52e83..3410809 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -27,7 +27,6 @@ classifiers = [ "Topic :: Scientific/Engineering :: Bio-Informatics" ] dependencies = [ - "six", "setuptools", "importlib_metadata" ] diff --git a/tests/test_Fasta_synchronization.py b/tests/test_Fasta_synchronization.py index 6810a7c..f427845 100644 --- a/tests/test_Fasta_synchronization.py +++ b/tests/test_Fasta_synchronization.py @@ -1,9 +1,6 @@ import os import pytest -try: - from collections import OrderedDict -except ImportError: #python 2.6 - from ordereddict import OrderedDict +from collections import OrderedDict import threading from pyfaidx import Fasta import random diff --git a/tests/test_feature_indexing.py b/tests/test_feature_indexing.py index 532da49..0479565 100644 --- a/tests/test_feature_indexing.py +++ b/tests/test_feature_indexing.py @@ -7,12 +7,7 @@ import platform import shutil -try: - from unittest import mock -except ImportError: - import mock - -import six.moves.builtins as builtins +from unittest import mock path = os.path.dirname(__file__) os.chdir(path) @@ -268,7 +263,7 @@ def test_open(*args, **kwargs): opened_files.append(f) return f - with mock.patch('six.moves.builtins.open', side_effect=test_open): + with mock.patch('builtins.open', side_effect=test_open): try: Faidx(fasta_path) remove_index.assertFail( @@ -305,7 +300,7 @@ def test_open(*args, **kwargs): opened_files.append(f) return f - with mock.patch('six.moves.builtins.open', side_effect=test_open): + with mock.patch('builtins.open', side_effect=test_open): try: Faidx(fasta_path) remove_index.assertFail( From ae555b5856dc34fdc6413c8c0f32392d53a040f4 Mon Sep 17 00:00:00 2001 From: Alexandre Detiste Date: Sun, 7 Jan 2024 20:56:41 +0100 Subject: [PATCH 2/2] add missing import on builtins --- tests/test_feature_indexing.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/test_feature_indexing.py b/tests/test_feature_indexing.py index 0479565..4b04afb 100644 --- a/tests/test_feature_indexing.py +++ b/tests/test_feature_indexing.py @@ -1,3 +1,4 @@ +import builtins import os import pytest from os.path import getmtime