Skip to content

Commit

Permalink
Remove Python 2.7 leftovers
Browse files Browse the repository at this point in the history
Functions `u()` and `du()` are not required anymore in Python 3. All variables are `str`.
  • Loading branch information
DimitriPapadopoulos committed Jan 21, 2025
1 parent ea9ee94 commit 201cd0b
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 43 deletions.
2 changes: 1 addition & 1 deletion doc/source/dev/building_extension.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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::
Expand Down
2 changes: 1 addition & 1 deletion doc/source/dev/how_to_release.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
---------------------------------
Expand Down
4 changes: 2 additions & 2 deletions doc/source/dev/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
.. _GitHub: https://github.com/holgern/pyedflib
10 changes: 5 additions & 5 deletions doc/source/dev/preparing_windows_build_environment.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 for Python
---------------------------------------------------

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
Expand All @@ -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/
2 changes: 1 addition & 1 deletion doc/source/resources.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
41 changes: 15 additions & 26 deletions pyedflib/edfwriter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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:
"""
Expand Down Expand Up @@ -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:
"""
Expand Down
2 changes: 1 addition & 1 deletion pyedflib/highlevel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
8 changes: 2 additions & 6 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 201cd0b

Please sign in to comment.