diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000..f739f59 --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,40 @@ +name: build +on: + push: + branches: + - master + pull_request: + branches: + - master +jobs: + lint: + name: lint + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-python@v2 + - run: python -m pip install --upgrade pip wheel + - run: pip install tox tox-gh-actions + - run: tox -eflake8 + - run: tox -edocs + tests: + name: tests + strategy: + matrix: + # TODO: add windows-latest + os: [ubuntu-latest, macos-latest] + python: ['3.6', '3.7', '3.8', '3.9', 'pypy3'] + exclude: + # pypy3 currently fails to run on Windows + - os: windows-latest + python: pypy3 + fail-fast: false + runs-on: ${{ matrix.os }} + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python }} + - run: python -m pip install --upgrade pip wheel + - run: pip install tox tox-gh-actions + - run: tox diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 291452d..0000000 --- a/.travis.yml +++ /dev/null @@ -1,9 +0,0 @@ -dist: xenial -language: python -python: - - 3.6 - - 3.7 - - 3.8 - - pypy3 -install: python setup.py install -script: python setup.py test diff --git a/README.md b/README.md index f93e7c8..0a0ae0c 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ Flask-Migrate ============= -[![Build Status](https://travis-ci.org/miguelgrinberg/Flask-Migrate.png?branch=master)](https://travis-ci.org/miguelgrinberg/Flask-Migrate) +[![Build status](https://github.com/miguelgrinberg/flask-migrate/workflows/build/badge.svg)](https://github.com/miguelgrinberg/flask-migrate/actions) Flask-Migrate is an extension that handles SQLAlchemy database migrations for Flask applications using Alembic. The database operations are provided as command-line arguments under the `flask db` command. diff --git a/flask_migrate/__init__.py b/flask_migrate/__init__.py index ccdd76f..d0c260b 100755 --- a/flask_migrate/__init__.py +++ b/flask_migrate/__init__.py @@ -54,8 +54,8 @@ def init_app(self, app, db=None, directory=None, **kwargs): self.alembic_ctx_kwargs.update(kwargs) if not hasattr(app, 'extensions'): app.extensions = {} - app.extensions['migrate'] = _MigrateConfig(self, self.db, - **self.alembic_ctx_kwargs) + app.extensions['migrate'] = _MigrateConfig( + self, self.db, **self.alembic_ctx_kwargs) def configure(self, f): self.configure_callbacks.append(f) @@ -307,21 +307,26 @@ def show(directory=None, revision='head'): command.show(config, revision) -@MigrateCommand.option('-i', '--indicate-current', dest='indicate_current', action='store_true', - default=False, help='Indicate current version (Alembic 0.9.9 or greater is required)') +@MigrateCommand.option('-i', '--indicate-current', dest='indicate_current', + action='store_true', default=False, + help=('Indicate current version (Alembic 0.9.9 or ' + 'greater is required)')) @MigrateCommand.option('-v', '--verbose', dest='verbose', action='store_true', default=False, help='Use more verbose output') @MigrateCommand.option('-r', '--rev-range', dest='rev_range', default=None, - help='Specify a revision range; format is [start]:[end]') + help=('Specify a revision range; format is ' + '[start]:[end]')) @MigrateCommand.option('-d', '--directory', dest='directory', default=None, help=("Migration script directory (default is " "'migrations')")) @catch_errors -def history(directory=None, rev_range=None, verbose=False, indicate_current=False): +def history(directory=None, rev_range=None, verbose=False, + indicate_current=False): """List changeset scripts in chronological order.""" config = current_app.extensions['migrate'].migrate.get_config(directory) if alembic_version >= (0, 9, 9): - command.history(config, rev_range, verbose=verbose, indicate_current=indicate_current) + command.history(config, rev_range, verbose=verbose, + indicate_current=indicate_current) else: command.history(config, rev_range, verbose=verbose) diff --git a/flask_migrate/cli.py b/flask_migrate/cli.py index 21c1720..9b3c851 100644 --- a/flask_migrate/cli.py +++ b/flask_migrate/cli.py @@ -14,6 +14,7 @@ from flask_migrate import current as _current from flask_migrate import stamp as _stamp + @click.group() def db(): """Perform database migrations.""" @@ -85,7 +86,8 @@ def revision(directory, message, autogenerate, sql, head, splice, branch_label, @with_appcontext def migrate(directory, message, sql, head, splice, branch_label, version_path, rev_id, x_arg): - """Autogenerate a new revision file (Alias for 'revision --autogenerate')""" + """Autogenerate a new revision file (Alias for + 'revision --autogenerate')""" _migrate(directory, message, sql, head, splice, branch_label, version_path, rev_id, x_arg) @@ -168,7 +170,9 @@ def show(directory, revision): @click.option('-r', '--rev-range', default=None, help='Specify a revision range; format is [start]:[end]') @click.option('-v', '--verbose', is_flag=True, help='Use more verbose output') -@click.option('-i', '--indicate-current', is_flag=True, help='Indicate current version (Alembic 0.9.9 or greater is required)') +@click.option('-i', '--indicate-current', is_flag=True, + help=('Indicate current version (Alembic 0.9.9 or greater is ' + 'required)')) @with_appcontext def history(directory, rev_range, verbose, indicate_current): """List changeset scripts in chronological order.""" diff --git a/flask_migrate/templates/flask-multidb/env.py b/flask_migrate/templates/flask-multidb/env.py index c041738..79a2cfb 100644 --- a/flask_migrate/templates/flask-multidb/env.py +++ b/flask_migrate/templates/flask-multidb/env.py @@ -2,7 +2,6 @@ import logging from logging.config import fileConfig -import re from sqlalchemy import engine_from_config from sqlalchemy import MetaData @@ -164,7 +163,7 @@ def process_revision_directives(context, revision, directives): for rec in engines.values(): rec['transaction'].commit() - except: + except: # noqa: E722 for rec in engines.values(): rec['transaction'].rollback() raise diff --git a/tests/__init__.py b/tests/__init__.py index 8b13789..e69de29 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -1 +0,0 @@ - diff --git a/tests/app_compare_type1.py b/tests/app_compare_type1.py index f15b86a..2cd963f 100755 --- a/tests/app_compare_type1.py +++ b/tests/app_compare_type1.py @@ -18,5 +18,6 @@ class User(db.Model): id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(128)) + if __name__ == '__main__': manager.run() diff --git a/tests/app_compare_type2.py b/tests/app_compare_type2.py index 62e0bbd..4dd2d0c 100755 --- a/tests/app_compare_type2.py +++ b/tests/app_compare_type2.py @@ -18,5 +18,6 @@ class User(db.Model): id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(10)) + if __name__ == '__main__': manager.run() diff --git a/tests/test_migrate.py b/tests/test_migrate.py index 3d1210e..74721c8 100644 --- a/tests/test_migrate.py +++ b/tests/test_migrate.py @@ -8,10 +8,10 @@ def run_cmd(cmd): """Run a command and return a tuple with (stdout, stderr, exit_code)""" + print('\n$ ' + cmd) process = subprocess.Popen(shlex.split(cmd), stdout=subprocess.PIPE, stderr=subprocess.PIPE) (stdout, stderr) = process.communicate() - print('\n$ ' + cmd) print(stdout.decode('utf-8')) print(stderr.decode('utf-8')) return stdout, stderr, process.wait() @@ -64,33 +64,43 @@ def test_migrate_upgrade(self): self.assertTrue(s == 0) def test_custom_directory(self): - (o, e, s) = run_cmd(sys.executable + ' app_custom_directory.py db init') + (o, e, s) = run_cmd( + sys.executable + ' app_custom_directory.py db init') self.assertTrue(s == 0) - (o, e, s) = run_cmd(sys.executable + ' app_custom_directory.py db migrate') + (o, e, s) = run_cmd( + sys.executable + ' app_custom_directory.py db migrate') self.assertTrue(s == 0) - (o, e, s) = run_cmd(sys.executable + ' app_custom_directory.py db upgrade') + (o, e, s) = run_cmd( + sys.executable + ' app_custom_directory.py db upgrade') self.assertTrue(s == 0) (o, e, s) = run_cmd(sys.executable + ' app_custom_directory.py add') self.assertTrue(s == 0) def test_custom_directory_path(self): - (o, e, s) = run_cmd(sys.executable + ' app_custom_directory_path.py db init') + (o, e, s) = run_cmd( + sys.executable + ' app_custom_directory_path.py db init') self.assertTrue(s == 0) - (o, e, s) = run_cmd(sys.executable + ' app_custom_directory_path.py db migrate') + (o, e, s) = run_cmd( + sys.executable + ' app_custom_directory_path.py db migrate') self.assertTrue(s == 0) - (o, e, s) = run_cmd(sys.executable + ' app_custom_directory_path.py db upgrade') + (o, e, s) = run_cmd( + sys.executable + ' app_custom_directory_path.py db upgrade') self.assertTrue(s == 0) - (o, e, s) = run_cmd(sys.executable + ' app_custom_directory_path.py add') + (o, e, s) = run_cmd( + sys.executable + ' app_custom_directory_path.py add') self.assertTrue(s == 0) def test_compare_type(self): (o, e, s) = run_cmd(sys.executable + ' app_compare_type1.py db init') self.assertTrue(s == 0) - (o, e, s) = run_cmd(sys.executable + ' app_compare_type1.py db migrate') + (o, e, s) = run_cmd( + sys.executable + ' app_compare_type1.py db migrate') self.assertTrue(s == 0) - (o, e, s) = run_cmd(sys.executable + ' app_compare_type1.py db upgrade') + (o, e, s) = run_cmd( + sys.executable + ' app_compare_type1.py db upgrade') self.assertTrue(s == 0) - (o, e, s) = run_cmd(sys.executable + ' app_compare_type2.py db migrate') + (o, e, s) = run_cmd( + sys.executable + ' app_compare_type2.py db migrate') self.assertTrue(s == 0) self.assertTrue(b'Detected type change from VARCHAR(length=128) ' b'to String(length=10)' in e) diff --git a/tests/test_multidb_migrate.py b/tests/test_multidb_migrate.py index 45aeca8..b026ab3 100644 --- a/tests/test_multidb_migrate.py +++ b/tests/test_multidb_migrate.py @@ -40,7 +40,8 @@ def tearDown(self): pass def test_multidb_migrate_upgrade(self): - (o, e, s) = run_cmd(sys.executable + ' app_multidb.py db init --multidb') + (o, e, s) = run_cmd( + sys.executable + ' app_multidb.py db init --multidb') self.assertTrue(s == 0) (o, e, s) = run_cmd(sys.executable + ' app_multidb.py db migrate') self.assertTrue(s == 0) diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000..ecb2759 --- /dev/null +++ b/tox.ini @@ -0,0 +1,33 @@ +[tox] +envlist=flake8,py36,py37,py38,py39,pypy3,docs +skip_missing_interpreters=True + +[gh-actions] +python = + 3.6: py36 + 3.7: py37 + 3.8: py38 + 3.9: py39 + pypy3: pypy3 + +[testenv] +deps= + flask-script +commands= + python setup.py test + +[testenv:flake8] +deps= + six + flake8 +commands= + flake8 --exclude=".*" flask_migrate tests + +[testenv:docs] +changedir=docs +deps= + sphinx +whitelist_externals= + make +commands= + make html