Skip to content

Commit 4d9b61e

Browse files
committed
Remove six usage
1 parent 1b6fbfb commit 4d9b61e

File tree

15 files changed

+20
-96
lines changed

15 files changed

+20
-96
lines changed

README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ by citing the following paper in your publication:
6666
Requirements
6767
------------------------------------------------------------------------
6868

69-
The diffpy.structure package requires Python 3.7 or later or 2.7 and
69+
The diffpy.structure package requires Python 3.7 or later and
7070
the following software:
7171

7272
* ``setuptools`` - software distribution tools for Python

requirements/run.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
numpy < 2.0.0 # Need to fix deprecations before 2.0.0 compat
22
pycifrw
3-
six

src/diffpy/structure/_legacy_importer.py

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -25,24 +25,10 @@
2525
"""
2626

2727

28+
import importlib.abc
2829
import sys
2930
from warnings import warn
3031

31-
import six
32-
33-
if six.PY2:
34-
import importlib
35-
36-
class mock_importlib_abc(object):
37-
MetaPathFinder = object
38-
Loader = object
39-
40-
importlib.abc = mock_importlib_abc
41-
sys.modules.setdefault("importlib.abc", mock_importlib_abc)
42-
del mock_importlib_abc
43-
44-
import importlib.abc
45-
4632
WMSG = "Module {!r} is deprecated. Use {!r} instead."
4733

4834
# ----------------------------------------------------------------------------
@@ -63,15 +49,6 @@ def find_spec(self, fullname, path=None, target=None):
6349
spec.loader = MapRenamedStructureModule()
6450
return spec
6551

66-
if six.PY2:
67-
68-
def find_module(self, fullname, path):
69-
# only handle submodules of diffpy.Structure
70-
loader = None
71-
if fullname.startswith(self.prefix):
72-
loader = MapRenamedStructureModule()
73-
return loader
74-
7552

7653
# end of class FindRenamedStructureModule
7754

@@ -95,15 +72,6 @@ def create_module(self, spec):
9572
def exec_module(self, module):
9673
return
9774

98-
if six.PY2:
99-
from collections import namedtuple
100-
101-
ModuleSpec = namedtuple("ModuleSpec", "name")
102-
103-
def load_module(self, fullname):
104-
spec = self.ModuleSpec(fullname)
105-
return self.create_module(spec)
106-
10775

10876
# end of class MapRenamedStructureModule
10977

src/diffpy/structure/atom.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
"""
1919

2020
import numpy
21-
import six
2221

2322
from diffpy.structure.lattice import cartesian as cartesian_lattice
2423

@@ -558,15 +557,5 @@ def __array_wrap__(self, out_arr, context=None):
558557
"""
559558
return out_arr.view(numpy.ndarray)
560559

561-
# Python 2 Compatibility -------------------------------------------------
562-
563-
if six.PY2:
564-
565-
def __setslice__(self, lo, hi, sequence):
566-
self.__setitem__(slice(lo, hi), sequence)
567-
return
568-
569-
# ------------------------------------------------------------------------
570-
571560

572561
# End of _AtomCartesianCoordinates

src/diffpy/structure/parsers/p_cif.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@
1818
https://www.iucr.org/resources/cif
1919
"""
2020

21+
import io
2122
import re
2223
import sys
2324
from contextlib import contextmanager
2425

2526
import numpy
26-
import six
2727

