diff --git a/.gitignore b/.gitignore index 6060cf3..1a58382 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,4 @@ dist/ .cache/ env/ tests/test_project_fixtures/*/.git/ +.tox/ diff --git a/.travis.yml b/.travis.yml index 1ddbdb7..5fea858 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 0000000..04f196a --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1,2 @@ +include README.md +include LICENSE diff --git a/README.md b/README.md index 6c8e3b4..e807b18 100644 --- a/README.md +++ b/README.md @@ -49,7 +49,7 @@ 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). ## License diff --git a/django_migration_linter/__init__.py b/django_migration_linter/__init__.py index 2ad64ea..959bac8 100644 --- a/django_migration_linter/__init__.py +++ b/django_migration_linter/__init__.py @@ -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. diff --git a/django_migration_linter/migration_linter.py b/django_migration_linter/migration_linter.py index 0539f56..edc32ff 100644 --- a/django_migration_linter/migration_linter.py +++ b/django_migration_linter/migration_linter.py @@ -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) diff --git a/django_migration_linter/sql_analyser.py b/django_migration_linter/sql_analyser.py index 121a767..d566072 100644 --- a/django_migration_linter/sql_analyser.py +++ b/django_migration_linter/sql_analyser.py @@ -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. diff --git a/django_migration_linter/utils.py b/django_migration_linter/utils.py index 20def7f..b2b8f23 100644 --- a/django_migration_linter/utils.py +++ b/django_migration_linter/utils.py @@ -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. diff --git a/setup.py b/setup.py index 3a7e1c8..565adad 100644 --- a/setup.py +++ b/setup.py @@ -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. @@ -30,9 +30,9 @@ install_requirements = [ test_requirements = [ 'pytest', - 'django', + 'tox', + 'django>=1.10', 'django-fake-database-backends', - 'flake8' ] setup( @@ -62,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', diff --git a/tests/fixtures.py b/tests/fixtures.py index 0bd647b..2502885 100644 --- a/tests/fixtures.py +++ b/tests/fixtures.py @@ -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. diff --git a/tests/functional/test_cmd_line_call.py b/tests/functional/test_cmd_line_call.py index f4c5b95..bc34b15 100644 --- a/tests/functional/test_cmd_line_call.py +++ b/tests/functional/test_cmd_line_call.py @@ -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) diff --git a/tests/functional/test_migration_linter.py b/tests/functional/test_migration_linter.py index 2c78c12..17f6afc 100644 --- a/tests/functional/test_migration_linter.py +++ b/tests/functional/test_migration_linter.py @@ -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. diff --git a/tests/functional/test_multiple_calls.py b/tests/functional/test_multiple_calls.py index d467d19..bea9262 100644 --- a/tests/functional/test_multiple_calls.py +++ b/tests/functional/test_multiple_calls.py @@ -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. diff --git a/tests/unit/test_linter.py b/tests/unit/test_linter.py index b658d93..0a4e47e 100644 --- a/tests/unit/test_linter.py +++ b/tests/unit/test_linter.py @@ -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. diff --git a/tests/unit/test_utils.py b/tests/unit/test_utils.py index fd6d5d0..88d20af 100644 --- a/tests/unit/test_utils.py +++ b/tests/unit/test_utils.py @@ -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. diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000..ac72378 --- /dev/null +++ b/tox.ini @@ -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