#92 Drop Python 2 compatibility
Closed 9 months ago by tdawson. Opened a year ago by carlwgeorge.
centos/ carlwgeorge/centpkg no-six  into  develop

file modified
+1 -1
@@ -2,7 +2,7 @@ 

  import os

  import sys

  

- from six.moves.configparser import ConfigParser

+ from configparser import ConfigParser

  

  if __name__ == '__main__':

      module_path = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))

file modified
+1 -1
@@ -16,7 +16,7 @@ 

          'python-gitlab',

          'pycurl',

          'rpkg>=1.65',

-         'six',

      ],

      scripts=['src/bin/centpkg', 'src/bin/centpkg-sig'],

+     python_requires='>=3.6',

  )

file modified
+2 -2
@@ -17,7 +17,7 @@ 

  import sys

  import logging

  

- import six.moves.configparser as ConfigParser

+ from configparser import ConfigParser

  

  import pyrpkg

  import pyrpkg.utils
@@ -54,7 +54,7 @@ 

          sys.exit(1)

  

      # Setup a configuration object and read config file data

-     config = ConfigParser.SafeConfigParser()

+     config = ConfigParser()

      config.read(args.config)

      config.read(args.user_config)

  

file modified
+4 -4
@@ -22,8 +22,8 @@ 

  import centpkg.utils

  from pyrpkg.cli import cliClient

  from pyrpkg import rpkgError

- from six.moves.urllib_parse import urlparse

- import six.moves.configparser as ConfigParser

+ from urllib.parse import urlparse

+ from configparser import ConfigParser

  

  import gitlab

  import json
@@ -147,7 +147,7 @@ 

          internal_config_file = "/etc/rpkg/centpkg_internal.conf"

          if os.path.exists(internal_config_file):

              # Get our internal only variables

-             cfg = ConfigParser.SafeConfigParser()

+             cfg = ConfigParser()

              cfg.read(internal_config_file)

              pp_api_url = config_get_safely(cfg, "centpkg.internal", 'pp_api_url')

              gitbz_query_url = config_get_safely(cfg, "centpkg.internal", 'gitbz_query_url')
@@ -242,7 +242,7 @@ 

  

                  else:

                      # Get our internal only variables

-                     cfg = ConfigParser.SafeConfigParser()

+                     cfg = ConfigParser()

                      cfg.read(internal_config_file)

                      pp_api_url = config_get_safely(cfg, "centpkg.internal", 'pp_api_url')

                      gitbz_query_url = config_get_safely(cfg, "centpkg.internal", 'gitbz_query_url')

file modified
-14
@@ -16,7 +16,6 @@ 

  import io

  import os

  import pycurl

- import six

  import sys

  

  from pyrpkg.errors import InvalidHashType, UploadError, LayoutError
@@ -257,12 +256,6 @@ 

          # https://bugzilla.redhat.com/show_bug.cgi?id=1241059

          _name = utils.get_repo_name(name) if is_dist_git(os.getcwd()) else name

  

-         if six.PY2 and isinstance(filename, six.text_type):

-             filename = filename.encode('utf-8')

- 

-         if six.PY2 and isinstance(self.branch, six.text_type):

-             self.branch = self.branch.encode('utf-8')

- 

          post_data = [('name', _name),

                       ('%ssum' % self.hashtype, hash),

                       ('filename', filename)]
@@ -328,13 +321,6 @@ 

          """

          filename = os.path.basename(filepath)

  

-         # As in remote_file_exists, we need to convert unicode strings to str

-         if six.PY2:

-             if isinstance(name, six.text_type):

-                 name = name.encode('utf-8')

-             if isinstance(filepath, six.text_type):

-                 filepath = filepath.encode('utf-8')

- 

          if self.remote_file_exists(name, filename, hash):

              self.log.info("File already uploaded: %s", filepath)

              return

file modified
+2 -2
@@ -20,8 +20,8 @@ 

  from datetime import date, datetime

  from pyrpkg import rpkgError

  from requests.exceptions import ConnectionError

- from six.moves.configparser import NoOptionError, NoSectionError

- from six.moves.urllib.parse import quote_plus, urlparse

+ from configparser import NoOptionError, NoSectionError

+ from urllib.parse import quote_plus, urlparse

  

  import git as gitpython

  

It was recently discovered that our usage of SafeConfigParser no longer works in Python 3.12. This class was actually renamed to ConfigParser all the way back during Python 3.2. There are still differences in Python 2. Rather than adding conditionals for which name to import between Python 2 and 3, it is easier to just drop Python 2 compatibility. This also removes the need for the six dependency.

https://docs.python.org/3.2/whatsnew/3.2.html#configparser

I am fine with removing python2.
centpkg hasn't worked on RHEL 7 since around 0.6.9. We had one user complain and after we showed them toolbox, they were happier than before. When we moved to centpkg 0.7 It was decided to drop RHEL 7 as supported. Since RHEL7 is no longer supported, there is no reason to keep python2.

I approve this. But I'm going to wait a few days before merging it, incase someone has an objection.

This has been merged in a different way.
I forgot this was a pull request and merged the patch from the rpm.
So, closing this.

Pull-Request has been closed by tdawson

9 months ago

Note: This is in centpkg 0.8.2.