Skip to content

Commit

Permalink
remove old Python 2 hybridation
Browse files Browse the repository at this point in the history
  • Loading branch information
a-detiste committed Jan 7, 2024
1 parent cac82f2 commit 9cca418
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 47 deletions.
2 changes: 0 additions & 2 deletions .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ omit =
*/lib_pypy/_*.py
*/site-packages/ordereddict.py
*/site-packages/nose/*
*/site-packages/six/*
*/unittest2/*

[paths]
source =
Expand Down
2 changes: 0 additions & 2 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
six
pytest
pytest-cov
setuptools
mock
cython
# pysam
requests
Expand Down
45 changes: 15 additions & 30 deletions pyfaidx/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
Fasta file -> Faidx -> Fasta -> FastaRecord -> Sequence
"""

from __future__ import division

import datetime
import os
import re
Expand All @@ -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
Expand All @@ -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
Expand All @@ -39,9 +31,6 @@

__version__ = version("pyfaidx")

if sys.version_info > (3, ):
buffer = memoryview

dna_bases = re.compile(r'([ACTGNactgnYRWSKMDVHBXyrwskmdvhbx]+)')

class KeyFunctionError(ValueError):
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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)))
Expand All @@ -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)))

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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'))
}


Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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):
Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ classifiers = [
"Topic :: Scientific/Engineering :: Bio-Informatics"
]
dependencies = [
"six",
"setuptools",
"importlib_metadata"
]
Expand Down
5 changes: 1 addition & 4 deletions tests/test_Fasta_synchronization.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
11 changes: 3 additions & 8 deletions tests/test_feature_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 9cca418

Please sign in to comment.