From 229913a77fa05e7880ff1895864c0ae9acb202f0 Mon Sep 17 00:00:00 2001 From: Daniel Mach Date: Thu, 28 Jul 2022 12:28:33 +0200 Subject: [PATCH] Clean imports up, drop python 2 fallbacks --- osc/OscConfigParser.py | 22 +++-------- osc/babysitter.py | 24 ++++++------ osc/build.py | 55 ++++++++++----------------- osc/checker.py | 12 +++--- osc/commandline.py | 37 ++++++------------ osc/conf.py | 12 +++--- osc/core.py | 72 ++++++++++-------------------------- osc/credentials.py | 10 ++--- osc/fetch.py | 28 ++++++-------- osc/grabber.py | 21 ++++------- osc/util/ar.py | 4 +- osc/util/archquery.py | 11 +++--- osc/util/cpio.py | 2 +- osc/util/debquery.py | 10 ++--- osc/util/helper.py | 46 ++--------------------- osc/util/packagequery.py | 3 +- osc/util/repodata.py | 27 +++++--------- osc/util/rpmquery.py | 7 ++-- setup.py | 13 +++---- tests/test_addfiles.py | 7 +++- tests/test_commit.py | 21 ++++------- tests/test_core.py | 4 +- tests/test_deletefiles.py | 5 ++- tests/test_difffiles.py | 7 +++- tests/test_helpers.py | 2 + tests/test_init_package.py | 6 ++- tests/test_init_project.py | 6 ++- tests/test_package_status.py | 5 ++- tests/test_prdiff.py | 8 ++-- tests/test_project_status.py | 5 ++- tests/test_repairwc.py | 16 ++++---- tests/test_request.py | 12 ++---- tests/test_results.py | 7 +++- tests/test_revertfiles.py | 5 ++- tests/test_setlinkrev.py | 11 +++--- tests/test_update.py | 8 +++- 36 files changed, 216 insertions(+), 335 deletions(-) diff --git a/osc/OscConfigParser.py b/osc/OscConfigParser.py index a36284f8..475845fa 100644 --- a/osc/OscConfigParser.py +++ b/osc/OscConfigParser.py @@ -13,19 +13,9 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA -from __future__ import print_function -import sys +import configparser -if sys.version_info >= ( 3, ): - import configparser - ConfigParser = configparser.ConfigParser -else: - #python 2.x - import ConfigParser as configparser - ConfigParser = configparser.SafeConfigParser - -import re # inspired from http://code.google.com/p/iniparse/ - although their implementation is # quite different @@ -192,7 +182,7 @@ class OptionLine(Line): self.format(line) def format(self, line): - mo = ConfigParser.OPTCRE.match(line.strip()) + mo = configparser.ConfigParser.OPTCRE.match(line.strip()) key, val = mo.group('option', 'value') self.frmt = line.replace(key.strip(), '%s', 1) pos = val.find(' ;') @@ -205,7 +195,7 @@ class OptionLine(Line): return self.value -class OscConfigParser(ConfigParser): +class OscConfigParser(configparser.ConfigParser): """ OscConfigParser() behaves like a normal ConfigParser() object. The only differences is that it preserves the order+format of configuration entries @@ -214,7 +204,7 @@ class OscConfigParser(ConfigParser): class. """ def __init__(self, defaults={}): - ConfigParser.__init__(self, defaults) + super().__init__(defaults) self._sections = ConfigLineOrder() # XXX: unfortunately we have to override the _read() method from the ConfigParser() @@ -323,7 +313,7 @@ class OscConfigParser(ConfigParser): fp.write(str(self)) fp.write('\n') else: - ConfigParser.write(self, fp) + super().write(fp) def has_option(self, section, option, proper=False, **kwargs): """ @@ -333,7 +323,7 @@ class OscConfigParser(ConfigParser): """ if proper: return self.optionxform(option) in self._sections[section].keys() - return ConfigParser.has_option(self, section, option, **kwargs) + return super().has_option(section, option, **kwargs) # XXX: simplify! def __str__(self): diff --git a/osc/babysitter.py b/osc/babysitter.py index 2dc26940..93e63b19 100644 --- a/osc/babysitter.py +++ b/osc/babysitter.py @@ -3,23 +3,26 @@ # and distributed under the terms of the GNU General Public Licence, # either version 2, or (at your option) any later version. -from __future__ import print_function import errno -import os.path +import os import pdb +import signal import ssl import sys -import signal import traceback +from http.client import HTTPException, BadStatusLine +from urllib.error import URLError, HTTPError -from osc import commandline -from osc import oscerr +import urllib3.exceptions + +from . import commandline +from . import oscerr +from .OscConfigParser import configparser from .oscssl import CertVerificationError -from osc.util.cpio import CpioError -from osc.util.packagequery import PackageError -from osc.util.helper import decode_it -from osc.OscConfigParser import configparser +from .util.cpio import CpioError +from .util.helper import decode_it +from .util.packagequery import PackageError try: # import as RPMError because the class "error" is too generic @@ -29,9 +32,6 @@ except: class RPMError(Exception): pass -import urllib3.exceptions -from http.client import HTTPException, BadStatusLine -from urllib.error import URLError, HTTPError # the good things are stolen from Matt Mackall's mercurial diff --git a/osc/build.py b/osc/build.py index 6799365a..4f5989a2 100644 --- a/osc/build.py +++ b/osc/build.py @@ -3,42 +3,27 @@ # and distributed under the terms of the GNU General Public Licence, # either version 2, or (at your option) any later version. -from __future__ import print_function - import os import re -import sys import shutil - -try: - from urllib.parse import urlsplit - from urllib.request import URLError, HTTPError -except ImportError: - #python 2.x - from urlparse import urlsplit - from urllib2 import URLError, HTTPError - -from tempfile import NamedTemporaryFile, mkdtemp -from osc.fetch import * -from osc.core import get_buildinfo, store_read_apiurl, store_read_project, store_read_package, meta_exists, quote_plus, get_buildconfig, is_package_dir, dgst -from osc.core import get_binarylist, get_binary_file, run_external, return_external, raw_input -from osc.util import rpmquery, debquery, archquery -from osc.util.helper import decode_it -import osc.conf -from . import oscerr import subprocess -try: - # Works up to Python 3.8, needed for Python < 3.3 (inc 2.7) - from xml.etree import cElementTree as ET -except ImportError: - # will import a fast implementation from 3.3 onwards, needed - # for 3.9+ - from xml.etree import ElementTree as ET +import sys +from tempfile import NamedTemporaryFile, mkdtemp +from urllib.parse import urlsplit +from urllib.request import URLError, HTTPError +from xml.etree import ElementTree as ET +from . import conf from . import connection +from . import oscerr from .conf import config - +from .core import get_buildinfo, store_read_project, store_read_package, meta_exists, quote_plus, get_buildconfig, is_package_dir, dgst +from .core import get_binarylist, get_binary_file, run_external, return_external, raw_input +from .fetch import Fetcher, verify_pacs from .meter import create_text_meter +from .util import rpmquery, debquery, archquery +from .util.helper import decode_it + change_personality = { 'i686': 'linux32', @@ -819,9 +804,9 @@ def main(apiurl, opts, argv): bc_file = None bi_filename = '_buildinfo-%s-%s.xml' % (repo, arch) bc_filename = '_buildconfig-%s-%s' % (repo, arch) - if is_package_dir('.') and os.access(osc.core.store, os.W_OK): - bi_filename = os.path.join(os.getcwd(), osc.core.store, bi_filename) - bc_filename = os.path.join(os.getcwd(), osc.core.store, bc_filename) + if is_package_dir('.') and os.access(core.store, os.W_OK): + bi_filename = os.path.join(os.getcwd(), core.store, bi_filename) + bc_filename = os.path.join(os.getcwd(), core.store, bc_filename) elif not os.access('.', os.W_OK): bi_file = NamedTemporaryFile(prefix=bi_filename) bi_filename = bi_file.name @@ -849,7 +834,7 @@ def main(apiurl, opts, argv): # check for source services if not opts.offline and not opts.noservice: - p = osc.core.Package(os.curdir) + p = core.Package(os.curdir) r = p.run_source_services(verbose=True) if r: raise oscerr.ServiceRuntimeError('Source service run failed!') @@ -1132,12 +1117,12 @@ def main(apiurl, opts, argv): if not old_pkg_dir.startswith('/') and not opts.offline: data = [ prj, pacname, repo, arch] if old_pkg_dir == '_link': - p = osc.core.findpacs(os.curdir)[0] + p = core.findpacs(os.curdir)[0] if not p.islink(): raise oscerr.WrongOptions('package is not a link') data[0] = p.linkinfo.project data[1] = p.linkinfo.package - repos = osc.core.get_repositories_of_project(apiurl, data[0]) + repos = core.get_repositories_of_project(apiurl, data[0]) # hack for links to e.g. Factory if not data[2] in repos and 'standard' in repos: data[2] = 'standard' @@ -1455,7 +1440,7 @@ def main(apiurl, opts, argv): # record our settings for later builds if is_package_dir(os.curdir): - osc.core.store_write_last_buildroot(os.curdir, repo, arch, vm_type) + core.store_write_last_buildroot(os.curdir, repo, arch, vm_type) try: rc = run_external(cmd[0], *cmd[1:]) diff --git a/osc/checker.py b/osc/checker.py index f80a0dad..a7b1e99c 100644 --- a/osc/checker.py +++ b/osc/checker.py @@ -1,10 +1,10 @@ -from __future__ import print_function - -from tempfile import mkdtemp -import os -from shutil import rmtree -import rpm import base64 +import os +from tempfile import mkdtemp +from shutil import rmtree + +import rpm + class KeyError(Exception): def __init__(self, key, *args): diff --git a/osc/commandline.py b/osc/commandline.py index f6fa7a3f..419a229b 100644 --- a/osc/commandline.py +++ b/osc/commandline.py @@ -3,39 +3,24 @@ # and distributed under the terms of the GNU General Public Licence, # either version 2, or version 3 (at your option). -from __future__ import print_function +import imp +import inspect +import os +import sys +import time +from functools import cmp_to_key +from operator import itemgetter +from optparse import SUPPRESS_HELP +from urllib.parse import urlsplit +from urllib.error import HTTPError from . import cmdln from . import conf from . import oscerr -import sys -import time -import imp -import inspect -import os -try: - from urllib.parse import urlsplit - from urllib.error import HTTPError - ET_ENCODING = "unicode" -except ImportError: - #python 2.x - from urlparse import urlsplit - from urllib2 import HTTPError - ET_ENCODING = "utf-8" - -from optparse import SUPPRESS_HELP - from .core import * from .util import safewriter - -try: - from functools import cmp_to_key -except ImportError: - from .util.helper import cmp_to_key - from .util.helper import _html_escape -from operator import itemgetter MAN_HEADER = r""".TH %(ucname)s "1" "%(date)s" "%(name)s %(version)s" "User Commands" .SH NAME @@ -8224,7 +8209,7 @@ Please submit there instead, or use --nodevelproject to force direct submission. data.find('title').text = ''.join(title) data.find('description').text = ''.join(descr) data.find('url').text = url - data = ET.tostring(data, encoding=ET_ENCODING) + data = ET.tostring(data, encoding="unicode") else: print('error - cannot get meta data', file=sys.stderr) sys.exit(1) diff --git a/osc/conf.py b/osc/conf.py index 24df71ca..c9582358 100644 --- a/osc/conf.py +++ b/osc/conf.py @@ -3,7 +3,6 @@ # and distributed under the terms of the GNU General Public Licence, # either version 2, or version 3 (at your option). -from __future__ import print_function """Read osc configuration and store it in a dictionary @@ -36,20 +35,21 @@ The configuration dictionary could look like this: """ + import bz2 import errno +import getpass import os import re import sys -import getpass - from io import StringIO from urllib.parse import urlsplit +from . import credentials from . import OscConfigParser -from osc import oscerr -from osc.util.helper import raw_input -from osc import credentials +from . import oscerr +from .util.helper import raw_input + GENERIC_KEYRING = False GNOME_KEYRING = False diff --git a/osc/core.py b/osc/core.py index 09007c9b..a0b2cf2f 100644 --- a/osc/core.py +++ b/osc/core.py @@ -3,8 +3,6 @@ # and distributed under the terms of the GNU General Public Licence, # either version 2, or version 3 (at your option). -from __future__ import print_function - from .util import git_version __version__ = git_version.get_version('1.0.0~b0') @@ -15,62 +13,37 @@ __version__ = git_version.get_version('1.0.0~b0') # functionality to check_store_version(). __store_version__ = '1.0' + +import errno +import hashlib import locale import os -import os.path -import sys +import platform +import re +import shlex import shutil import subprocess -import re -import socket -import errno -import shlex -import hashlib -import platform - +import sys +from functools import cmp_to_key +from http.client import IncompleteRead +from io import StringIO +from urllib.parse import urlsplit, urlunsplit, urlparse, quote_plus, urlencode, unquote +from urllib.error import HTTPError +from urllib.request import pathname2url +from xml.etree import ElementTree as ET try: import distro except ImportError: distro = None -from urllib.parse import urlsplit, urlunsplit, urlparse, quote_plus, urlencode, unquote -from urllib.error import HTTPError -from urllib.request import pathname2url -from io import StringIO -from http.client import IncompleteRead - -try: - # Works up to Python 3.8, needed for Python < 3.3 (inc 2.7) - from xml.etree import cElementTree as ET -except ImportError: - # will import a fast implementation from 3.3 onwards, needed - # for 3.9+ - from xml.etree import ElementTree as ET - -from . import oscerr from . import conf +from . import oscerr from .connection import http_request, http_GET, http_POST, http_PUT, http_DELETE +from .util.helper import decode_list, decode_it, raw_input, _html_escape -try: - from functools import cmp_to_key -except ImportError: - from .util.helper import cmp_to_key -from osc.util.helper import decode_list, decode_it, raw_input, _html_escape - -try: - # python 2.6 and python 2.7 - unicode - ET_ENCODING = "utf-8" - # python 2.6 does not have bytes and python 2.7 reimplements it as alias to - # str, but in incompatible way as it does not accept the same arguments - bytes = lambda x, *args: x -except: - #python3 does not have unicode, so lets reimplement it - #as void function as it already gets unicode strings - unicode = lambda x, *args: x - ET_ENCODING = "unicode" +ET_ENCODING = "unicode" def compare(a, b): return cmp(a[1:], b[1:]) @@ -4200,8 +4173,7 @@ def create_release_request(apiurl, src_project, message=''): r = Request() # api will complete the request r.add_action('maintenance_release', src_project=src_project) - # XXX: clarify why we need the unicode(...) stuff - r.description = unicode(message, 'utf8') + r.description = message r.create(apiurl) return r @@ -4213,8 +4185,7 @@ def create_maintenance_request(apiurl, src_project, src_packages, tgt_project, t r.add_action('maintenance_incident', src_project=src_project, src_package=p, src_rev=rev, tgt_project=tgt_project, tgt_releaseproject=tgt_releaseproject, opt_sourceupdate = opt_sourceupdate) else: r.add_action('maintenance_incident', src_project=src_project, tgt_project=tgt_project, tgt_releaseproject=tgt_releaseproject, opt_sourceupdate = opt_sourceupdate) - # XXX: clarify why we need the unicode(...) stuff - r.description = unicode(message, 'utf8') + r.description = message r.create(apiurl, addrevision=True, enforce_branching=enforce_branching) return r @@ -4259,11 +4230,6 @@ def create_submit_request(apiurl, options_block, _html_escape(message)) - # Don't do _html_escape(unicode(message, "utf8"))) above. - # Promoting the string to utf8, causes the post to explode with: - # uncaught exception: Fatal error: Start tag expected, '<' not found at :1. - # I guess, my original workaround was not that bad. - u = makeurl(apiurl, ['request'], query='cmd=create') r = None try: diff --git a/osc/credentials.py b/osc/credentials.py index d076b2ad..f20e5896 100644 --- a/osc/credentials.py +++ b/osc/credentials.py @@ -1,13 +1,9 @@ -import importlib -import bz2 import base64 +import bz2 import getpass +import importlib import sys - -try: - from urllib.parse import urlsplit -except ImportError: - from urlparse import urlsplit +from urllib.parse import urlsplit try: import keyring diff --git a/osc/fetch.py b/osc/fetch.py index 839023d0..734c8dfb 100644 --- a/osc/fetch.py +++ b/osc/fetch.py @@ -3,28 +3,22 @@ # and distributed under the terms of the GNU General Public Licence, # either version 2, or (at your option) any later version. -from __future__ import print_function -import sys, os +import os +import re +import sys +import tempfile +from urllib.parse import quote_plus +from urllib.request import HTTPError -try: - from urllib.parse import quote_plus - from urllib.request import HTTPError -except ImportError: - #python 2.x - from urllib import quote_plus - from urllib2 import HTTPError - -from .core import makeurl, streamfile, dgst -from .grabber import OscFileGrabber, OscMirrorGroup -from .util import packagequery, cpio from . import conf from . import oscerr -import tempfile -import re - -from osc.util.helper import decode_it +from .core import makeurl, streamfile, dgst +from .grabber import OscFileGrabber, OscMirrorGroup from .meter import create_text_meter +from .util import packagequery, cpio +from .util.helper import decode_it + class Fetcher: def __init__(self, cachedir='/tmp', api_host_options={}, urllist=[], diff --git a/osc/grabber.py b/osc/grabber.py index b8e4441a..83892f06 100644 --- a/osc/grabber.py +++ b/osc/grabber.py @@ -3,20 +3,15 @@ # and distributed under the terms of the GNU General Public Licence, # either version 2, or (at your option) any later version. -import sys -import os.path -from .core import streamfile -try: - from urllib.request import HTTPError - from urllib.parse import urlparse - from urllib.parse import unquote - from urllib.error import URLError -except ImportError: - from urllib2 import HTTPError - from urlparse import urlparse - from urllib import unquote - from urllib2 import URLError +import os +import sys +from urllib.request import HTTPError +from urllib.parse import urlparse +from urllib.parse import unquote +from urllib.error import URLError + +from .core import streamfile class OscFileGrabber(object): diff --git a/osc/util/ar.py b/osc/util/ar.py index 6e5d2039..8e93a9c1 100644 --- a/osc/util/ar.py +++ b/osc/util/ar.py @@ -13,13 +13,11 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA -from __future__ import print_function import os import re -import sys import stat - +import sys from io import BytesIO diff --git a/osc/util/archquery.py b/osc/util/archquery.py index e8debe8b..526d9a10 100644 --- a/osc/util/archquery.py +++ b/osc/util/archquery.py @@ -1,11 +1,10 @@ - -from __future__ import print_function - -import os.path +import os import re -import tarfile -from . import packagequery import subprocess +import tarfile + +from . import packagequery + class ArchError(packagequery.PackageError): pass diff --git a/osc/util/cpio.py b/osc/util/cpio.py index 9d7bb5c2..5aa875db 100644 --- a/osc/util/cpio.py +++ b/osc/util/cpio.py @@ -13,7 +13,6 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA -from __future__ import print_function import mmap import os @@ -21,6 +20,7 @@ import stat import struct import sys + # workaround for python24 if not hasattr(os, 'SEEK_SET'): os.SEEK_SET = 0 diff --git a/osc/util/debquery.py b/osc/util/debquery.py index 3464d618..6030cac8 100644 --- a/osc/util/debquery.py +++ b/osc/util/debquery.py @@ -1,13 +1,11 @@ - -from __future__ import print_function - -from . import ar -import os.path +import itertools +import os import re import tarfile from io import BytesIO + +from . import ar from . import packagequery -import itertools HAVE_LZMA = True diff --git a/osc/util/helper.py b/osc/util/helper.py index 102c6c81..3bb11a72 100644 --- a/osc/util/helper.py +++ b/osc/util/helper.py @@ -3,43 +3,10 @@ # and distributed under the terms of the GNU General Public Licence, # either version 2, or (at your option) any later version. -try: - import html -except ImportError: - import cgi as html -from osc import oscerr +import html -def cmp_to_key(mycmp): - """ Converts a cmp= function into a key= function. - """ - - class K(object): - def __init__(self, obj, *args): - self.obj = obj - - def __lt__(self, other): - return mycmp(self.obj, other.obj) < 0 - - def __gt__(self, other): - return mycmp(self.obj, other.obj) > 0 - - def __eq__(self, other): - return mycmp(self.obj, other.obj) == 0 - - def __le__(self, other): - return mycmp(self.obj, other.obj) <= 0 - - def __ge__(self, other): - return mycmp(self.obj, other.obj) >= 0 - - def __ne__(self, other): - return mycmp(self.obj, other.obj) != 0 - - def __hash__(self): - raise TypeError('hash not implemented') - - return K +from .. import oscerr def decode_list(ilist): @@ -72,13 +39,8 @@ def decode_it(obj): def raw_input(*args): - try: - import builtins - func = builtins.input - except ImportError: - #python 2.7 - import __builtin__ - func = __builtin__.raw_input + import builtins + func = builtins.input try: return func(*args) diff --git a/osc/util/packagequery.py b/osc/util/packagequery.py index e07a6bbe..c0e28c6e 100644 --- a/osc/util/packagequery.py +++ b/osc/util/packagequery.py @@ -1,6 +1,5 @@ +from .helper import decode_it -from __future__ import print_function -from osc.util.helper import decode_it class PackageError(Exception): """base class for all package related errors""" diff --git a/osc/util/repodata.py b/osc/util/repodata.py index 6c27fba4..d93de24c 100644 --- a/osc/util/repodata.py +++ b/osc/util/repodata.py @@ -1,21 +1,14 @@ """Module for reading repodata directory (created with createrepo) for package information instead of scanning individual rpms.""" -# standard modules + import gzip -import os.path +import os +from xml.etree import ElementTree as ET -try: - # Works up to Python 3.8, needed for Python < 3.3 (inc 2.7) - from xml.etree import cElementTree as ET -except ImportError: - # will import a fast implementation from 3.3 onwards, needed - # for 3.9+ - from xml.etree import ElementTree as ET +from . import rpmquery +from . import packagequery -# project modules -import osc.util.rpmquery -import osc.util.packagequery def namespace(name): return "{http://linux.duke.edu/metadata/%s}" % name @@ -92,7 +85,7 @@ def _to_bytes_list(method): return _method -class RepoDataQueryResult(osc.util.packagequery.PackageQueryResult): +class RepoDataQueryResult(packagequery.PackageQueryResult): """PackageQueryResult that reads in data from the repodata directory files.""" def __init__(self, directory, element): @@ -206,7 +199,7 @@ class RepoDataQueryResult(osc.util.packagequery.PackageQueryResult): release = None else: release = self.release() - return osc.util.rpmquery.RpmQuery.filename(self.name(), None, + return rpmquery.RpmQuery.filename(self.name(), None, self.version(), release, self.arch()) def gettag(self, tag): @@ -217,13 +210,13 @@ class RepoDataQueryResult(osc.util.packagequery.PackageQueryResult): # if either self.epoch() or other.epoch() is None, the vercmp will do # the correct thing because one is transformed into b'None' and the # other one into b"b''" (and 'b' is greater than 'N') - res = osc.util.rpmquery.RpmQuery.rpmvercmp(str(self.epoch()).encode(), str(other.epoch()).encode()) + res = rpmquery.RpmQuery.rpmvercmp(str(self.epoch()).encode(), str(other.epoch()).encode()) if res != 0: return res - res = osc.util.rpmquery.RpmQuery.rpmvercmp(self.version(), other.version()) + res = rpmquery.RpmQuery.rpmvercmp(self.version(), other.version()) if res != 0: return res - res = osc.util.rpmquery.RpmQuery.rpmvercmp(self.release(), other.release()) + res = rpmquery.RpmQuery.rpmvercmp(self.release(), other.release()) return res @_to_bytes_or_None diff --git a/osc/util/rpmquery.py b/osc/util/rpmquery.py index 8d78cc8b..d77a0b7b 100644 --- a/osc/util/rpmquery.py +++ b/osc/util/rpmquery.py @@ -1,11 +1,10 @@ - -from __future__ import print_function - import os import re import struct from . import packagequery -from osc.util.helper import decode_it + +from .helper import decode_it + def cmp(a, b): return (a > b) - (a < b) diff --git a/setup.py b/setup.py index 4771b035..d9a03b3d 100755 --- a/setup.py +++ b/setup.py @@ -1,15 +1,14 @@ #!/usr/bin/env python3 -from distutils.core import setup + import distutils.core -from distutils.command import build, install_data import gzip -import os.path - +import os import setuptools +from distutils.command import build, install_data +import osc.commandline import osc.core -from osc import commandline class build_osc(build.build, object): @@ -23,7 +22,7 @@ class build_osc(build.build, object): man_path = os.path.join(self.build_base, 'osc.1.gz') distutils.log.info('generating %s' % man_path) outfile = gzip.open(man_path, 'wt') - osccli = commandline.Osc(stdout=outfile) + osccli = osc.commandline.Osc(stdout=outfile) # FIXME: we cannot call the main method because osc expects an ~/.oscrc # file (this would break builds in environments like the obs) # osccli.main(argv = ['osc','man']) @@ -119,9 +118,7 @@ setuptools.setup( "Operating System :: POSIX :: BSD :: FreeBSD", "Operating System :: POSIX :: Linux", "Programming Language :: Python", - "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "Programming Language :: Python :: 3.8", diff --git a/tests/test_addfiles.py b/tests/test_addfiles.py index 75d38420..30c16098 100644 --- a/tests/test_addfiles.py +++ b/tests/test_addfiles.py @@ -1,9 +1,12 @@ -import osc.core -import osc.oscerr import os import sys + +import osc.core +import osc.oscerr + from .common import OscTestCase + FIXTURES_DIR = os.path.join(os.path.dirname(__file__), 'addfile_fixtures') def suite(): diff --git a/tests/test_commit.py b/tests/test_commit.py index d2ba8c2e..10f06dc9 100644 --- a/tests/test_commit.py +++ b/tests/test_commit.py @@ -1,20 +1,13 @@ -import osc.core -import osc.oscerr import os import sys +from urllib.error import HTTPError +from xml.etree import ElementTree as ET + +import osc.core +import osc.oscerr + from .common import GET, PUT, POST, DELETE, OscTestCase -try: - # Works up to Python 3.8, needed for Python < 3.3 (inc 2.7) - from xml.etree import cElementTree as ET -except ImportError: - # will import a fast implementation from 3.3 onwards, needed - # for 3.9+ - from xml.etree import ElementTree as ET -try: - from urllib.error import HTTPError -except ImportError: - #python 2.x - from urllib2 import HTTPError + FIXTURES_DIR = os.path.join(os.path.dirname(__file__), 'commit_fixtures') diff --git a/tests/test_core.py b/tests/test_core.py index a81f015f..a574744e 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -1,8 +1,8 @@ +import unittest + from osc.core import parseRevisionOption from osc.oscerr import OscInvalidRevision -import unittest - class TestParseRevisionOption(unittest.TestCase): def test_empty(self): diff --git a/tests/test_deletefiles.py b/tests/test_deletefiles.py index 566ddf47..7b481b8d 100644 --- a/tests/test_deletefiles.py +++ b/tests/test_deletefiles.py @@ -1,8 +1,11 @@ +import os + import osc.core import osc.oscerr -import os + from .common import OscTestCase + FIXTURES_DIR = os.path.join(os.path.dirname(__file__), 'deletefile_fixtures') def suite(): diff --git a/tests/test_difffiles.py b/tests/test_difffiles.py index 43cd570d..1959c03d 100644 --- a/tests/test_difffiles.py +++ b/tests/test_difffiles.py @@ -1,10 +1,13 @@ +import os +import re + import osc.core import osc.oscerr from osc.util.helper import decode_list -import os -import re + from .common import GET, OscTestCase + FIXTURES_DIR = os.path.join(os.path.dirname(__file__), 'difffile_fixtures') def suite(): diff --git a/tests/test_helpers.py b/tests/test_helpers.py index 571b828e..92a65568 100644 --- a/tests/test_helpers.py +++ b/tests/test_helpers.py @@ -1,6 +1,8 @@ import unittest + from osc.util.helper import decode_it, decode_list + def suite(): return unittest.makeSuite(TestResults) diff --git a/tests/test_init_package.py b/tests/test_init_package.py index c513bdd6..ec6c5286 100644 --- a/tests/test_init_package.py +++ b/tests/test_init_package.py @@ -1,7 +1,11 @@ +import os + import osc.core import osc.oscerr -import os + from .common import OscTestCase + + FIXTURES_DIR = os.path.join(os.path.dirname(__file__), 'init_package_fixtures') def suite(): diff --git a/tests/test_init_project.py b/tests/test_init_project.py index ff9dfb9e..269d656c 100644 --- a/tests/test_init_project.py +++ b/tests/test_init_project.py @@ -1,7 +1,11 @@ +import os + import osc.core import osc.oscerr -import os + from .common import GET, OscTestCase + + FIXTURES_DIR = os.path.join(os.path.dirname(__file__), 'init_project_fixtures') def suite(): diff --git a/tests/test_package_status.py b/tests/test_package_status.py index 0fefb4e3..42a24446 100644 --- a/tests/test_package_status.py +++ b/tests/test_package_status.py @@ -1,8 +1,11 @@ +import os + import osc.core import osc.oscerr -import os + from .common import OscTestCase + FIXTURES_DIR = os.path.join(os.path.dirname(__file__), 'project_package_status_fixtures') def suite(): diff --git a/tests/test_prdiff.py b/tests/test_prdiff.py index 35948714..3f1ed989 100644 --- a/tests/test_prdiff.py +++ b/tests/test_prdiff.py @@ -1,9 +1,11 @@ -import osc.commandline -import osc.core -import osc.oscerr import os import re import sys + +import osc.commandline +import osc.core +import osc.oscerr + from .common import GET, POST, OscTestCase, EXPECTED_REQUESTS diff --git a/tests/test_project_status.py b/tests/test_project_status.py index 696f97b5..02f77e36 100644 --- a/tests/test_project_status.py +++ b/tests/test_project_status.py @@ -1,8 +1,11 @@ +import os + import osc.core import osc.oscerr -import os + from .common import OscTestCase + FIXTURES_DIR = os.path.join(os.path.dirname(__file__), 'project_package_status_fixtures') def suite(): diff --git a/tests/test_repairwc.py b/tests/test_repairwc.py index a037b602..e0189e6b 100644 --- a/tests/test_repairwc.py +++ b/tests/test_repairwc.py @@ -1,15 +1,13 @@ -import osc.core -import osc.oscerr import os import sys +from xml.etree import ElementTree as ET + +import osc.core +import osc.oscerr + from .common import GET, PUT, POST, DELETE, OscTestCase -try: - # Works up to Python 3.8, needed for Python < 3.3 (inc 2.7) - from xml.etree import cElementTree as ET -except ImportError: - # will import a fast implementation from 3.3 onwards, needed - # for 3.9+ - from xml.etree import ElementTree as ET + + FIXTURES_DIR = os.path.join(os.path.dirname(__file__), 'repairwc_fixtures') def suite(): diff --git a/tests/test_request.py b/tests/test_request.py index 7840a13f..d0bd491a 100644 --- a/tests/test_request.py +++ b/tests/test_request.py @@ -1,16 +1,12 @@ -try: - # Works up to Python 3.8, needed for Python < 3.3 (inc 2.7) - from xml.etree import cElementTree as ET -except ImportError: - # will import a fast implementation from 3.3 onwards, needed - # for 3.9+ - from xml.etree import ElementTree as ET +import os +from xml.etree import ElementTree as ET import osc.core import osc.oscerr -import os + from .common import OscTestCase + FIXTURES_DIR = os.path.join(os.path.dirname(__file__), 'request_fixtures') def suite(): diff --git a/tests/test_results.py b/tests/test_results.py index 1d4d9660..ad32fcb8 100644 --- a/tests/test_results.py +++ b/tests/test_results.py @@ -1,8 +1,11 @@ -import osc.commandline -from .common import GET, OscTestCase import os import sys +import osc.commandline + +from .common import GET, OscTestCase + + def suite(): import unittest return unittest.makeSuite(TestResults) diff --git a/tests/test_revertfiles.py b/tests/test_revertfiles.py index 121fea39..fe09958b 100644 --- a/tests/test_revertfiles.py +++ b/tests/test_revertfiles.py @@ -1,8 +1,11 @@ +import os + import osc.core import osc.oscerr -import os + from .common import OscTestCase + FIXTURES_DIR = os.path.join(os.path.dirname(__file__), 'revertfile_fixtures') def suite(): diff --git a/tests/test_setlinkrev.py b/tests/test_setlinkrev.py index b4da4743..05888512 100644 --- a/tests/test_setlinkrev.py +++ b/tests/test_setlinkrev.py @@ -1,7 +1,11 @@ +import os + import osc.core import osc.oscerr -import os + from .common import GET, PUT, OscTestCase + + FIXTURES_DIR = os.path.join(os.path.dirname(__file__), 'setlinkrev_fixtures') def suite(): @@ -60,10 +64,7 @@ class TestSetLinkRev(OscTestCase): @GET('http://localhost/source/srcprj/srcpkg?rev=latest&expand=1', text='conflict in file merge', code=400) def test_linkerror(self): """link is broken""" - try: - from urllib.error import HTTPError - except ImportError: - from urllib2 import HTTPError + from urllib.error import HTTPError # the backend returns status 400 if we try to expand a broken _link self.assertRaises(HTTPError, osc.core.set_link_rev, 'http://localhost', 'osctest', 'simple', expand=True) diff --git a/tests/test_update.py b/tests/test_update.py index 251268e8..f6689652 100644 --- a/tests/test_update.py +++ b/tests/test_update.py @@ -1,8 +1,12 @@ -import osc.core -import osc.oscerr import os import sys + +import osc.core +import osc.oscerr + from .common import GET, OscTestCase + + FIXTURES_DIR = os.path.join(os.path.dirname(__file__), 'update_fixtures') def suite():