Adapt code to python3.4 and add it to travis
Added to travis explicitly python 2.7, 3.4, 3.5, 3.6
This commit is contained in:
1 parent
7143baedc7
commit
174bb19319
4 files changed
+25
-11
No files matched your search
@@ -1,4 +1,9 @@
|
|||||||
language: python
|
language: python
|
||||||
|
python:
|
||||||
|
- "2.7"
|
||||||
|
- "3.4"
|
||||||
|
- "3.5"
|
||||||
|
- "3.6"
|
||||||
script:
|
script:
|
||||||
- py.test
|
- py.test
|
||||||
install:
|
install:
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
from migration_linter import * # noqa
|
from .migration_linter import * # noqa
|
||||||
@@ -35,6 +35,10 @@ def has_default(sql, **kwargs):
|
|||||||
return False # Never fails
|
return False # Never fails
|
||||||
|
|
||||||
|
|
||||||
|
def clean_bytes_to_str(byte_input):
|
||||||
|
return byte_input.decode('utf-8').strip()
|
||||||
|
|
||||||
|
|
||||||
class MigrationLinter:
|
class MigrationLinter:
|
||||||
MIGRATION_FOLDER_NAME = 'migrations'
|
MIGRATION_FOLDER_NAME = 'migrations'
|
||||||
|
|
||||||
@@ -83,8 +87,8 @@ class MigrationLinter:
|
|||||||
git_init_cmd = 'cd {0} && git rev-list HEAD | tail -n 1'.format(
|
git_init_cmd = 'cd {0} && git rev-list HEAD | tail -n 1'.format(
|
||||||
self.location)
|
self.location)
|
||||||
process = Popen(git_init_cmd, shell=True, stdout=PIPE, stderr=PIPE)
|
process = Popen(git_init_cmd, shell=True, stdout=PIPE, stderr=PIPE)
|
||||||
for line in process.stdout.readlines():
|
for line in map(clean_bytes_to_str, process.stdout.readlines()):
|
||||||
self.commit_id = line.strip()
|
self.commit_id = line
|
||||||
break
|
break
|
||||||
process.wait()
|
process.wait()
|
||||||
log.info('Operating until git identifier {0}'.format(self.commit_id))
|
log.info('Operating until git identifier {0}'.format(self.commit_id))
|
||||||
@@ -95,17 +99,17 @@ class MigrationLinter:
|
|||||||
log.info('Executing {0}'.format(git_diff_command))
|
log.info('Executing {0}'.format(git_diff_command))
|
||||||
diff_process = Popen(
|
diff_process = Popen(
|
||||||
git_diff_command, shell=True, stdout=PIPE, stderr=PIPE)
|
git_diff_command, shell=True, stdout=PIPE, stderr=PIPE)
|
||||||
for line in diff_process.stdout.readlines():
|
for line in map(clean_bytes_to_str, diff_process.stdout.readlines()):
|
||||||
# Only gather lines that include migrations
|
# Only gather lines that include migrations
|
||||||
if re.search(
|
if re.search(
|
||||||
'\/{0}\/.*\.py'.format(self.MIGRATION_FOLDER_NAME),
|
'\/{0}\/.*\.py'.format(self.MIGRATION_FOLDER_NAME),
|
||||||
line) and \
|
line) and \
|
||||||
'__init__' not in line:
|
'__init__' not in line:
|
||||||
self.changed_migration_files.append(line.strip())
|
self.changed_migration_files.append(line)
|
||||||
diff_process.wait()
|
diff_process.wait()
|
||||||
if diff_process.returncode != 0:
|
if diff_process.returncode != 0:
|
||||||
output = []
|
output = []
|
||||||
for line in diff_process.stderr.readlines():
|
for line in map(clean_bytes_to_str, diff_process.stderr.readlines()):
|
||||||
output.append(line)
|
output.append(line)
|
||||||
log.info("Error while git diff command:\n{}".format(
|
log.info("Error while git diff command:\n{}".format(
|
||||||
"".join(output)))
|
"".join(output)))
|
||||||
@@ -180,14 +184,14 @@ class MigrationLinter:
|
|||||||
'--database {3}').format(
|
'--database {3}').format(
|
||||||
self.location, app_name, migration_name, self.database)
|
self.location, app_name, migration_name, self.database)
|
||||||
log.info('Executing {0}'.format(git_diff_command))
|
log.info('Executing {0}'.format(git_diff_command))
|
||||||
diff_process = Popen(
|
sqlmigrate_process = Popen(
|
||||||
git_diff_command, shell=True, stdout=PIPE, stderr=PIPE)
|
git_diff_command, shell=True, stdout=PIPE, stderr=PIPE)
|
||||||
sql_statements = []
|
sql_statements = []
|
||||||
for line in diff_process.stdout.readlines():
|
for line in map(clean_bytes_to_str, sqlmigrate_process.stdout.readlines()):
|
||||||
if not line.startswith('--'): # Ignore comments
|
if not line.startswith('--'): # Ignore comments
|
||||||
sql_statements.append(line.strip())
|
sql_statements.append(line)
|
||||||
diff_process.wait()
|
sqlmigrate_process.wait()
|
||||||
if diff_process.returncode != 0:
|
if sqlmigrate_process.returncode != 0:
|
||||||
raise RuntimeError('sqlmigrate command failed')
|
raise RuntimeError('sqlmigrate command failed')
|
||||||
log.info('Found {0} sql migration lines'.format(len(sql_statements)))
|
log.info('Found {0} sql migration lines'.format(len(sql_statements)))
|
||||||
return sql_statements
|
return sql_statements
|
||||||
|
|||||||
@@ -59,7 +59,12 @@ setup(
|
|||||||
'Environment :: Web Environment',
|
'Environment :: Web Environment',
|
||||||
'Framework :: Django',
|
'Framework :: Django',
|
||||||
|
|
||||||
|
'Programming Language :: Python',
|
||||||
'Programming Language :: Python :: 2',
|
'Programming Language :: Python :: 2',
|
||||||
'Programming Language :: Python :: 2.7',
|
'Programming Language :: Python :: 2.7',
|
||||||
|
'Programming Language :: Python :: 3',
|
||||||
|
'Programming Language :: Python :: 3.4',
|
||||||
|
'Programming Language :: Python :: 3.5',
|
||||||
|
'Programming Language :: Python :: 3.6',
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
Reference in new issue
Block a user