From c0d33dd57948d71dfbd039536e615b2159726657 Mon Sep 17 00:00:00 2001 From: Victor Seva Date: Mon, 27 May 2019 13:16:59 +0200 Subject: [PATCH] support setting DJANGO_PROJECT_FOLDER via --project-root-path settings file can be located in a subdirectory of the project --- README.rst | 3 ++- .../management/commands/lintmigrations.py | 12 +++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/README.rst b/README.rst index 8312237..cb3b37e 100644 --- a/README.rst +++ b/README.rst @@ -43,7 +43,7 @@ Add the migration linter your ``INSTALLED_APPS``: ] -``python manage.py lintmigrations [GIT_COMMIT_ID] [--ignore-name-contains IGNORE_NAME_CONTAINS] [--include-apps INCLUDE_APPS [INCLUDE_APPS ...] | --exclude-apps EXCLUDE_APPS [EXCLUDE_APPS ...]]`` +``python manage.py lintmigrations [GIT_COMMIT_ID] [--ignore-name-contains IGNORE_NAME_CONTAINS] [--include-apps INCLUDE_APPS [INCLUDE_APPS ...] | --exclude-apps EXCLUDE_APPS [EXCLUDE_APPS ...]] [--project-root-path DJANGO_PROJECT_FOLDER]`` ================================================== =========================================================================================================================== Parameter Description @@ -59,6 +59,7 @@ Add the migration linter your ``INSTALLED_APPS``: ``--no-cache`` Don't use a cache. ``--applied-migrations`` Only lint migrations that are applied to the selected database. Other migrations are ignored. ``--unapplied-migrations`` Only lint migrations that are not yet applied to the selected database. Other migrations are ignored. +``--project-root-path DJANGO_PROJECT_FOLDER`` An absolute or relative path to the django project. ================================================== =========================================================================================================================== Examples diff --git a/django_migration_linter/management/commands/lintmigrations.py b/django_migration_linter/management/commands/lintmigrations.py index c64b571..2263d9d 100644 --- a/django_migration_linter/management/commands/lintmigrations.py +++ b/django_migration_linter/management/commands/lintmigrations.py @@ -46,6 +46,9 @@ class Command(BaseCommand): "Defaults to default" ), ) + parser.add_argument( + "--project-root-path", type=str, nargs="?", help="django project root path" + ) cache_group = parser.add_mutually_exclusive_group(required=False) cache_group.add_argument( @@ -86,9 +89,12 @@ class Command(BaseCommand): ) def handle(self, *args, **options): - settings_path = os.path.dirname( - import_module(os.getenv("DJANGO_SETTINGS_MODULE")).__file__ - ) + if options["project_root_path"]: + settings_path = options["project_root_path"] + else: + settings_path = os.path.dirname( + import_module(os.getenv("DJANGO_SETTINGS_MODULE")).__file__ + ) if options["verbosity"] > 1: logging.basicConfig(format="%(message)s", level=logging.DEBUG)