python: Reformat with Black, except quotes.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg
2021-02-11 23:19:30 -08:00
committed by Tim Abbott
parent 5028c081cb
commit 11741543da
817 changed files with 44952 additions and 24860 deletions

View File

@@ -17,28 +17,31 @@ def validate_order(order: List[int], length: int) -> None:
print("Incorrect input")
sys.exit(1)
def renumber_migration(conflicts: List[str], order: List[int], last_correct_migration: str) -> None:
stack: List[str] = []
for i in order:
if conflicts[i-1][0:4] not in stack:
stack.append(conflicts[i-1][0:4])
if conflicts[i - 1][0:4] not in stack:
stack.append(conflicts[i - 1][0:4])
else:
# Replace dependencies with the last correct migration
file = fileinput.FileInput('zerver/migrations/' + conflicts[i-1], inplace=True)
file = fileinput.FileInput('zerver/migrations/' + conflicts[i - 1], inplace=True)
for line in file:
print(re.sub(r'[\d]+(_[a-z0-9]+)+', last_correct_migration, line), end='')
# Rename the migration indexing at the end
new_name = conflicts[i-1].replace(conflicts[i-1][0:4],
f'{int(last_correct_migration[0:4]) + 1:04}')
os.rename('zerver/migrations/' + conflicts[i-1], 'zerver/migrations/' + new_name)
new_name = conflicts[i - 1].replace(
conflicts[i - 1][0:4], f'{int(last_correct_migration[0:4]) + 1:04}'
)
os.rename('zerver/migrations/' + conflicts[i - 1], 'zerver/migrations/' + new_name)
last_correct_migration = new_name.replace('.py', '')
def resolve_conflicts(conflicts: List[str], files_list: List[str]) -> None:
print("Conflicting migrations:")
for i in range(0, len(conflicts)):
print(str(i+1) + '. ' + conflicts[i])
print(str(i + 1) + '. ' + conflicts[i])
order_input = input("Enter the order in which these migrations should be arranged: ")
order = list(map(int, order_input.split()))
@@ -49,6 +52,7 @@ def resolve_conflicts(conflicts: List[str], files_list: List[str]) -> None:
last_correct_migration = last_correct_migration.replace('.py', '')
renumber_migration(conflicts, order, last_correct_migration)
if __name__ == '__main__':
MIGRATIONS_TO_SKIP = {'0209', '0261'}
@@ -69,7 +73,11 @@ if __name__ == '__main__':
# migrations graph structure, not the IDs, is what
# matters).
if migration_number not in MIGRATIONS_TO_SKIP:
conflicts += [file_name for file_name in files_list if file_name.startswith(migration_number)]
conflicts += [
file_name
for file_name in files_list
if file_name.startswith(migration_number)
]
stack.append(migration_number)
if len(conflicts) > 0: