From eceefe7114bc5d0fc94ac77ee4e510c94c1a76bf Mon Sep 17 00:00:00 2001 From: Ross Brattain Date: Wed, 21 Jun 2017 14:57:13 -0700 Subject: add Python3 support with six switch to relative imports for package file use absolute imports in main this requires renaming anteater.py to main.py to avoid absolute import name conflict update setup.py to indicate python 3.4 support Change-Id: I0fcaf8a9825557962dc98a6a4eef490051fbbfb0 Signed-off-by: Ross Brattain --- anteater/anteater.py | 64 -------------------------------------- anteater/main.py | 65 +++++++++++++++++++++++++++++++++++++++ anteater/src/__init__.py | 1 + anteater/src/get_lists.py | 6 ++-- anteater/src/patch_scan.py | 6 ++-- anteater/src/project_scan.py | 7 +++-- anteater/utils/__init__.py | 1 + anteater/utils/anteater_logger.py | 7 +++-- setup.py | 7 +++-- tasks.py | 2 ++ 10 files changed, 90 insertions(+), 76 deletions(-) delete mode 100644 anteater/anteater.py create mode 100644 anteater/main.py diff --git a/anteater/anteater.py b/anteater/anteater.py deleted file mode 100644 index 063fcbd..0000000 --- a/anteater/anteater.py +++ /dev/null @@ -1,64 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- -############################################################################## -# Copyright (c) 2017 Luke Hinds , Red Hat -# -# All rights reserved. This program and the accompanying materials -# are made available under the terms of the Apache License, Version 2.0 -# which accompanies this distribution, and is available at -# http://www.apache.org/licenses/LICENSE-2.0 -############################################################################## - -# from __future__ import division, print_function, absolute_import - -"""Anteater - CI Gate Checks. - -Usage: - anteater (-p |--project) [(-ps |--patchset) ] - anteater (-p |--project) [--path ] - anteater (-h | --help) - anteater --version - -Options: - -h --help Show this screen. - --version Show version. -""" - -import ConfigParser -from docopt import docopt -import os -from src.patch_scan import prepare_patchset -from src.project_scan import prepare_project -import utils.anteater_logger as antlog - - -config = ConfigParser.RawConfigParser() -config.read('anteater.conf') -reports_dir = config.get('config', 'reports_dir') -logger = antlog.Logger(__name__).getLogger() -__version__ = "0.1" - - -def check_dir(): - """ Creates a directory for scan reports """ - try: - os.makedirs(reports_dir) - logger.info('Creating reports directory: {0}'.format(reports_dir)) - except OSError as e: - if not os.path.isdir(reports_dir): - logger.error(e) - - -def main(): - """ Main function, mostly for passing arguments """ - check_dir() - arguments = docopt(__doc__, version=__version__) - - if arguments['']: - prepare_patchset(arguments[''], arguments['']) - elif arguments['']: - prepare_project(arguments[''], arguments['']) - - -if __name__ == "__main__": - main() diff --git a/anteater/main.py b/anteater/main.py new file mode 100644 index 0000000..3a23ceb --- /dev/null +++ b/anteater/main.py @@ -0,0 +1,65 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +############################################################################## +# Copyright (c) 2017 Luke Hinds , Red Hat +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +############################################################################## + +# from __future__ import division, print_function, absolute_import + +"""Anteater - CI Gate Checks. + +Usage: + anteater (-p |--project) [(-ps |--patchset) ] + anteater (-p |--project) [--path ] + anteater (-h | --help) + anteater --version + +Options: + -h --help Show this screen. + --version Show version. +""" +from __future__ import absolute_import + +import six.moves.configparser +from docopt import docopt +import os +from anteater.src.patch_scan import prepare_patchset +from anteater.src.project_scan import prepare_project +from anteater.utils import anteater_logger as antlog + + +config = six.moves.configparser.RawConfigParser() +config.read('anteater.conf') +reports_dir = config.get('config', 'reports_dir') +logger = antlog.Logger(__name__).getLogger() +__version__ = "0.1" + + +def check_dir(): + """ Creates a directory for scan reports """ + try: + os.makedirs(reports_dir) + logger.info('Creating reports directory: {0}'.format(reports_dir)) + except OSError as e: + if not os.path.isdir(reports_dir): + logger.error(e) + + +def main(): + """ Main function, mostly for passing arguments """ + check_dir() + arguments = docopt(__doc__, version=__version__) + + if arguments['']: + prepare_patchset(arguments[''], arguments['']) + elif arguments['']: + prepare_project(arguments[''], arguments['']) + + +if __name__ == "__main__": + main() diff --git a/anteater/src/__init__.py b/anteater/src/__init__.py index 896994c..1db8868 100644 --- a/anteater/src/__init__.py +++ b/anteater/src/__init__.py @@ -1,3 +1,4 @@ +from __future__ import absolute_import import pkg_resources try: diff --git a/anteater/src/get_lists.py b/anteater/src/get_lists.py index b7b9aea..e27335a 100644 --- a/anteater/src/get_lists.py +++ b/anteater/src/get_lists.py @@ -13,15 +13,17 @@ Gathers various values from the gate check yaml file and return them to the calling instance """ +from __future__ import absolute_import import anteater.utils.anteater_logger as antlog -import ConfigParser +import six.moves.configparser import copy import os import yaml import re -config = ConfigParser.RawConfigParser() + +config = six.moves.configparser.RawConfigParser() config.read('anteater.conf') logger = antlog.Logger(__name__).getLogger() master_list = config.get('config', 'master_list') diff --git a/anteater/src/patch_scan.py b/anteater/src/patch_scan.py index f8ef225..71604a8 100644 --- a/anteater/src/patch_scan.py +++ b/anteater/src/patch_scan.py @@ -19,15 +19,15 @@ from __future__ import division, print_function, absolute_import from binaryornot.check import is_binary import anteater.utils.anteater_logger as antlog -import anteater.src.get_lists as get_lists -import ConfigParser import hashlib +import six.moves.configparser import sys import re +from . import get_lists logger = antlog.Logger(__name__).getLogger() -config = ConfigParser.RawConfigParser() +config = six.moves.configparser.RawConfigParser() config.read('anteater.conf') reports_dir = config.get('config', 'reports_dir') failure = False diff --git a/anteater/src/project_scan.py b/anteater/src/project_scan.py index 15498f1..647c256 100644 --- a/anteater/src/project_scan.py +++ b/anteater/src/project_scan.py @@ -16,16 +16,17 @@ """ from __future__ import division, print_function, absolute_import -import ConfigParser import hashlib +import six.moves.configparser import os import re import anteater.utils.anteater_logger as antlog -import anteater.src.get_lists as get_lists from binaryornot.check import is_binary +from . import get_lists + logger = antlog.Logger(__name__).getLogger() -config = ConfigParser.RawConfigParser() +config = six.moves.configparser.RawConfigParser() config.read('anteater.conf') reports_dir = config.get('config', 'reports_dir') master_list = config.get('config', 'master_list') diff --git a/anteater/utils/__init__.py b/anteater/utils/__init__.py index 896994c..1db8868 100644 --- a/anteater/utils/__init__.py +++ b/anteater/utils/__init__.py @@ -1,3 +1,4 @@ +from __future__ import absolute_import import pkg_resources try: diff --git a/anteater/utils/anteater_logger.py b/anteater/utils/anteater_logger.py index 1fe705f..785e644 100644 --- a/anteater/utils/anteater_logger.py +++ b/anteater/utils/anteater_logger.py @@ -9,11 +9,14 @@ # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## -import ConfigParser +from __future__ import absolute_import + import logging + import os +import six.moves.configparser -config = ConfigParser.RawConfigParser() +config = six.moves.configparser.RawConfigParser() config.read('anteater.conf') anteater_log = config.get('config', 'anteater_log') diff --git a/setup.py b/setup.py index 47d1b19..d392231 100755 --- a/setup.py +++ b/setup.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +from __future__ import absolute_import import re import sys from setuptools.command.test import test as TestCommand @@ -37,7 +38,7 @@ def find_version(fname): raise RuntimeError('Cannot find version information') return version -__version__ = find_version("anteater/anteater.py") +__version__ = find_version("anteater/main.py") def read(fname): @@ -64,6 +65,8 @@ setup( 'Natural Language :: English', "Programming Language :: Python :: 2", 'Programming Language :: Python :: 2.7', + "Programming Language :: Python :: 3", + 'Programming Language :: Python :: 3.4', 'Programming Language :: Python :: Implementation :: CPython', 'Programming Language :: Python :: Implementation :: PyPy' ], @@ -71,7 +74,7 @@ setup( py_modules=["anteater"], entry_points={ 'console_scripts': [ - "anteater = anteater.anteater:main" + "anteater = anteater.main:main" ] }, tests_require=['pytest'], diff --git a/tasks.py b/tasks.py index e2e084b..55ac340 100644 --- a/tasks.py +++ b/tasks.py @@ -1,4 +1,6 @@ # -*- coding: utf-8 -*- +from __future__ import absolute_import +from __future__ import print_function import os import sys -- cgit 1.2.3-korg