From c236f6aa032786b1156dd2e9b0200429e38fe4d9 Mon Sep 17 00:00:00 2001 From: Carl George Date: Sep 15 2023 03:38:56 +0000 Subject: Drop Python 2 compatibility 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 --- diff --git a/doc/centpkg_man_page.py b/doc/centpkg_man_page.py index edae454..aa6ec35 100644 --- a/doc/centpkg_man_page.py +++ b/doc/centpkg_man_page.py @@ -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__), '..')) diff --git a/setup.py b/setup.py index 71b2ea1..8b20454 100644 --- a/setup.py +++ b/setup.py @@ -16,7 +16,7 @@ setup( 'python-gitlab', 'pycurl', 'rpkg>=1.65', - 'six', ], scripts=['src/bin/centpkg', 'src/bin/centpkg-sig'], + python_requires='>=3.6', ) diff --git a/src/centpkg/__main__.py b/src/centpkg/__main__.py index c696c69..c0dd86c 100644 --- a/src/centpkg/__main__.py +++ b/src/centpkg/__main__.py @@ -17,7 +17,7 @@ import os import sys import logging -import six.moves.configparser as ConfigParser +from configparser import ConfigParser import pyrpkg import pyrpkg.utils @@ -54,7 +54,7 @@ def main(): 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) diff --git a/src/centpkg/cli.py b/src/centpkg/cli.py index 4b7f830..27d25e6 100755 --- a/src/centpkg/cli.py +++ b/src/centpkg/cli.py @@ -22,8 +22,8 @@ from centpkg.utils import config_get_safely, do_add_remote, do_fork 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 @@ class centpkgClient(cliClient): 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 @@ class centpkgClient(cliClient): 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') diff --git a/src/centpkg/lookaside.py b/src/centpkg/lookaside.py index 4c72c88..859ea8e 100644 --- a/src/centpkg/lookaside.py +++ b/src/centpkg/lookaside.py @@ -16,7 +16,6 @@ download path. import io import os import pycurl -import six import sys from pyrpkg.errors import InvalidHashType, UploadError, LayoutError @@ -257,12 +256,6 @@ class SIGLookasideCache(CGILookasideCache): # 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 @@ class SIGLookasideCache(CGILookasideCache): """ 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 diff --git a/src/centpkg/utils.py b/src/centpkg/utils.py index b201697..7438a96 100644 --- a/src/centpkg/utils.py +++ b/src/centpkg/utils.py @@ -20,8 +20,8 @@ import sys 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