2828
from diffpy.structure import Atom, Lattice, Structure
2929
from diffpy.structure.parsers import StructureParser
@@ -297,7 +297,7 @@ def parse(self, s):
297297
"""
298298
self.ciffile = None
299299
self.filename = ""
300-
fp = six.StringIO(s)
300+
fp = io.StringIO(s)
301301
rv = self._parseCifDataSource(fp)
302302
return rv
303303

@@ -363,7 +363,7 @@ def _parseCifDataSource(self, datasource):
363363
exc_type, exc_value, exc_traceback = sys.exc_info()
364364
emsg = str(err).strip()
365365
e = StructureFormatError(emsg)
366-
six.reraise(StructureFormatError, e, exc_traceback)
366+
raise e.with_traceback(exc_traceback)
367367
return self.stru
368368

369369
def _parseCifBlock(self, blockname):
@@ -412,7 +412,7 @@ def _parse_lattice(self, block):
412412
exc_type, exc_value, exc_traceback = sys.exc_info()
413413
emsg = str(err)
414414
e = StructureFormatError(emsg)
415-
six.reraise(StructureFormatError, e, exc_traceback)
415+
raise e.with_traceback(exc_traceback)
416416
self.stru.lattice = Lattice(*latpars)
417417
return
418418

src/diffpy/structure/parsers/p_discus.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919
import sys
2020
from functools import reduce
2121

22-
import six
23-
2422
from diffpy.structure import Lattice, PDFFitStructure
2523
from diffpy.structure.parsers import StructureParser
2624
from diffpy.structure.structureerrors import StructureFormatError
@@ -100,7 +98,7 @@ def parseLines(self, lines):
10098
exc_type, exc_value, exc_traceback = sys.exc_info()
10199
emsg = "%d: file is not in DISCUS format" % self.nl
102100
e = StructureFormatError(emsg)
103-
six.reraise(StructureFormatError, e, exc_traceback)
101+
raise e.with_traceback(exc_traceback)
104102
return self.stru
105103

106104
def toLines(self, stru):

src/diffpy/structure/parsers/p_pdb.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import sys
2525

2626
import numpy
27-
import six
2827
from numpy import pi
2928

3029
from diffpy.structure import Structure
@@ -225,7 +224,7 @@ def parseLines(self, lines):
225224
emsg = "%d: invalid PDB record" % p_nl
226225
exc_type, exc_value, exc_traceback = sys.exc_info()
227226
e = StructureFormatError(emsg)
228-
six.reraise(StructureFormatError, e, exc_traceback)
227+
raise e.with_traceback(exc_traceback)
229228
return stru
230229

231230
def titleLines(self, stru):

src/diffpy/structure/parsers/p_pdffit.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
from functools import reduce
2121

2222
import numpy
23-
import six
2423

2524
from diffpy.structure import Lattice, PDFFitStructure
2625
from diffpy.structure.parsers import StructureParser
@@ -158,7 +157,7 @@ def parseLines(self, lines):
158157
emsg = "%d: file is not in PDFfit format" % p_nl
159158
exc_type, exc_value, exc_traceback = sys.exc_info()
160159
e = StructureFormatError(emsg)
161-
six.reraise(StructureFormatError, e, exc_traceback)
160+
raise e.with_traceback(exc_traceback)
162161
return stru
163162

164163
def toLines(self, stru):

src/diffpy/structure/parsers/p_rawxyz.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020

2121
import sys
2222

23-
import six
24-
2523
from diffpy.structure import Structure
2624
from diffpy.structure.parsers import StructureParser
2725
from diffpy.structure.structureerrors import StructureFormatError
@@ -91,7 +89,7 @@ def parseLines(self, lines):
9189
emsg = "%d: invalid number" % p_nl
9290
exc_type, exc_value, exc_traceback = sys.exc_info()
9391
e = StructureFormatError(emsg)
94-
six.reraise(StructureFormatError, e, exc_traceback)
92+
raise e.with_traceback(exc_traceback)
9593
return stru
9694

9795
def toLines(self, stru):

src/diffpy/structure/parsers/p_xcfg.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import sys
2020

2121
import numpy
22-
import six
2322

2423
from diffpy.structure import Structure
2524
from diffpy.structure.parsers import StructureParser
@@ -260,7 +259,7 @@ def parseLines(self, lines):
260259
emsg = "%d: file is not in XCFG format" % p_nl
261260
exc_type, exc_value, exc_traceback = sys.exc_info()
262261
e = StructureFormatError(emsg)
263-
six.reraise(StructureFormatError, e, exc_traceback)
262+
raise e.with_traceback(exc_traceback)
264263
return stru
265264

266265
def toLines(self, stru):

0 commit comments

Comments
 (0)