Skip to content

Commit

Permalink
Python: Remove code for Python 2, remove six from requirements (#3079)
Browse files Browse the repository at this point in the history
* remove unused code

* removing six dependency from CI

* remove reference to removed orderdict.py

* python2: remove old py3-compat imports from __future__

* python2 removal: review all "except ImportError:"

* python2 removal: update ctypesgen help text

* python2 removal: Ctypes is a builtin now

* rpm: remove reference to RHEL6 python2 packages


---------

Co-authored-by: Anna Petrasova <[email protected]>
  • Loading branch information
a-detiste and petrasovaa authored Aug 8, 2023
1 parent 4428fae commit e2d4fba
Show file tree
Hide file tree
Showing 170 changed files with 328 additions and 1,171 deletions.
1 change: 0 additions & 1 deletion .github/workflows/apt.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ python3-numpy
python3-pil
python3-ply
python3-pyvirtualdisplay
python3-six
python3-termcolor
sqlite3
zlib1g-dev
4 changes: 2 additions & 2 deletions .github/workflows/osgeo4w.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:
mingw-w64-x86_64-gcc mingw-w64-x86_64-ccache mingw-w64-x86_64-zlib mingw-w64-x86_64-libiconv
mingw-w64-x86_64-bzip2 mingw-w64-x86_64-gettext mingw-w64-x86_64-libsystre
mingw-w64-x86_64-libtre-git mingw-w64-x86_64-libwinpthread-git mingw-w64-x86_64-libpng
mingw-w64-x86_64-pcre mingw-w64-x86_64-python3-six
mingw-w64-x86_64-pcre

- name: Install OSGeo4W
run: |
Expand All @@ -57,7 +57,7 @@ jobs:
pdal-devel,netcdf-devel,cairo-devel,fftw,freetype-devel,gdal-ecw,\
gdal-mrsid,liblas-devel,libxdr,libpq-devel,pdcurses,\
python3-matplotlib,python3-numpy,python3-ply,python3-pywin32,\
python3-six,python3-wxpython,regex-devel,zstd-devel"
python3-wxpython,regex-devel,zstd-devel"

- name: Compile GRASS GIS
run: D:\msys64\usr\bin\bash.exe -l (''+(Get-Location)+'\.github\workflows\build_osgeo4w.sh') (Get-Location)
Expand Down
2 changes: 1 addition & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ init-import=no

# List of qualified module names which can have objects that can redefine
# builtins.
redefining-builtins-modules=six.moves,past.builtins,future.builtins,builtins,io
redefining-builtins-modules=past.builtins,future.builtins,builtins,io


[SIMILARITIES]
Expand Down
1 change: 0 additions & 1 deletion .travis/linux.install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ sudo apt-get install --no-install-recommends \
python3-pil \
python3-pip \
python3-ply \
python3-six \
python-wxgtk3.0 \
unixodbc-dev \
libnetcdf-dev \
Expand Down
8 changes: 0 additions & 8 deletions REQUIREMENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,6 @@ Note: also the respective development packages (commonly named `xxx-dev` or
[https://cran.r-project.org](https://cran.r-project.org)
- **FreeType2** (for TrueType font support and `d.text.freetype`)
[https://freetype.org/](https://freetype.org/)
- **Ctypes** (for ctypes interface)
Ctypes can be added as a third-party module in Python 2.3 and
2.4 - [https://pypi.org/project/ctypes/1.0.2/](https://pypi.org/project/ctypes/1.0.2/)
[https://docs.python.org/library/ctypes.html](https://docs.python.org/library/ctypes.html)
- **wxPython >= 2.8.10.1** (for wxGUI)
[https://www.wxpython.org](https://www.wxpython.org)
- **NumPy >= 1.0.4** (for various wxGUI components and pyGRASS)
Expand All @@ -107,10 +103,6 @@ Note: also the respective development packages (commonly named `xxx-dev` or
[https://matplotlib.org/](https://matplotlib.org/)
- **python-termcolor** (recommended for `g.search.modules`)
[https://pypi.org/project/termcolor/](https://pypi.org/project/termcolor/)
- **six** (`python-six`, needed for Python API and for cross-version Python
compatibility)
[https://pypi.python.org/pypi/six](https://pypi.python.org/pypi/six)
[https://github.com/benjaminp/six](https://github.com/benjaminp/six)
- **FFMPEG or alternative** (for wxGUI Animation tool - `g.gui.module`),
specifically ffmpeg tool
[https://ffmpeg.org](https://ffmpeg.org)
Expand Down
1 change: 0 additions & 1 deletion Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
"python3-numpy",
"python3-ply",
"python3-pil",
"python3-six",
"libnetcdf-dev",
"netcdf-bin",
"libblas-dev",
Expand Down
1 change: 0 additions & 1 deletion docker/alpine/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ ENV GRASS_RUN_PACKAGES="\
openblas \
py3-numpy \
py3-pillow \
py3-six \
pdal \
pdal-dev \
postgresql15-client \
Expand Down
2 changes: 1 addition & 1 deletion gui/wxpython/.pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ init-import=no

# List of qualified module names which can have objects that can redefine
# builtins.
redefining-builtins-modules=six.moves,past.builtins,future.builtins,builtins,io
redefining-builtins-modules=past.builtins,future.builtins,builtins,io


[SIMILARITIES]
Expand Down
2 changes: 0 additions & 2 deletions gui/wxpython/animation/dialogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
@author Anna Petrasova <kratochanna gmail.com>
"""

from __future__ import print_function

import os
import wx
import copy
Expand Down
3 changes: 1 addition & 2 deletions gui/wxpython/animation/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import os
import wx
import wx.aui
import six

import grass.script as gcore
import grass.temporal as tgis
Expand Down Expand Up @@ -143,7 +142,7 @@ def _addPanes(self):
.DestroyOnClose(True)
.Layer(0),
)
for name, slider in six.iteritems(self.animationSliders):
for name, slider in self.animationSliders.items():
self._mgr.AddPane(
slider,
wx.aui.AuiPaneInfo()
Expand Down
7 changes: 1 addition & 6 deletions gui/wxpython/animation/nviztask.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,7 @@
@author Anna Petrasova <kratochanna gmail.com>
"""

from __future__ import print_function

try:
import xml.etree.ElementTree as etree
except ImportError:
import elementtree.ElementTree as etree # Python <= 2.4
import xml.etree.ElementTree as etree

from core.workspace import ProcessWorkspaceFile
from core.gcmd import RunCommand, GException
Expand Down
2 changes: 0 additions & 2 deletions gui/wxpython/animation/temporal_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
@author Anna Kratochvilova <kratochanna gmail.com>
"""

from __future__ import print_function

import datetime

import grass.script as grass
Expand Down
3 changes: 1 addition & 2 deletions gui/wxpython/animation/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import os
import wx
import hashlib
import six
from multiprocessing import cpu_count

try:
Expand Down Expand Up @@ -99,7 +98,7 @@ def validateMapNames(names, etype):
raise GException(_("Map <%s> not found.") % name)
else:
found = False
for mapset, mapNames in six.iteritems(mapDict):
for mapset, mapNames in mapDict.items():
if name in mapNames:
found = True
newNames.append(name + "@" + mapset)
Expand Down
5 changes: 0 additions & 5 deletions gui/wxpython/core/gcmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
@author Martin Landa <landa.martin gmail.com>
"""

from __future__ import print_function

import os
import sys
import time
Expand All @@ -53,9 +51,6 @@
from grass.script import core as grass
from grass.script.utils import decode, encode

if sys.version_info.major == 2:
bytes = str


def DecodeString(string):
"""Decode string using system encoding
Expand Down
10 changes: 3 additions & 7 deletions gui/wxpython/core/gconsole.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,13 +409,9 @@ def Redirect(self):
except AttributeError:
enc = locale.getdefaultlocale()[1]
if enc:
if sys.version_info.major == 2:
sys.stdout = codecs.getwriter(enc)(sys.__stdout__)
sys.stderr = codecs.getwriter(enc)(sys.__stderr__)
else:
# https://stackoverflow.com/questions/4374455/how-to-set-sys-stdout-encoding-in-python-3
sys.stdout = codecs.getwriter(enc)(sys.__stdout__.detach())
sys.stderr = codecs.getwriter(enc)(sys.__stderr__.detach())
# https://stackoverflow.com/questions/4374455/how-to-set-sys-stdout-encoding-in-python-3
sys.stdout = codecs.getwriter(enc)(sys.__stdout__.detach())
sys.stderr = codecs.getwriter(enc)(sys.__stderr__.detach())
else:
sys.stdout = sys.__stdout__
sys.stderr = sys.__stderr__
Expand Down
5 changes: 1 addition & 4 deletions gui/wxpython/core/gthread.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@

import sys

if sys.version_info.major == 2:
import Queue
else:
import queue as Queue
import queue as Queue

from core.gconsole import EVT_CMD_DONE, wxCmdDone

Expand Down
8 changes: 1 addition & 7 deletions gui/wxpython/core/menutree.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,10 @@
@author Anna Petrasova <kratochanna gmail.com>
"""

from __future__ import print_function

import os
import sys
import copy

try:
import xml.etree.ElementTree as etree
except ImportError:
import elementtree.ElementTree as etree # Python <= 2.4
import xml.etree.ElementTree as etree

import wx

Expand Down
2 changes: 0 additions & 2 deletions gui/wxpython/core/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
@author Luca Delucchi <lucadeluge gmail.com> (language choice)
"""

from __future__ import print_function

import os
import sys
import copy
Expand Down
38 changes: 3 additions & 35 deletions gui/wxpython/core/toolboxes.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,18 @@
@author Anna Petrasova <kratochanna gmail.com>
"""

from __future__ import print_function

import os
import sys
import copy
import xml.etree.ElementTree as etree
from xml.parsers import expat

# Get the XML parsing exceptions to catch. The behavior chnaged with Python 2.7
# and ElementTree 1.3.
if hasattr(etree, "ParseError"):
ETREE_EXCEPTIONS = (etree.ParseError, expat.ExpatError)
else:
ETREE_EXCEPTIONS = expat.ExpatError

if sys.version_info[0:2] > (2, 6):
has_xpath = True
else:
has_xpath = False

import grass.script.task as gtask
import grass.script.core as gcore
from grass.script.utils import try_remove, decode
from grass.exceptions import ScriptError, CalledModuleError

ETREE_EXCEPTIONS = (etree.ParseError, expat.ExpatError)

# duplicating code from core/globalvar.py
# if this will become part of grass Python library or module, this should be
Expand Down Expand Up @@ -430,18 +417,7 @@ def _expandToolboxes(node, toolboxes):
items = n.find("./items")
idx = list(items).index(subtoolbox)

if has_xpath:
toolbox = toolboxes.find(
'.//toolbox[@name="%s"]' % subtoolbox.get("name")
)
else:
toolbox = None
potentialToolboxes = toolboxes.findall(".//toolbox")
sName = subtoolbox.get("name")
for pToolbox in potentialToolboxes:
if pToolbox.get("name") == sName:
toolbox = pToolbox
break
toolbox = toolboxes.find('.//toolbox[@name="%s"]' % subtoolbox.get("name"))

if toolbox is None: # not in file
continue
Expand Down Expand Up @@ -576,15 +552,7 @@ def _expandItems(node, items, itemTag):
"""
for moduleItem in node.findall(".//" + itemTag):
itemName = moduleItem.get("name")
if has_xpath:
moduleNode = items.find('.//%s[@name="%s"]' % (itemTag, itemName))
else:
moduleNode = None
potentialModuleNodes = items.findall(".//%s" % itemTag)
for mNode in potentialModuleNodes:
if mNode.get("name") == itemName:
moduleNode = mNode
break
moduleNode = items.find('.//%s[@name="%s"]' % (itemTag, itemName))

if moduleNode is None: # module not available in dist
continue
Expand Down
3 changes: 1 addition & 2 deletions gui/wxpython/core/treemodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
@author Anna Petrasova <kratochanna gmail.com>
"""
import six
import copy

from grass.script.utils import naturally_sort
Expand Down Expand Up @@ -219,7 +218,7 @@ def children(self):
def nprint(self, text, indent=0):
text.append(indent * " " + self.label)
if self.data:
for key, value in six.iteritems(self.data):
for key, value in self.data.items():
text.append(
"%(indent)s* %(key)s : %(value)s"
% {"indent": (indent + 2) * " ", "key": key, "value": value}
Expand Down
3 changes: 1 addition & 2 deletions gui/wxpython/core/units.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
@author Martin Landa <landa.martin gmail.com>
"""

import six
import math

if __name__ == "__main__":
Expand Down Expand Up @@ -80,7 +79,7 @@ def GetUnitsIndex(self, type, key):
:return: index
"""
for k, u in six.iteritems(self._units[type]):
for k, u in self._units[type].items():
if u["key"] == key:
return k
return 0
Expand Down
3 changes: 1 addition & 2 deletions gui/wxpython/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import re
import inspect
import operator
import six

from grass.script import core as grass
from grass.script import task as gtask
Expand Down Expand Up @@ -878,7 +877,7 @@ def StoreEnvVariable(key, value=None, envFile=None):
else:
expCmd = "export"

for key, value in six.iteritems(environ):
for key, value in environ.items():
fd.write("%s %s=%s\n" % (expCmd, key, value))

# write also skipped lines
Expand Down
Loading

0 comments on commit e2d4fba

Please sign in to comment.