Skip to content

Commit

Permalink
Move builds to GitHub actions
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelgrinberg committed Nov 21, 2020
1 parent 4887bd5 commit c4a5151
Show file tree
Hide file tree
Showing 12 changed files with 118 additions and 34 deletions.
40 changes: 40 additions & 0 deletions .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
9 changes: 0 additions & 9 deletions .travis.yml

This file was deleted.

2 changes: 1 addition & 1 deletion 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.

Expand Down
19 changes: 12 additions & 7 deletions flask_migrate/__init__.py
Expand Up @@ -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)
Expand Down Expand Up @@ -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)

Expand Down
8 changes: 6 additions & 2 deletions flask_migrate/cli.py
Expand Up @@ -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."""
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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."""
Expand Down
3 changes: 1 addition & 2 deletions flask_migrate/templates/flask-multidb/env.py
Expand Up @@ -2,7 +2,6 @@

import logging
from logging.config import fileConfig
import re

from sqlalchemy import engine_from_config
from sqlalchemy import MetaData
Expand Down Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion tests/__init__.py
@@ -1 +0,0 @@

1 change: 1 addition & 0 deletions tests/app_compare_type1.py
Expand Up @@ -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()
1 change: 1 addition & 0 deletions tests/app_compare_type2.py
Expand Up @@ -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()
32 changes: 21 additions & 11 deletions tests/test_migrate.py
Expand Up @@ -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()
Expand Down Expand Up @@ -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)
3 changes: 2 additions & 1 deletion tests/test_multidb_migrate.py
Expand Up @@ -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)
Expand Down
33 changes: 33 additions & 0 deletions 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

0 comments on commit c4a5151

Please sign in to comment.