diff --git a/.pre-commit-hooks.yaml b/.pre-commit-hooks.yaml index e0d81e4..78d8cd3 100644 --- a/.pre-commit-hooks.yaml +++ b/.pre-commit-hooks.yaml @@ -1,8 +1,7 @@ - id: django-migrate - name: django-migrate + name: django migrate description: Check a django app for missing migrations - entry: hook/django_migrate.sh - language: script - types: [shell] + entry: django-migrate + language: python always_run: true verbose: true diff --git a/hook/django_migrate.sh b/hook/django_migrate.sh deleted file mode 100755 index 73e6d67..0000000 --- a/hook/django_migrate.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/usr/bin/env bash -set -o errexit -set -o pipefail -set -o nounset - -if command python manage.py makemigrations --dry-run | grep -q 'No changes detected'; then - exit 0 -else - exit 1 -fi \ No newline at end of file diff --git a/hooks/__init__.py b/hooks/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/hooks/django_migrate.py b/hooks/django_migrate.py new file mode 100755 index 0000000..21f1853 --- /dev/null +++ b/hooks/django_migrate.py @@ -0,0 +1,17 @@ +import subprocess +import os +from pathlib import Path + +def main(): + exitcode = 0 + cp = subprocess.run( + ["python", "manage.py", "makemigrations", "--dry-run", "/dev/null"], + capture_output=True + ) + if cp.stdout: + if not cp.stdout.__contains__("No changes detected"): + exitcode = 1 + return exitcode + +if __name__ == "__main__": + exit(main()) \ No newline at end of file diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..a394bdc --- /dev/null +++ b/setup.cfg @@ -0,0 +1,26 @@ +[metadata] +name = hooks +version = 0.0.1 +description = Checks for missing django migrations +license = MIT +license_file = LICENSE +classifiers = + License :: OSI Approved :: MIT License + Programming Language :: Python :: 3 + Programming Language :: Python :: 3 :: Only + Programming Language :: Python :: 3.6 + Programming Language :: Python :: 3.7 + Programming Language :: Python :: 3.8 + Programming Language :: Python :: Implementation :: CPython + Programming Language :: Python :: Implementation :: PyPy + +[options] +packages = find: +python_requires = >=3.6.1 + +[options.entry_points] +console_scripts = + django-migrate = hooks.django_migrate:main + +[bdist_wheel] +universal = True \ No newline at end of file diff --git a/setup.py b/setup.py index e69de29..533b733 100644 --- a/setup.py +++ b/setup.py @@ -0,0 +1,25 @@ +# Always prefer setuptools over distutils +from setuptools import setup +setup() +# from setuptools import setup, find_packages + + +# setup( +# name='django-migrations', +# version='0.0.1', +# packages=find_packages(), +# entry_points = { +# 'console_scripts': ['django_migrate=django_migrate:check_migrations'], +# }, +# url='https://github.com/caktus/django-migrations', +# author='Caktus Group', +# author_email='', +# description='A pre-commit hook to check a django app for migrations', +# python_requires='>=3.5', +# classifiers=[ +# 'Intended Audience :: Developers', +# 'Topic :: Software Development :: Build Tools', +# 'License :: OSI Approved :: BSD License', +# 'Programming Language :: Python :: 3', +# ] +# )