From 92a686f13bc152c6c102d495861675a97d420498 Mon Sep 17 00:00:00 2001 From: Felix Date: Sat, 5 Jan 2019 19:50:22 +0100 Subject: [PATCH] Make imports relative --- django_migration_linter/cache.py | 2 +- django_migration_linter/migration_linter.py | 20 +++++++++----------- django_migration_linter/sql_analyser.py | 2 +- django_migration_linter/utils.py | 2 +- 4 files changed, 12 insertions(+), 14 deletions(-) diff --git a/django_migration_linter/cache.py b/django_migration_linter/cache.py index 0beedcf6..909d45f1 100644 --- a/django_migration_linter/cache.py +++ b/django_migration_linter/cache.py @@ -16,7 +16,7 @@ import os import pickle -from django_migration_linter.utils import split_path +from .utils import split_path class Cache(dict): diff --git a/django_migration_linter/migration_linter.py b/django_migration_linter/migration_linter.py index dee83f69..21b847ac 100644 --- a/django_migration_linter/migration_linter.py +++ b/django_migration_linter/migration_linter.py @@ -19,10 +19,10 @@ from subprocess import Popen, PIPE import sys -from django_migration_linter.cache import Cache -from django_migration_linter.constants import DEFAULT_CACHE_PATH, MIGRATION_FOLDER_NAME -from . import utils +from .cache import Cache +from .constants import DEFAULT_CACHE_PATH, MIGRATION_FOLDER_NAME from .migration import Migration +from .utils import is_directory, is_django_project, is_git_project, clean_bytes_to_str from .sql_analyser import analyse_sql_statements logger = logging.getLogger(__name__) @@ -31,13 +31,13 @@ class MigrationLinter(object): def __init__(self, project_path, **kwargs): # Verify correctness - if not utils.is_directory(project_path): + if not is_directory(project_path): raise ValueError( "The given path {0} does not seem to be a directory.".format( project_path ) ) - if not utils.is_django_project(project_path): + if not is_django_project(project_path): raise ValueError( ("The given path {0} does not " "seem to be a django project.").format( project_path @@ -136,7 +136,7 @@ def print_errors(errors): def lint_all_migrations(self, git_commit_id=None): # Collect migrations if git_commit_id: - if not utils.is_git_project(self.django_path): + if not is_git_project(self.django_path): raise ValueError( ( "The given project {0} does not seem " "to be versioned by git." @@ -190,9 +190,7 @@ def get_sql(self, app_name, migration_name): ) sql_statements = [] - for line in map( - utils.clean_bytes_to_str, sqlmigrate_process.stdout.readlines() - ): + for line in map(clean_bytes_to_str, sqlmigrate_process.stdout.readlines()): sql_statements.append(line) sqlmigrate_process.wait() if sqlmigrate_process.returncode != 0: @@ -211,7 +209,7 @@ def _gather_migrations_git(self, git_commit_id): ).format(self.django_path, git_commit_id) logger.info("Executing {0}".format(git_diff_command)) diff_process = Popen(git_diff_command, shell=True, stdout=PIPE, stderr=PIPE) - for line in map(utils.clean_bytes_to_str, diff_process.stdout.readlines()): + for line in map(clean_bytes_to_str, diff_process.stdout.readlines()): # Only gather lines that include added migrations if ( re.search(r"\/{0}\/.*\.py".format(MIGRATION_FOLDER_NAME), line) @@ -222,7 +220,7 @@ def _gather_migrations_git(self, git_commit_id): if diff_process.returncode != 0: output = [] - for line in map(utils.clean_bytes_to_str, diff_process.stderr.readlines()): + for line in map(clean_bytes_to_str, diff_process.stderr.readlines()): output.append(line) logger.info("Error while git diff command:\n{}".format("".join(output))) raise Exception("Error while executing git diff command") diff --git a/django_migration_linter/sql_analyser.py b/django_migration_linter/sql_analyser.py index de54f432..44b5246a 100644 --- a/django_migration_linter/sql_analyser.py +++ b/django_migration_linter/sql_analyser.py @@ -15,7 +15,7 @@ import re import logging -from django_migration_linter.operations import IGNORE_MIGRATION_SQL +from .operations import IGNORE_MIGRATION_SQL IGNORED_MIGRATION = "IGNORED_MIGRATION" diff --git a/django_migration_linter/utils.py b/django_migration_linter/utils.py index 1efc5d7d..da5dfdc2 100644 --- a/django_migration_linter/utils.py +++ b/django_migration_linter/utils.py @@ -17,7 +17,7 @@ import os import sys -from django_migration_linter.constants import MIGRATION_FOLDER_NAME +from .constants import MIGRATION_FOLDER_NAME def is_django_project(path):