From 9d95c2235603c7d54ae378d31db9e5a386149b3f Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Sat, 18 Jan 2025 18:38:42 +0100 Subject: [PATCH] Remove Python 2.7 leftovers Functions `u()` and `du()` are not required anymore in Python 3. All variables are `str`. --- doc/source/dev/building_extension.rst | 2 +- doc/source/dev/how_to_release.rst | 2 +- doc/source/dev/index.rst | 4 +- .../preparing_windows_build_environment.rst | 10 ++--- doc/source/resources.rst | 2 +- pyedflib/edfwriter.py | 41 +++++++------------ pyedflib/highlevel.py | 2 +- setup.py | 8 +--- 8 files changed, 28 insertions(+), 43 deletions(-) diff --git a/doc/source/dev/building_extension.rst b/doc/source/dev/building_extension.rst index 41cc4871..f5a2fe2c 100644 --- a/doc/source/dev/building_extension.rst +++ b/doc/source/dev/building_extension.rst @@ -34,7 +34,7 @@ repository or use the upstream repository to get the source code:: git clone https://github.com/holgern/pyedflib.git pyedflib -Install Microsoft Visual C++ Compiler for Python 2.7 from https://www.microsoft.com/en-us/download/details.aspx?id=44266 +Install Microsoft Visual C++ Compiler from https://visualstudio.microsoft.com/fr/downloads/ Activate your Python virtual environment, go to the cloned source directory and type the following commands to build and install the package:: diff --git a/doc/source/dev/how_to_release.rst b/doc/source/dev/how_to_release.rst index 75e795d0..b228983a 100644 --- a/doc/source/dev/how_to_release.rst +++ b/doc/source/dev/how_to_release.rst @@ -41,7 +41,7 @@ Register all files with and upload with -```twine upload dist\filename_which_should_uploaded.whl``` +```twine upload dist\filename_which_should_uploaded.whl``` Prepare for continued development --------------------------------- diff --git a/doc/source/dev/index.rst b/doc/source/dev/index.rst index 59a68a46..5318bb83 100644 --- a/doc/source/dev/index.rst +++ b/doc/source/dev/index.rst @@ -22,6 +22,6 @@ Something not working? ---------------------- If these instructions are not clear or you need help setting up your -development environment, go ahead and open a ticket on GitHub_. +development environment, go ahead and open a ticket on GitHub_. -.. _GitHub: https://github.com/holgern/pyedflib \ No newline at end of file +.. _GitHub: https://github.com/holgern/pyedflib diff --git a/doc/source/dev/preparing_windows_build_environment.rst b/doc/source/dev/preparing_windows_build_environment.rst index a8694c2c..b194aea8 100644 --- a/doc/source/dev/preparing_windows_build_environment.rst +++ b/doc/source/dev/preparing_windows_build_environment.rst @@ -7,16 +7,16 @@ Preparing Windows build environment To start developing pyedflib code on Windows you will have to install a C compiler and prepare the build environment. -Installing Microsoft Visual C++ Compiler for Python 2.7 -------------------------------------------------------- +Installing Microsoft Visual C++ Compiler +---------------------------------------- -Downloading Microsoft Visual C++ Compiler for Python 2.7 from https://www.microsoft.com/en-us/download/details.aspx?id=44266. +Downloading Microsoft Visual C++ Compiler from https://visualstudio.microsoft.com/fr/downloads/. After installing the Compiler and before compiling the extension you have to configure some environment variables. -For build execute the ``util/setenv_win.bat`` script in the cmd +For build execute the ``util/setenv_win.bat`` script in the cmd window: .. sourcecode:: bat @@ -39,4 +39,4 @@ After completing these steps continue with .. _numpy: https://numpy.org/ .. _Cython: https://cython.org/ .. _Sphinx: https://www.sphinx-doc.org/ -.. _Microsoft Visual C++ Compiler for Python 2.7: https://www.microsoft.com/en-us/download/details.aspx?id=44266 +.. _Microsoft Visual C++ Compiler: https://visualstudio.microsoft.com/fr/downloads/ diff --git a/doc/source/resources.rst b/doc/source/resources.rst index d53fd996..a02cb260 100644 --- a/doc/source/resources.rst +++ b/doc/source/resources.rst @@ -11,7 +11,7 @@ The `GitHub repository`_ is now the main code repository. If you are using the Mercurial repository at Bitbucket, please switch -to Git/GitHub and follow for development updates. +to Git/GitHub and follow for development updates. Questions and bug reports diff --git a/pyedflib/edfwriter.py b/pyedflib/edfwriter.py index ea9d3e9e..a0583fcf 100644 --- a/pyedflib/edfwriter.py +++ b/pyedflib/edfwriter.py @@ -143,17 +143,6 @@ def check_signal_header_correct(channels: List[Dict[str, Union[str, None, float] str(ch['physical_max'])[:8])) -def u(x: bytes) -> str: - return x.decode("utf_8", "strict") - - -def du(x: Union[str, bytes]) -> bytes: - if isinstance(x, bytes): - return x - else: - return x.encode("utf_8") - - def isstr(s: Any) -> bool: warnings.warn("Function 'isstr' is deprecated.", DeprecationWarning, stacklevel=2) return isinstance(s, str) @@ -294,13 +283,13 @@ def update_header(self) -> None: # this can be overwritten by explicitly calling setDatarecordDuration self._calculate_optimal_record_duration() - set_technician(self.handle, du(self.technician)) - set_recording_additional(self.handle, du(self.recording_additional)) - set_patientname(self.handle, du(self.patient_name)) - set_patientcode(self.handle, du(self.patient_code)) - set_patient_additional(self.handle, du(self.patient_additional)) - set_equipment(self.handle, du(self.equipment)) - set_admincode(self.handle, du(self.admincode)) + set_technician(self.handle, self.technician) + set_recording_additional(self.handle, self.recording_additional) + set_patientname(self.handle, self.patient_name) + set_patientcode(self.handle, self.patient_code) + set_patient_additional(self.handle, self.patient_additional) + set_equipment(self.handle, self.equipment) + set_admincode(self.handle, self.admincode) set_sex(self.handle, sex2int(self.sex)) set_datarecord_duration(self.handle, self.record_duration) @@ -325,10 +314,10 @@ def update_header(self) -> None: set_physical_minimum(self.handle, i, self.channels[i]['physical_min']) set_digital_maximum(self.handle, i, self.channels[i]['digital_max']) set_digital_minimum(self.handle, i, self.channels[i]['digital_min']) - set_label(self.handle, i, du(self.channels[i]['label'])) - set_physical_dimension(self.handle, i, du(self.channels[i]['dimension'])) - set_transducer(self.handle, i, du(self.channels[i]['transducer'])) - set_prefilter(self.handle, i, du(self.channels[i]['prefilter'])) + set_label(self.handle, i, self.channels[i]['label']) + set_physical_dimension(self.handle, i, self.channels[i]['dimension']) + set_transducer(self.handle, i, self.channels[i]['transducer']) + set_prefilter(self.handle, i, self.channels[i]['prefilter']) def setHeader(self, fileHeader: Dict[str, Union[str, float, int, None]]) -> None: """ @@ -926,16 +915,16 @@ def writeAnnotation(self, onset_in_seconds: Union[int, float], duration_in_secon if str_format == 'utf_8': if duration_in_seconds >= 0: - return write_annotation_utf8(self.handle, np.round(onset_in_seconds*10000).astype(np.int64), np.round(duration_in_seconds*10000).astype(int), du(description)) + return write_annotation_utf8(self.handle, np.round(onset_in_seconds*10000).astype(np.int64), np.round(duration_in_seconds*10000).astype(int), description) else: - return write_annotation_utf8(self.handle, np.round(onset_in_seconds*10000).astype(np.int64), -1, du(description)) + return write_annotation_utf8(self.handle, np.round(onset_in_seconds*10000).astype(np.int64), -1, description) else: if duration_in_seconds >= 0: # FIX: description must be bytes. string will fail in u function - return write_annotation_latin1(self.handle, np.round(onset_in_seconds*10000).astype(np.int64), np.round(duration_in_seconds*10000).astype(int), u(description).encode('latin1')) # type: ignore + return write_annotation_latin1(self.handle, np.round(onset_in_seconds*10000).astype(np.int64), np.round(duration_in_seconds*10000).astype(int), description.encode('latin1')) # type: ignore else: # FIX: description must be bytes. string will fail in u function - return write_annotation_latin1(self.handle, np.round(onset_in_seconds*10000).astype(np.int64), -1, u(description).encode('latin1')) # type: ignore + return write_annotation_latin1(self.handle, np.round(onset_in_seconds*10000).astype(np.int64), -1, description.encode('latin1')) # type: ignore def close(self) -> None: """ diff --git a/pyedflib/highlevel.py b/pyedflib/highlevel.py index 1895805f..3f11c111 100644 --- a/pyedflib/highlevel.py +++ b/pyedflib/highlevel.py @@ -756,7 +756,7 @@ def drop_channels( if isinstance(ch,str): ch_idx = ch_names.index(ch.lower()) to_keep[i] = ch_idx - load_channels = list(to_keep) # copy list compatible with py2.7 + load_channels = to_keep.copy() elif to_drop is not None: for i,ch in enumerate(to_drop): if isinstance(ch,str): diff --git a/setup.py b/setup.py index b308fd52..b591608b 100644 --- a/setup.py +++ b/setup.py @@ -66,12 +66,8 @@ def get_numpy_include(): # versions. # setuptools forgets to unset numpy's setup flag and we get a crippled # version of it unless we do it ourselves. - try: - import __builtin__ # py2 - __builtin__.__NUMPY_SETUP__ = False - except: - import builtins # py3 - builtins.__NUMPY_SETUP__ = False + import builtins + builtins.__NUMPY_SETUP__ = False import numpy as np except ImportError as e: try: