From 9abb9b3d568323ea4216d0286dff7583c6007528 Mon Sep 17 00:00:00 2001 From: Marc Harper Date: Tue, 20 Oct 2015 09:40:08 -0700 Subject: [PATCH] Relative imports to fix packaging issues --- gitinspector/blame.py | 20 ++++---- gitinspector/changes.py | 8 +-- gitinspector/config.py | 12 +++-- gitinspector/format.py | 10 ++-- gitinspector/gitinspector.py | 51 ++++++++++--------- gitinspector/gravatar.py | 6 ++- gitinspector/help.py | 7 ++- gitinspector/localization.py | 10 ++-- gitinspector/metrics.py | 14 ++--- gitinspector/output/blameoutput.py | 15 +++--- gitinspector/output/changesoutput.py | 15 +++--- gitinspector/output/extensionsoutput.py | 12 +++-- gitinspector/output/filteringoutput.py | 39 +++++++------- gitinspector/output/metricsoutput.py | 5 +- gitinspector/output/outputable.py | 2 +- gitinspector/output/responsibilitiesoutput.py | 19 ++++--- gitinspector/output/timelineoutput.py | 14 ++--- gitinspector/responsibilities.py | 5 +- gitinspector/version.py | 9 ++-- 19 files changed, 152 insertions(+), 121 deletions(-) diff --git a/gitinspector/blame.py b/gitinspector/blame.py index a4ce2b7..edba926 100644 --- a/gitinspector/blame.py +++ b/gitinspector/blame.py @@ -19,20 +19,22 @@ from __future__ import print_function from __future__ import unicode_literals -from localization import N_ -from changes import FileDiff -import comment import datetime -import filtering -import format -import interval import multiprocessing import re import subprocess import sys -import terminal import threading +from . import changes +from . import comment +from . import filtering +from . import format +from . import interval +from .localization import N_ +from . import terminal + + NUM_THREADS = multiprocessing.cpu_count() class BlameEntry(object): @@ -138,11 +140,11 @@ class Blame(object): row = row.encode("latin-1", "replace") row = row.decode("utf-8", "replace").strip("\"").strip("'").strip() - if FileDiff.is_valid_extension(row) and not filtering.set_filtered(FileDiff.get_filename(row)): + if changes.FileDiff.is_valid_extension(row) and not filtering.set_filtered(changes.FileDiff.get_filename(row)): blame_command = filter(None, ["git", "blame", "--line-porcelain", "-w"] + \ (["-C", "-C", "-M"] if hard else []) + [interval.get_since(), interval.get_ref(), "--", row]) - thread = BlameThread(useweeks, changes, blame_command, FileDiff.get_extension(row), self.blames, row.strip()) + thread = BlameThread(useweeks, changes, blame_command, changes.FileDiff.get_extension(row), self.blames, row.strip()) thread.daemon = True thread.start() diff --git a/gitinspector/changes.py b/gitinspector/changes.py index 249f255..7d28155 100644 --- a/gitinspector/changes.py +++ b/gitinspector/changes.py @@ -19,14 +19,16 @@ from __future__ import unicode_literals import datetime -import extensions -import filtering -import interval import multiprocessing import os import subprocess import threading +from . import extensions +from . import filtering +from . import interval + + CHANGES_PER_THREAD = 200 NUM_THREADS = multiprocessing.cpu_count() diff --git a/gitinspector/config.py b/gitinspector/config.py index 63b004b..911bb87 100644 --- a/gitinspector/config.py +++ b/gitinspector/config.py @@ -18,14 +18,16 @@ # along with gitinspector. If not, see . from __future__ import unicode_literals -import extensions -import filtering -import format -import interval -import optval + import os import subprocess +from . import extensions +from . import filtering +from . import format +from . import interval +from . import optval + def __read_git_config__(repo, variable): previous_directory = os.getcwd() os.chdir(repo) diff --git a/gitinspector/format.py b/gitinspector/format.py index ada5c99..04968a2 100644 --- a/gitinspector/format.py +++ b/gitinspector/format.py @@ -19,16 +19,18 @@ from __future__ import print_function from __future__ import unicode_literals -import localization -import version import base64 -import basedir import os -import terminal import textwrap import time import zipfile +from . import basedir +from . import localization +from . import terminal +from . import version + + __available_formats__ = ["html", "htmlembedded", "text", "xml"] DEFAULT_FORMAT = __available_formats__[2] diff --git a/gitinspector/gitinspector.py b/gitinspector/gitinspector.py index 56a00bf..9a29de7 100755 --- a/gitinspector/gitinspector.py +++ b/gitinspector/gitinspector.py @@ -20,35 +20,36 @@ from __future__ import print_function from __future__ import unicode_literals -import localization -localization.init() -import sys -sys.path.append("gitinspector") - -from output import outputable -from output.blameoutput import BlameOutput -from output.changesoutput import ChangesOutput -from output.extensionsoutput import ExtensionsOutput -from output.filteringoutput import FilteringOutput -from output.metricsoutput import MetricsOutput -from output.responsibilitiesoutput import ResponsibilitiesOutput -from output.timelineoutput import TimelineOutput import atexit -import basedir -import changes -import clone -import config -import extensions -import filtering -import format -import help -import interval import getopt import os -import optval -import terminal -import version +import sys + +from . import basedir +from . import changes +from . import clone +from . import config +from . import extensions +from . import filtering +from . import format +from . import help +from . import interval +from . import localization +from . import optval +from . import terminal +from . import version +from .output import outputable +from .output.blameoutput import BlameOutput +from .output.changesoutput import ChangesOutput +from .output.extensionsoutput import ExtensionsOutput +from .output.filteringoutput import FilteringOutput +from .output.metricsoutput import MetricsOutput +from .output.responsibilitiesoutput import ResponsibilitiesOutput +from .output.timelineoutput import TimelineOutput + +localization.init() + class Runner(object): def __init__(self): diff --git a/gitinspector/gravatar.py b/gitinspector/gravatar.py index bcf2846..6416415 100644 --- a/gitinspector/gravatar.py +++ b/gitinspector/gravatar.py @@ -18,12 +18,14 @@ # along with gitinspector. If not, see . from __future__ import unicode_literals +import hashlib + try: from urllib.parse import urlencode except: from urllib import urlencode -import format -import hashlib + +from . import format def get_url(email, size=20): md5hash = hashlib.md5(email.encode("utf-8").lower().strip()).hexdigest() diff --git a/gitinspector/help.py b/gitinspector/help.py index 9ddc5c8..2b211f6 100644 --- a/gitinspector/help.py +++ b/gitinspector/help.py @@ -19,10 +19,13 @@ from __future__ import print_function from __future__ import unicode_literals -from extensions import DEFAULT_EXTENSIONS -from format import __available_formats__ + import sys +from .extensions import DEFAULT_EXTENSIONS +from .format import __available_formats__ + + __doc__ = _("""Usage: {0} [OPTION]... [REPOSITORY] List information about the repository in REPOSITORY. If no repository is specified, the current directory is used. If multiple repositories are diff --git a/gitinspector/localization.py b/gitinspector/localization.py index 3bf9284..afb3d13 100644 --- a/gitinspector/localization.py +++ b/gitinspector/localization.py @@ -20,11 +20,6 @@ from __future__ import print_function from __future__ import unicode_literals -try: - import basedir -except: - import gitinspector.basedir as basedir - import gettext import locale import os @@ -32,6 +27,11 @@ import re import sys import time +try: + from . import basedir +except: + import gitinspector.basedir as basedir + __enabled__ = False __installed__ = False __translation__ = None diff --git a/gitinspector/metrics.py b/gitinspector/metrics.py index 5713786..9a9bda1 100644 --- a/gitinspector/metrics.py +++ b/gitinspector/metrics.py @@ -18,13 +18,15 @@ # along with gitinspector. If not, see . from __future__ import unicode_literals -from changes import FileDiff -import comment -import filtering -import interval + import re import subprocess +from . import changes +from . import comment +from . import filtering +from . import interval + __metric_eloc__ = {"java": 500, "c": 500, "cpp": 500, "cs": 500, "h": 300, "hpp": 300, "php": 500, "py": 500, "glsl": 1000, "rb": 500, "js": 500, "sql": 1000, "xml": 1000} @@ -54,11 +56,11 @@ class MetricsLogic(object): i = i.encode("latin-1", "replace") i = i.decode("utf-8", "replace").strip("\"").strip("'").strip() - if FileDiff.is_valid_extension(i) and not filtering.set_filtered(FileDiff.get_filename(i)): + if changes.FileDiff.is_valid_extension(i) and not filtering.set_filtered(changes.FileDiff.get_filename(i)): file_r = subprocess.Popen(["git", "show", interval.get_ref() + ":{0}".format(i.strip())], bufsize=1, stdout=subprocess.PIPE).stdout.readlines() - extension = FileDiff.get_extension(i) + extension = changes.FileDiff.get_extension(i) lines = MetricsLogic.get_eloc(file_r, extension) cycc = MetricsLogic.get_cyclomatic_complexity(file_r, extension) diff --git a/gitinspector/output/blameoutput.py b/gitinspector/output/blameoutput.py index 665a966..7056beb 100644 --- a/gitinspector/output/blameoutput.py +++ b/gitinspector/output/blameoutput.py @@ -19,16 +19,19 @@ from __future__ import print_function from __future__ import unicode_literals -from localization import N_ -from .outputable import Outputable -import blame -import format -import gravatar + import json import sys -import terminal import textwrap +from .. import blame +from .. import format +from .. import gravatar +from ..localization import N_ +from .. import terminal +from .outputable import Outputable + + BLAME_INFO_TEXT = N_("Below are the number of rows from each author that have survived and are still " "intact in the current revision") diff --git a/gitinspector/output/changesoutput.py b/gitinspector/output/changesoutput.py index c8be882..f654984 100644 --- a/gitinspector/output/changesoutput.py +++ b/gitinspector/output/changesoutput.py @@ -19,15 +19,18 @@ from __future__ import print_function from __future__ import unicode_literals -from localization import N_ -from .outputable import Outputable -import changes -import format -import gravatar + import json -import terminal import textwrap +from .. import changes +from .. import format +from .. import gravatar +from ..localization import N_ +from .. import terminal +from .outputable import Outputable + + HISTORICAL_INFO_TEXT = N_("The following historical commit information, by author, was found in the repository") NO_COMMITED_FILES_TEXT = N_("No commited files with the specified extensions were found") diff --git a/gitinspector/output/extensionsoutput.py b/gitinspector/output/extensionsoutput.py index e755802..2be4f3a 100644 --- a/gitinspector/output/extensionsoutput.py +++ b/gitinspector/output/extensionsoutput.py @@ -19,12 +19,16 @@ from __future__ import print_function from __future__ import unicode_literals -import extensions -from localization import N_ -from .outputable import Outputable -import terminal + import textwrap +from .. import extensions +from ..localization import N_ +from .. import terminal + +from .outputable import Outputable + + EXTENSIONS_INFO_TEXT = N_("The extensions below were found in the repository history") EXTENSIONS_MARKED_TEXT = N_("(extensions used during statistical analysis are marked)") diff --git a/gitinspector/output/filteringoutput.py b/gitinspector/output/filteringoutput.py index 2cec70f..9a9bcd7 100644 --- a/gitinspector/output/filteringoutput.py +++ b/gitinspector/output/filteringoutput.py @@ -19,13 +19,14 @@ from __future__ import print_function from __future__ import unicode_literals -from filtering import __filters__ -from filtering import has_filtered -from localization import N_ -from .outputable import Outputable -import terminal import textwrap +from .. import filtering +from ..localization import N_ +from .. import terminal +from .outputable import Outputable + + FILTERING_INFO_TEXT = N_("The following files were excluded from the statistics due to the specified exclusion patterns") FILTERING_AUTHOR_INFO_TEXT = N_("The following authors were excluded from the statistics due to the specified exclusion patterns") FILTERING_EMAIL_INFO_TEXT = N_("The authors with the following emails were excluded from the statistics due to the specified " \ @@ -47,12 +48,12 @@ class FilteringOutput(Outputable): return filtering_xml def output_html(self): - if has_filtered(): + if filtering.has_filtered(): filtering_xml = "
" - FilteringOutput.__output_html_section__(_(FILTERING_INFO_TEXT), __filters__["file"][1]) - FilteringOutput.__output_html_section__(_(FILTERING_AUTHOR_INFO_TEXT), __filters__["author"][1]) - FilteringOutput.__output_html_section__(_(FILTERING_EMAIL_INFO_TEXT), __filters__["email"][1]) - FilteringOutput.__output_html_section__(_(FILTERING_COMMIT_INFO_TEXT), __filters__["revision"][1]) + FilteringOutput.__output_html_section__(_(FILTERING_INFO_TEXT), filtering.__filters__["file"][1]) + FilteringOutput.__output_html_section__(_(FILTERING_AUTHOR_INFO_TEXT), filtering.__filters__["author"][1]) + FilteringOutput.__output_html_section__(_(FILTERING_EMAIL_INFO_TEXT), filtering.__filters__["email"][1]) + FilteringOutput.__output_html_section__(_(FILTERING_COMMIT_INFO_TEXT), filtering.__filters__["revision"][1]) filtering_xml += "
" print(filtering_xml) @@ -67,10 +68,10 @@ class FilteringOutput(Outputable): print("...%s" % i[-width+3:] if len(i) > width else i) def output_text(self): - FilteringOutput.__output_text_section__(_(FILTERING_INFO_TEXT), __filters__["file"][1]) - FilteringOutput.__output_text_section__(_(FILTERING_AUTHOR_INFO_TEXT), __filters__["author"][1]) - FilteringOutput.__output_text_section__(_(FILTERING_EMAIL_INFO_TEXT), __filters__["email"][1]) - FilteringOutput.__output_text_section__(_(FILTERING_COMMIT_INFO_TEXT), __filters__["revision"][1]) + FilteringOutput.__output_text_section__(_(FILTERING_INFO_TEXT), filtering.__filters__["file"][1]) + FilteringOutput.__output_text_section__(_(FILTERING_AUTHOR_INFO_TEXT), filtering.__filters__["author"][1]) + FilteringOutput.__output_text_section__(_(FILTERING_EMAIL_INFO_TEXT), filtering.__filters__["email"][1]) + FilteringOutput.__output_text_section__(_(FILTERING_COMMIT_INFO_TEXT), filtering.__filters__["revision"][1]) @staticmethod def __output_xml_section__(info_string, filtered, container_tagname): @@ -86,10 +87,10 @@ class FilteringOutput(Outputable): print("\t\t".format(container_tagname)) def output_xml(self): - if has_filtered(): + if filtering.has_filtered(): print("\t") - FilteringOutput.__output_xml_section__(_(FILTERING_INFO_TEXT), __filters__["file"][1], "files") - FilteringOutput.__output_xml_section__(_(FILTERING_AUTHOR_INFO_TEXT), __filters__["author"][1], "authors") - FilteringOutput.__output_xml_section__(_(FILTERING_EMAIL_INFO_TEXT), __filters__["email"][1], "emails") - FilteringOutput.__output_xml_section__(_(FILTERING_COMMIT_INFO_TEXT), __filters__["revision"][1], "revision") + FilteringOutput.__output_xml_section__(_(FILTERING_INFO_TEXT), filtering.__filters__["file"][1], "files") + FilteringOutput.__output_xml_section__(_(FILTERING_AUTHOR_INFO_TEXT), filtering.__filters__["author"][1], "authors") + FilteringOutput.__output_xml_section__(_(FILTERING_EMAIL_INFO_TEXT), filtering.__filters__["email"][1], "emails") + FilteringOutput.__output_xml_section__(_(FILTERING_COMMIT_INFO_TEXT), filtering.__filters__["revision"][1], "revision") print("\t") diff --git a/gitinspector/output/metricsoutput.py b/gitinspector/output/metricsoutput.py index 2a7775a..f031f30 100644 --- a/gitinspector/output/metricsoutput.py +++ b/gitinspector/output/metricsoutput.py @@ -19,9 +19,10 @@ from __future__ import print_function from __future__ import unicode_literals -from localization import N_ + +from ..localization import N_ +from .. import metrics from .outputable import Outputable -import metrics ELOC_INFO_TEXT = N_("The following files are suspiciously big (in order of severity)") CYCLOMATIC_COMPLEXITY_TEXT = N_("The following files have an elevated cyclomatic complexity (in order of severity)") diff --git a/gitinspector/output/outputable.py b/gitinspector/output/outputable.py index 9f2899d..2fe5684 100644 --- a/gitinspector/output/outputable.py +++ b/gitinspector/output/outputable.py @@ -19,7 +19,7 @@ from __future__ import print_function from __future__ import unicode_literals -import format +from .. import format class Outputable(object): def output_html(self): diff --git a/gitinspector/output/responsibilitiesoutput.py b/gitinspector/output/responsibilitiesoutput.py index 2b7439d..3dada72 100644 --- a/gitinspector/output/responsibilitiesoutput.py +++ b/gitinspector/output/responsibilitiesoutput.py @@ -19,16 +19,19 @@ from __future__ import print_function from __future__ import unicode_literals -from localization import N_ -from .outputable import Outputable -import blame -import changes -import format -import gravatar -import responsibilities as resp -import terminal + import textwrap +from .. import blame +from .. import changes +from .. import format +from .. import gravatar +from ..localization import N_ +from .. import responsibilities as resp +from .. import terminal +from .outputable import Outputable + + RESPONSIBILITIES_INFO_TEXT = N_("The following repsonsibilties, by author, were found in the current " "revision of the repository (comments are exluded from the line count, " "if possible)") diff --git a/gitinspector/output/timelineoutput.py b/gitinspector/output/timelineoutput.py index 46e83a1..30e6908 100644 --- a/gitinspector/output/timelineoutput.py +++ b/gitinspector/output/timelineoutput.py @@ -19,13 +19,15 @@ from __future__ import print_function from __future__ import unicode_literals -from localization import N_ -from .outputable import Outputable -import format -import gravatar -import terminal + import textwrap -import timeline + +from .. import format +from .. import gravatar +from ..localization import N_ +from .. import terminal +from .. import timeline +from .outputable import Outputable TIMELINE_INFO_TEXT = N_("The following history timeline has been gathered from the repository") MODIFIED_ROWS_TEXT = N_("Modified Rows:") diff --git a/gitinspector/responsibilities.py b/gitinspector/responsibilities.py index 77dbc31..af2dc85 100644 --- a/gitinspector/responsibilities.py +++ b/gitinspector/responsibilities.py @@ -19,8 +19,9 @@ from __future__ import print_function from __future__ import unicode_literals -import blame -import changes + +from . import blame +from . import changes class ResponsibiltyEntry(object): blames = {} diff --git a/gitinspector/version.py b/gitinspector/version.py index 6c8c256..6691996 100644 --- a/gitinspector/version.py +++ b/gitinspector/version.py @@ -20,12 +20,9 @@ from __future__ import print_function from __future__ import unicode_literals -try: - import localization - localization.init() -except: - import gitinspector.localization - gitinspector.localization.init() +from . import localization +localization.init() + __version__ = "0.4.3dev"