From ed897ffb97694639b39a95823da1a0092f5dddcb Mon Sep 17 00:00:00 2001 From: secwall Date: Sun, 14 Apr 2019 20:55:33 +0300 Subject: [PATCH] Bump deps versions --- Dockerfile | 2 +- features/steps/callbacks.py | 13 ++-- features/steps/run_pgmigrate.py | 23 +++++-- pgmigrate.py | 118 +++++++++++++++----------------- run_test.sh | 4 +- setup.py | 30 ++++---- tox.ini | 4 +- 7 files changed, 100 insertions(+), 94 deletions(-) diff --git a/Dockerfile b/Dockerfile index a70b754..e4d3c6a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,7 +13,7 @@ ENV DEBIAN_FRONTEND noninteractive RUN apt-key adv --keyserver ha.pool.sks-keyservers.net --recv-keys B97B0AFCAA1A47F044F244A07FCC7D46ACCC4CF8 -ENV PG_MAJOR 10 +ENV PG_MAJOR 11 RUN echo 'deb http://apt.postgresql.org/pub/repos/apt/ bionic-pgdg main' $PG_MAJOR > /etc/apt/sources.list.d/pgdg.list diff --git a/features/steps/callbacks.py b/features/steps/callbacks.py index c140bb1..83becbf 100644 --- a/features/steps/callbacks.py +++ b/features/steps/callbacks.py @@ -40,18 +40,19 @@ def step_impl(context): @given('successful pgmigrate run with our callbacks and "{args}"') # noqa def step_impl(context, args): cbs = ','.join(context.callbacks) - context.execute_steps('given successful pgmigrate run with ' + - '"%s"' % ('-a ' + cbs + ' ' + args,)) + context.execute_steps('given successful pgmigrate run with ' + '"%s"' % + ('-a ' + cbs + ' ' + args, )) @when('we run pgmigrate with our callbacks and "{args}"') # noqa def step_impl(context, args): cbs = ','.join(context.callbacks) - context.execute_steps('when we run pgmigrate with ' + - '"%s"' % ('-a ' + cbs + ' ' + args,)) + context.execute_steps('when we run pgmigrate with ' + '"%s"' % + ('-a ' + cbs + ' ' + args, )) -@when('we run pgmigrate with dir callbacks and type "{cb_type}" and "{args}"') # noqa +@when('we run pgmigrate with dir callbacks and type "{cb_type}" and "{args}"' + ) # noqa def step_impl(context, cb_type, args): p_args = '-a ' + cb_type + ':' + context.migr_dir + '/callbacks/ ' + args - context.execute_steps('when we run pgmigrate with "%s"' % (p_args,)) + context.execute_steps('when we run pgmigrate with "%s"' % (p_args, )) diff --git a/features/steps/run_pgmigrate.py b/features/steps/run_pgmigrate.py index fae0897..d2d8e15 100644 --- a/features/steps/run_pgmigrate.py +++ b/features/steps/run_pgmigrate.py @@ -9,12 +9,12 @@ from behave import given, then, when def run_pgmigrate(migr_dir, args): - cmd = ['coverage', 'run', '-p', '--include=pgmigrate.py', - './pgmigrate.py', '-vvv', '-d', migr_dir, - '-c', 'dbname=pgmigratetest'] + str(args).split(' ') + cmd = [ + 'coverage', 'run', '-p', '--include=pgmigrate.py', './pgmigrate.py', + '-vvv', '-d', migr_dir, '-c', 'dbname=pgmigratetest' + ] + str(args).split(' ') - p = subprocess.Popen(cmd, stdout=subprocess.PIPE, - stderr=subprocess.PIPE) + p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) try: stdout, stderr = func_timeout(5, p.communicate) @@ -23,11 +23,16 @@ def run_pgmigrate(migr_dir, args): stdout, stderr = p.communicate() return p.returncode, str(stdout), str(stderr) + @given('successful pgmigrate run with "{args}"') def step_impl(context, args): if context.migrate_config: with open(os.path.join(context.migr_dir, 'migrations.yml'), 'w') as f: - f.write(yaml.dump(context.migrate_config)) + yaml.safe_dump(context.migrate_config, + f, + encoding=None, + default_flow_style=False, + allow_unicode=True) res = run_pgmigrate(context.migr_dir, args) if res[0] != 0: @@ -40,7 +45,11 @@ def step_impl(context, args): def step_impl(context, args): if context.migrate_config: with open(os.path.join(context.migr_dir, 'migrations.yml'), 'w') as f: - f.write(yaml.dump(context.migrate_config)) + yaml.safe_dump(context.migrate_config, + f, + encoding=None, + default_flow_style=False, + allow_unicode=True) res = run_pgmigrate(context.migr_dir, args) context.last_migrate_res = {'ret': res[0], 'out': res[1], 'err': res[2]} diff --git a/pgmigrate.py b/pgmigrate.py index 9cb3fc0..11a8ddb 100755 --- a/pgmigrate.py +++ b/pgmigrate.py @@ -50,42 +50,36 @@ class MigrateError(RuntimeError): """ Common migration error class """ - pass class MalformedStatement(MigrateError): """ Incorrect statement exception """ - pass class MalformedMigration(MigrateError): """ Incorrect migration exception """ - pass class MalformedSchema(MigrateError): """ Incorrect schema exception """ - pass class ConfigurationError(MigrateError): """ Incorrect config or cmd args exception """ - pass class BaselineError(MigrateError): """ Baseline error class """ - pass class ConflictTerminator(threading.Thread): @@ -703,20 +697,19 @@ COMMANDS = { 'migrate': migrate, } -CONFIG_DEFAULTS = Config( - target=None, - baseline=0, - cursor=None, - dryrun=False, - callbacks='', - base_dir='', - user=None, - session=['SET lock_timeout = 0'], - conn='dbname=postgres user=postgres ' - 'connect_timeout=1', - conn_instance=None, - terminator_instance=None, - termination_interval=None) +CONFIG_DEFAULTS = Config(target=None, + baseline=0, + cursor=None, + dryrun=False, + callbacks='', + base_dir='', + user=None, + session=['SET lock_timeout = 0'], + conn='dbname=postgres user=postgres ' + 'connect_timeout=1', + conn_instance=None, + terminator_instance=None, + termination_interval=None) def get_config(base_dir, args=None): @@ -726,7 +719,7 @@ def get_config(base_dir, args=None): path = os.path.join(base_dir, 'migrations.yml') try: with codecs.open(path, encoding='utf-8') as i: - base = yaml.load(i.read()) + base = yaml.safe_load(i) except IOError: LOG.info('Unable to load %s. Using defaults', path) base = {} @@ -746,9 +739,8 @@ def get_config(base_dir, args=None): conf = conf._replace(target=int(conf.target)) if conf.termination_interval and not conf.dryrun: - conf = conf._replace( - terminator_instance=ConflictTerminator(conf.conn, - conf.termination_interval)) + conf = conf._replace(terminator_instance=ConflictTerminator( + conf.conn, conf.termination_interval)) conf.terminator_instance.start() conf = conf._replace(conn_instance=_create_connection(conf)) @@ -770,47 +762,51 @@ def _main(): """ parser = argparse.ArgumentParser() - parser.add_argument( - 'cmd', choices=COMMANDS.keys(), type=str, help='Operation') + parser.add_argument('cmd', + choices=COMMANDS.keys(), + type=str, + help='Operation') parser.add_argument('-t', '--target', type=str, help='Target version') - parser.add_argument( - '-c', '--conn', type=str, help='Postgresql connection string') - parser.add_argument( - '-d', '--base_dir', type=str, default='', help='Migrations base dir') - parser.add_argument( - '-u', - '--user', - type=str, - help='Override database user in migration info') + parser.add_argument('-c', + '--conn', + type=str, + help='Postgresql connection string') + parser.add_argument('-d', + '--base_dir', + type=str, + default='', + help='Migrations base dir') + parser.add_argument('-u', + '--user', + type=str, + help='Override database user in migration info') parser.add_argument('-b', '--baseline', type=int, help='Baseline version') - parser.add_argument( - '-a', - '--callbacks', - type=str, - help='Comma-separated list of callbacks ' - '(type:dir/file)') - parser.add_argument( - '-s', - '--session', - action='append', - help='Session setup (e.g. isolation level)') - parser.add_argument( - '-n', - '--dryrun', - action='store_true', - help='Say "rollback" in the end instead of "commit"') - parser.add_argument( - '-l', - '--termination_interval', - type=float, - help='Inverval for terminating blocking pids') - parser.add_argument( - '-v', '--verbose', default=0, action='count', help='Be verbose') + parser.add_argument('-a', + '--callbacks', + type=str, + help='Comma-separated list of callbacks ' + '(type:dir/file)') + parser.add_argument('-s', + '--session', + action='append', + help='Session setup (e.g. isolation level)') + parser.add_argument('-n', + '--dryrun', + action='store_true', + help='Say "rollback" in the end instead of "commit"') + parser.add_argument('-l', + '--termination_interval', + type=float, + help='Inverval for terminating blocking pids') + parser.add_argument('-v', + '--verbose', + default=0, + action='count', + help='Be verbose') args = parser.parse_args() - logging.basicConfig( - level=(logging.ERROR - 10 * (min(3, args.verbose))), - format='%(asctime)s %(levelname)-8s: %(message)s') + logging.basicConfig(level=(logging.ERROR - 10 * (min(3, args.verbose))), + format='%(asctime)s %(levelname)-8s: %(message)s') config = get_config(args.base_dir, args) diff --git a/run_test.sh b/run_test.sh index ab14326..fd4c893 100755 --- a/run_test.sh +++ b/run_test.sh @@ -5,6 +5,8 @@ set -e chown -R postgres:postgres /dist mkdir -p /var/log/pogsgresql chown postgres:postgres /var/log/pogsgresql -sudo -u postgres /usr/lib/postgresql/${PG_MAJOR}/bin/pg_ctl -D /etc/postgresql/10/main -l /var/log/pogsgresql/postgresql-${PG_MAJOR}-main.log start +sudo -u postgres /usr/lib/postgresql/${PG_MAJOR}/bin/pg_ctl -D \ + /etc/postgresql/${PG_MAJOR}/main -l \ + /var/log/pogsgresql/postgresql-${PG_MAJOR}-main.log start cd /dist sudo -u postgres -i tox -c /dist/tox.ini diff --git a/setup.py b/setup.py index 8aea8c2..9ed21ee 100644 --- a/setup.py +++ b/setup.py @@ -30,32 +30,30 @@ try: except ImportError: from distutils import setup - REQUIREMENTS = [ - 'sqlparse >= 0.2.1', - 'psycopg2 >= 2.6.2', - 'PyYAML >= 3.12' - ] + 'sqlparse >= 0.3.0', + 'psycopg2 >= 2.8.2', + 'PyYAML >= 5.1', +] if sys.version_info < (3, 0): - REQUIREMENTS.append('future >= 0.15.2') + REQUIREMENTS.append('future >= 0.17.1') setup( - name="yandex-pgmigrate", - version="1.0.3", - description="PostgreSQL migrations made easy", - license="PostgreSQL License", - url="https://github.com/yandex/pgmigrate/", + name='yandex-pgmigrate', + version='1.0.3', + description='PostgreSQL migrations made easy', + license='PostgreSQL License', + url='https://github.com/yandex/pgmigrate/', author='Yandex LLC', author_email='opensource@yandex-team.ru', maintainer='Yandex LLC', maintainer_email='opensource@yandex-team.ru', zip_safe=False, - platforms=["Linux", "BSD", "MacOS"], + platforms=['Linux', 'BSD', 'MacOS'], packages=['.'], - entry_points={ - 'console_scripts': [ - 'pgmigrate = pgmigrate:_main', - ]}, + entry_points={'console_scripts': [ + 'pgmigrate = pgmigrate:_main', + ]}, install_requires=REQUIREMENTS, ) diff --git a/tox.ini b/tox.ini index ad1e9d6..00ae253 100644 --- a/tox.ini +++ b/tox.ini @@ -48,9 +48,9 @@ deps = pylint [testenv:yapf] commands = yapf -pd pgmigrate.py -deps = yapf==0.22.0 +deps = yapf==0.27.0 [flake8] copyright-check = True -copyright-regexp = Copyright\s+(\(C\)\s+)?(\d{4}-)?2016-2018\s+%(author)s +copyright-regexp = Copyright\s+(\(C\)\s+)?(\d{4}-)?2016-2019\s+%(author)s copyright-author = Yandex LLC