Merge branch 'dev'

This commit is contained in:
David-Wobrock committed 2018-01-13 00:48:07 +01:00
commit 5f078506a4
16 files changed
+117 -36

No files matched your search

+1
View File
@@ -11,3 +11,4 @@ dist/
.cache/
env/
tests/test_project_fixtures/*/.git/
.tox/
+35 -9
View File
@@ -1,11 +1,37 @@
sudo: false
language: python
python:
- "2.7"
- "3.4"
- "3.5"
- "3.6"
script:
- flake8 django_migration_linter
- py.test
matrix:
include:
- python: 2.7
env: TOXENV=py27-django110
- python: 2.7
env: TOXENV=py27-django111
- python: 3.4
env: TOXENV=py34-django110
- python: 3.4
env: TOXENV=py34-django111
- python: 3.4
env: TOXENV=py34-django20
- python: 3.5
env: TOXENV=py35-django110
- python: 3.5
env: TOXENV=py35-django111
- python: 3.5
env: TOXENV=py35-django20
- python: 3.6
env: TOXENV=py36-django111
- python: 3.6
env: TOXENV=py36-django20
- python: 3.6
env: TOXENV=lint
install:
- pip install -e ".[test]"
- pip install tox
script:
- tox
+2
View File
@@ -0,0 +1,2 @@
include README.md
include LICENSE
+6 -1
View File
@@ -49,7 +49,12 @@ The linter will try to detect if the project is a django project and is versione
## Tests
The easiest way to run the tests is to invoke [py.test](https://docs.pytest.org/en/latest/).
The easiest way to run the tests is to invoke [tox](https://pypi.python.org/pypi/tox).
## Contributing
First, thank you very much if you want to contribute to the project.
Please base your work on the `dev` branch and also target this branch in your pull request.
## License
+1 -1
View File
@@ -1,4 +1,4 @@
# Copyright 2017 3YOURMIND GmbH
# Copyright 2018 3YOURMIND GmbH
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
+11 -5
View File
@@ -1,4 +1,4 @@
# Copyright 2017 3YOURMIND GmbH
# Copyright 2018 3YOURMIND GmbH
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -43,6 +43,8 @@ class MigrationLinter(object):
self.include_apps = kwargs.get('include_apps', None)
self.exclude_apps = kwargs.get('exclude_apps', None)
self.database = kwargs.get('database', None) or 'default'
self.python_exe = '{0}/bin/{1}'.format(sys.prefix, 'python') if \
hasattr(sys, 'real_prefix') else 'python'
# Initialise counters
self.nb_valid = 0
@@ -125,9 +127,11 @@ class MigrationLinter(object):
"""
git_diff_command = (
'cd {0} && '
'python manage.py sqlmigrate {1} {2} '
'--database {3}').format(
self.django_path, app_name, migration_name, self.database)
'{1} manage.py sqlmigrate {2} {3} '
'--database {4}').format(
self.django_path,
self.python_exe, app_name, migration_name,
self.database)
log.info('Executing {0}'.format(git_diff_command))
sqlmigrate_process = Popen(
git_diff_command, shell=True, stdout=PIPE, stderr=PIPE)
@@ -139,7 +143,9 @@ class MigrationLinter(object):
sql_statements.append(line)
sqlmigrate_process.wait()
if sqlmigrate_process.returncode != 0:
raise RuntimeError('sqlmigrate command failed')
_, err = sqlmigrate_process.communicate()
raise RuntimeError('sqlmigrate command failed {0}'.format(
err.decode('utf-8')))
log.info('Found {0} sql migration lines'.format(len(sql_statements)))
return sql_statements
+1 -1
View File
@@ -1,4 +1,4 @@
# Copyright 2017 3YOURMIND GmbH
# Copyright 2018 3YOURMIND GmbH
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
+1 -1
View File
@@ -1,4 +1,4 @@
# Copyright 2017 3YOURMIND GmbH
# Copyright 2018 3YOURMIND GmbH
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
+11 -5
View File
@@ -1,4 +1,4 @@
# Copyright 2017 3YOURMIND GmbH
# Copyright 2018 3YOURMIND GmbH
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -19,17 +19,20 @@ from setuptools import setup, find_packages
PROJECT_DIR = path.abspath(path.dirname(__file__))
with open(path.join(PROJECT_DIR, 'README.md'), encoding='utf-8') as f:
long_description = f.read()
try:
import pypandoc
long_description = pypandoc.convert('README.md', 'rst')
except(IOError, ImportError):
long_description = open('README.md').read()
install_requirements = [
]
test_requirements = [
'pytest',
'django',
'tox',
'django>=1.10',
'django-fake-database-backends',
'flake8'
]
setup(
@@ -59,6 +62,9 @@ setup(
'Intended Audience :: Developers',
'Environment :: Web Environment',
'Framework :: Django',
'Framework :: Django :: 1.10',
'Framework :: Django :: 1.11',
'Framework :: Django :: 2.0',
'Programming Language :: Python',
'Programming Language :: Python :: 2',
+1 -1
View File
@@ -1,4 +1,4 @@
# Copyright 2017 3YOURMIND GmbH
# Copyright 2018 3YOURMIND GmbH
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
+21 -8
View File
@@ -1,4 +1,4 @@
# Copyright 2017 3YOURMIND GmbH
# Copyright 2018 3YOURMIND GmbH
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -16,11 +16,18 @@ import unittest
from subprocess import Popen, PIPE
from django_migration_linter import utils
from tests import fixtures
import sys
class CallLinterFromCommandLineTest(unittest.TestCase):
@classmethod
def setUpClass(cls):
super(CallLinterFromCommandLineTest, cls).setUpClass()
linter_name = 'django-migration-linter'
cls.linter_exec = '{0}/bin/{1}'.format(sys.prefix, linter_name) if hasattr(sys, 'real_prefix') else linter_name
def test_call_linter_cmd_line_working(self):
cmd = 'django-migration-linter {0}'.format(fixtures.CORRECT_PROJECT)
cmd = '{0} {1}'.format(self.linter_exec, fixtures.CORRECT_PROJECT)
process = Popen(
cmd, shell=True, stdout=PIPE, stderr=PIPE)
@@ -33,7 +40,8 @@ class CallLinterFromCommandLineTest(unittest.TestCase):
self.assertTrue(lines[2].endswith('OK'))
def test_call_linter_cmd_line_errors(self):
cmd = 'django-migration-linter {0}'.format(
cmd = '{0} {1}'.format(
self.linter_exec,
fixtures.ADD_NOT_NULL_COLUMN_PROJECT)
process = Popen(
@@ -48,7 +56,8 @@ class CallLinterFromCommandLineTest(unittest.TestCase):
self.assertTrue('RENAMING tables' in lines[2])
def test_call_linter_cmd_line_exclude_apps(self):
cmd = 'django-migration-linter {0} --exclude-apps test_app2'.format(
cmd = '{0} {1} --exclude-apps test_app2'.format(
self.linter_exec,
fixtures.CORRECT_PROJECT)
process = Popen(
@@ -62,7 +71,8 @@ class CallLinterFromCommandLineTest(unittest.TestCase):
self.assertTrue(lines[2].endswith('IGNORE'))
def test_call_linter_cmd_line_include_apps(self):
cmd = 'django-migration-linter {0} --include-apps test_app2'.format(
cmd = '{0} {1} --include-apps test_app2'.format(
self.linter_exec,
fixtures.CORRECT_PROJECT)
process = Popen(
@@ -76,7 +86,8 @@ class CallLinterFromCommandLineTest(unittest.TestCase):
self.assertTrue(lines[2].endswith('OK'))
def test_call_linter_cmd_line_ignore_name(self):
cmd = 'django-migration-linter {0} --ignore-name 0001_initial'.format(
cmd = '{0} {1} --ignore-name 0001_initial'.format(
self.linter_exec,
fixtures.CORRECT_PROJECT)
process = Popen(
@@ -90,7 +101,8 @@ class CallLinterFromCommandLineTest(unittest.TestCase):
self.assertTrue(lines[2].endswith('OK'))
def test_call_linter_cmd_line_ignore_name_contains(self):
cmd = 'django-migration-linter {0} --ignore-name-contains 0001'.format(
cmd = '{0} {1} --ignore-name-contains 0001'.format(
self.linter_exec,
fixtures.CORRECT_PROJECT)
process = Popen(
@@ -104,7 +116,8 @@ class CallLinterFromCommandLineTest(unittest.TestCase):
self.assertTrue(lines[2].endswith('IGNORE'))
def test_call_linter_cmd_line_git_id(self):
cmd = 'django-migration-linter {0} d7125d5f4f0cc9623f670a66c54f131acc50032d'.format(
cmd = '{0} {1} d7125d5f4f0cc9623f670a66c54f131acc50032d'.format(
self.linter_exec,
fixtures.MULTI_COMMIT_PROJECT)
fixtures.prepare_git_project(fixtures.MULTI_COMMIT_PROJECT)
+1 -1
View File
@@ -1,4 +1,4 @@
# Copyright 2017 3YOURMIND GmbH
# Copyright 2018 3YOURMIND GmbH
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
+1 -1
View File
@@ -1,4 +1,4 @@
# Copyright 2017 3YOURMIND GmbH
# Copyright 2018 3YOURMIND GmbH
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
+1 -1
View File
@@ -1,4 +1,4 @@
# Copyright 2017 3YOURMIND GmbH
# Copyright 2018 3YOURMIND GmbH
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
+1 -1
View File
@@ -1,4 +1,4 @@
# Copyright 2017 3YOURMIND GmbH
# Copyright 2018 3YOURMIND GmbH
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
+22
View File
@@ -0,0 +1,22 @@
[tox]
envlist =
py{27,34,35}-django110
py{27,34,35,36}-django111
py{34,35,36}-django20
lint
[testenv]
commands = py.test {posargs}
extras = test
pip_pre = true
deps =
django110: django>=1.10,<1.11
django111: django>=1.11,<2.0
django20: django>=2.0
[testenv:lint]
basepython = python3.6
deps =
flake8
commands =
flake8 django_migration_linter