Skip to content

Commit

Permalink
support setting DJANGO_PROJECT_FOLDER via --project-root-path
Browse files Browse the repository at this point in the history
settings file can be located in a subdirectory of the project
  • Loading branch information
linuxmaniac authored and David-Wobrock committed Jul 10, 2019
1 parent 83850fa commit c0d33dd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
3 changes: 2 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
12 changes: 9 additions & 3 deletions django_migration_linter/management/commands/lintmigrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ def add_arguments(self, parser):
"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(
Expand Down Expand Up @@ -86,9 +89,12 @@ def add_arguments(self, parser):
)

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)
Expand Down

0 comments on commit c0d33dd

Please sign in to comment.