From 18dd3b09fb60e93962615c4451d07f4db6541b22 Mon Sep 17 00:00:00 2001 From: Tieqiong Zhang Date: Tue, 7 Jan 2025 20:48:11 -0500 Subject: [PATCH 1/2] refactor: remove six --- requirements/conda.txt | 1 - requirements/pip.txt | 1 - src/diffpy/pdffit2/pdffit.py | 36 +++++++++++++++++------------------- tests/conftest.py | 4 ++-- 4 files changed, 19 insertions(+), 23 deletions(-) diff --git a/requirements/conda.txt b/requirements/conda.txt index 33133cd6..9cc306b0 100644 --- a/requirements/conda.txt +++ b/requirements/conda.txt @@ -1,2 +1 @@ diffpy.structure -six diff --git a/requirements/pip.txt b/requirements/pip.txt index 33133cd6..9cc306b0 100644 --- a/requirements/pip.txt +++ b/requirements/pip.txt @@ -1,2 +1 @@ diffpy.structure -six diff --git a/src/diffpy/pdffit2/pdffit.py b/src/diffpy/pdffit2/pdffit.py index 11f6f253..aaeeedda 100644 --- a/src/diffpy/pdffit2/pdffit.py +++ b/src/diffpy/pdffit2/pdffit.py @@ -20,8 +20,6 @@ import itertools import numbers -import six - # Load pdffit2 and output modules to the current namespace. # Note that "import diffpy.pdffit2.output as output" would # crash with AttributeError when executed during imports of @@ -213,7 +211,7 @@ def read_data(self, data, stype, qmax, qdamp): Raises: IOError when the file cannot be read from disk """ - pdffit2.read_data(self._handle, data, six.b(stype), qmax, qdamp) + pdffit2.read_data(self._handle, data, stype.encode(), qmax, qdamp) self.data_files.append(data) return @@ -228,7 +226,7 @@ def read_data_string(self, data, stype, qmax, qdamp, name=""): qdamp -- instrumental Q-resolution factor name -- tag with which to label data """ - pdffit2.read_data_string(self._handle, data, six.b(stype), qmax, qdamp, name) + pdffit2.read_data_string(self._handle, data, stype.encode(), qmax, qdamp, name) name = data self.data_files.append(name) return @@ -249,7 +247,7 @@ def read_data_lists(self, stype, qmax, qdamp, r_data, Gr_data, dGr_data=None, na Raises: ValueError when the data lists are of different length """ - pdffit2.read_data_arrays(self._handle, six.b(stype), qmax, qdamp, r_data, Gr_data, dGr_data, name) + pdffit2.read_data_arrays(self._handle, stype.encode(), qmax, qdamp, r_data, Gr_data, dGr_data, name) self.data_files.append(name) return @@ -290,7 +288,7 @@ def alloc(self, stype, qmax, qdamp, rmin, rmax, bin): ValueError for bad input values pdffit.unassignedError when no structure has been loaded """ - pdffit2.alloc(self._handle, six.b(stype), qmax, qdamp, rmin, rmax, bin) + pdffit2.alloc(self._handle, stype.encode(), qmax, qdamp, rmin, rmax, bin) return def calc(self): @@ -495,7 +493,7 @@ def constrain(self, var, par, fcon=None): if fcon: fc = self.FCON[fcon] pdffit2.constrain_int(self._handle, var_ref, varnc, par, fc) - elif isinstance(par, six.string_types): + elif isinstance(par, str): pdffit2.constrain_str(self._handle, var_ref, varnc, par) else: pdffit2.constrain_int(self._handle, var_ref, varnc, par) @@ -674,7 +672,7 @@ def fixpar(self, par): Raises: pdffit.unassignedError when parameter has not been assigned """ - if isinstance(par, six.string_types) and par.upper() in self.selalias: + if isinstance(par, str) and par.upper() in self.selalias: par = self.selalias[par.upper()] pdffit2.fixpar(self._handle, par) return @@ -687,7 +685,7 @@ def freepar(self, par): Raises: pdffit.unassignedError when parameter has not been assigned """ - if isinstance(par, six.string_types) and par.upper() in self.selalias: + if isinstance(par, str) and par.upper() in self.selalias: par = self.selalias[par.upper()] pdffit2.freepar(self._handle, par) return @@ -722,7 +720,7 @@ def psel(self, ip): Raises: pdffit2.unassignedError if selected phase does not exist """ - if isinstance(ip, six.string_types) and ip.upper() in self.selalias: + if isinstance(ip, str) and ip.upper() in self.selalias: ip = self.selalias[ip.upper()] pdffit2.psel(self._handle, ip) return @@ -734,7 +732,7 @@ def pdesel(self, ip): Raises: pdffit2.unassignedError if selected phase does not exist """ - if isinstance(ip, six.string_types) and ip.upper() in self.selalias: + if isinstance(ip, str) and ip.upper() in self.selalias: ip = self.selalias[ip.upper()] pdffit2.pdesel(self._handle, ip) return @@ -753,7 +751,7 @@ def selectAtomType(self, ip, ijchar, symbol, flag): pdffit2.unassignedError if selected phase does not exist ValueError for invalid value of ijchar """ - pdffit2.selectAtomType(self._handle, ip, six.b(ijchar), symbol, flag) + pdffit2.selectAtomType(self._handle, ip, ijchar.encode(), symbol, flag) return def selectAtomIndex(self, ip, ijchar, aidx, flag): @@ -770,7 +768,7 @@ def selectAtomIndex(self, ip, ijchar, aidx, flag): pdffit2.unassignedError if selected phase does not exist ValueError if atom index or ijchar are invalid """ - pdffit2.selectAtomIndex(self._handle, ip, six.b(ijchar), aidx, flag) + pdffit2.selectAtomIndex(self._handle, ip, ijchar.encode(), aidx, flag) return def selectAll(self, ip, ijchar): @@ -784,7 +782,7 @@ def selectAll(self, ip, ijchar): pdffit2.unassignedError if selected phase does not exist ValueError if ijchar is invalid """ - pdffit2.selectAll(self._handle, ip, six.b(ijchar)) + pdffit2.selectAll(self._handle, ip, ijchar.encode()) return def selectNone(self, ip, ijchar): @@ -798,7 +796,7 @@ def selectNone(self, ip, ijchar): pdffit2.unassignedError if selected phase does not exist ValueError if ijchar is invalid """ - pdffit2.selectNone(self._handle, ip, six.b(ijchar)) + pdffit2.selectNone(self._handle, ip, ijchar.encode()) return def bang(self, i, j, k): @@ -963,7 +961,7 @@ def get_scat_string(self, stype): Returns: string with all scattering factors. """ - return pdffit2.get_scat_string(self._handle, six.b(stype)) + return pdffit2.get_scat_string(self._handle, stype.encode()) def get_scat(self, stype, element): """get_scat(stype, element) --> Get active scattering factor for @@ -979,7 +977,7 @@ def get_scat(self, stype, element): Raises: ValueError if element is not known. """ - rv = pdffit2.get_scat(self._handle, six.b(stype), element) + rv = pdffit2.get_scat(self._handle, stype.encode(), element) return rv def set_scat(self, stype, element, value): @@ -999,7 +997,7 @@ def set_scat(self, stype, element, value): See also reset_scat, get_scat. """ - pdffit2.set_scat(self._handle, six.b(stype), element, value) + pdffit2.set_scat(self._handle, stype.encode(), element, value) return def reset_scat(self, element): @@ -1074,7 +1072,7 @@ def lat(n): 6 <==> 'gamma' """ LatParams = {"a": 1, "b": 2, "c": 3, "alpha": 4, "beta": 5, "gamma": 6} - if isinstance(n, six.string_types): + if isinstance(n, str): n = LatParams[n] return "lat(%i)" % n diff --git a/tests/conftest.py b/tests/conftest.py index 5407f543..6a142536 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,8 +1,8 @@ +import io import json from pathlib import Path import pytest -import six import diffpy.pdffit2 import diffpy.pdffit2.output # assuming this is the correct import path @@ -39,7 +39,7 @@ def capture_output(): def _capture(f, *args, **kwargs): savestdout = diffpy.pdffit2.output.stdout - fp = six.StringIO() + fp = io.StringIO() diffpy.pdffit2.redirect_stdout(fp) try: f(*args, **kwargs) From 8ef84a7a53ad0bf4c46f23f5c2b43123c958390a Mon Sep 17 00:00:00 2001 From: Tieqiong Zhang Date: Tue, 7 Jan 2025 20:51:26 -0500 Subject: [PATCH 2/2] add news --- news/remove_six.rst | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 news/remove_six.rst diff --git a/news/remove_six.rst b/news/remove_six.rst new file mode 100644 index 00000000..668d44ce --- /dev/null +++ b/news/remove_six.rst @@ -0,0 +1,23 @@ +**Added:** + +* + +**Changed:** + +* + +**Deprecated:** + +* + +**Removed:** + +* Six dependency and py2 support + +**Fixed:** + +* + +**Security:** + +*