prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  Add "radon" tool to the Backend and enable it in CI
  ## Expected Behavior
  
  Python code in backend should be validated by "radon" tool in CI.
  
  ## Actual Behavior
  
  MedTagger backend uses a few linters already but we should add more validators to increate automation and code quality.
  
  </issue>
  <code>
  [start of backend/scripts/migrate_hbase.py]
  1 """Script that can migrate existing HBase schema or prepare empty database with given schema.
  2 
  3 How to use it?
  4 --------------
  5 Run this script just by executing following line in the root directory of this project:
  6 
  7     (venv) $ python3.6 scripts/migrate_hbase.py
  8 
  9 """
  10 import argparse
  11 import logging
  12 import logging.config
  13 
  14 from medtagger.clients.hbase_client import HBaseClient
  15 from utils import get_connection_to_hbase, user_agrees
  16 
  17 logging.config.fileConfig('logging.conf')
  18 logger = logging.getLogger(__name__)
  19 
  20 parser = argparse.ArgumentParser(description='HBase migration.')
  21 parser.add_argument('-y', '--yes', dest='yes', action='store_const', const=True)
  22 args = parser.parse_args()
  23 
  24 
  25 HBASE_SCHEMA = HBaseClient.HBASE_SCHEMA
  26 connection = get_connection_to_hbase()
  27 existing_tables = set(connection.tables())
  28 schema_tables = set(HBASE_SCHEMA)
  29 tables_to_drop = list(existing_tables - schema_tables)
  30 for table_name in tables_to_drop:
  31     if args.yes or user_agrees('Do you want to drop table "{}"?'.format(table_name)):
  32         logger.info('Dropping table "%s".', table_name)
  33         table = connection.table(table_name)
  34         table.drop()
  35 
  36 for table_name in HBASE_SCHEMA:
  37     table = connection.table(table_name)
  38     if not table.exists():
  39         if args.yes or user_agrees('Do you want to create table "{}"?'.format(table_name)):
  40             list_of_columns = HBASE_SCHEMA[table_name]
  41             logger.info('Creating table "%s" with columns %s.', table_name, list_of_columns)
  42             table.create(*list_of_columns)
  43             table.enable_if_exists_checks()
  44     else:
  45         existing_column_families = set(table.columns())
  46         schema_column_families = set(HBASE_SCHEMA[table_name])
  47         columns_to_add = list(schema_column_families - existing_column_families)
  48         columns_to_drop = list(existing_column_families - schema_column_families)
  49 
  50         if columns_to_add:
  51             if args.yes or user_agrees('Do you want to add columns {} to "{}"?'.format(columns_to_add, table_name)):
  52                 table.add_columns(*columns_to_add)
  53 
  54         if columns_to_drop:
  55             if args.yes or user_agrees('Do you want to drop columns {} from "{}"?'.format(columns_to_drop, table_name)):
  56                 table.drop_columns(*columns_to_drop)
  57
  [end of backend/scripts/migrate_hbase.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: diff --git a/backend/scripts/migrate_hbase.py b/backend/scripts/migrate_hbase.py
  --- a/backend/scripts/migrate_hbase.py
  +++ b/backend/scripts/migrate_hbase.py
  @@ -11,6 +11,8 @@
   import logging
   import logging.config
   
  +from starbase import Table
  +
   from medtagger.clients.hbase_client import HBaseClient
   from utils import get_connection_to_hbase, user_agrees
   
  @@ -22,35 +24,59 @@
   args = parser.parse_args()
   
   
  -HBASE_SCHEMA = HBaseClient.HBASE_SCHEMA
  -connection = get_connection_to_hbase()
  -existing_tables = set(connection.tables())
  -schema_tables = set(HBASE_SCHEMA)
  -tables_to_drop = list(existing_tables - schema_tables)
  -for table_name in tables_to_drop:
  +def create_new_table(table: Table) -> None:
  +    """Create new table once user agrees on that."""
  +    table_name = table.name
  +    if args.yes or user_agrees('Do you want to create table "{}"?'.format(table_name)):
  +        list_of_columns = HBaseClient.HBASE_SCHEMA[table_name]
  +        logger.info('Creating table "%s" with columns %s.', table_name, list_of_columns)
  +        table.create(*list_of_columns)
  +        table.enable_if_exists_checks()
  +
  +
  +def update_table_schema(table: Table) -> None:
  +    """Update table schema once user agrees on that."""
  +    table_name = table.name
  +    existing_column_families = set(table.columns())
  +    schema_column_families = set(HBaseClient.HBASE_SCHEMA[table_name])
  +    columns_to_add = list(schema_column_families - existing_column_families)
  +    columns_to_drop = list(existing_column_families - schema_column_families)
  +
  +    if columns_to_add:
  +        if args.yes or user_agrees('Do you want to add columns {} to "{}"?'.format(columns_to_add, table_name)):
  +            table.add_columns(*columns_to_add)
  +
  +    if columns_to_drop:
  +        if args.yes or user_agrees('Do you want to drop columns {} from "{}"?'.format(columns_to_drop, table_name)):
  +            table.drop_columns(*columns_to_drop)
  +
  +
  +def drop_table(table: Table) -> None:
  +    """Drop table once user agrees on that."""
  +    table_name = table.name
       if args.yes or user_agrees('Do you want to drop table "{}"?'.format(table_name)):
           logger.info('Dropping table "%s".', table_name)
  -        table = connection.table(table_name)
           table.drop()
   
  -for table_name in HBASE_SCHEMA:
  -    table = connection.table(table_name)
  -    if not table.exists():
  -        if args.yes or user_agrees('Do you want to create table "{}"?'.format(table_name)):
  -            list_of_columns = HBASE_SCHEMA[table_name]
  -            logger.info('Creating table "%s" with columns %s.', table_name, list_of_columns)
  -            table.create(*list_of_columns)
  -            table.enable_if_exists_checks()
  -    else:
  -        existing_column_families = set(table.columns())
  -        schema_column_families = set(HBASE_SCHEMA[table_name])
  -        columns_to_add = list(schema_column_families - existing_column_families)
  -        columns_to_drop = list(existing_column_families - schema_column_families)
  -
  -        if columns_to_add:
  -            if args.yes or user_agrees('Do you want to add columns {} to "{}"?'.format(columns_to_add, table_name)):
  -                table.add_columns(*columns_to_add)
  -
  -        if columns_to_drop:
  -            if args.yes or user_agrees('Do you want to drop columns {} from "{}"?'.format(columns_to_drop, table_name)):
  -                table.drop_columns(*columns_to_drop)
  +
  +def main() -> None:
  +    """Run main functionality of this script."""
  +    connection = get_connection_to_hbase()
  +    existing_tables = set(connection.tables())
  +    schema_tables = set(HBaseClient.HBASE_SCHEMA)
  +    tables_to_drop = list(existing_tables - schema_tables)
  +
  +    for table_name in tables_to_drop:
  +        table = connection.table(table_name)
  +        drop_table(table)
  +
  +    for table_name in HBaseClient.HBASE_SCHEMA:
  +        table = connection.table(table_name)
  +        if not table.exists():
  +            create_new_table(table)
  +        else:
  +            update_table_schema(table)
  +
  +
  +if __name__ == '__main__':
  +    main()
  
verification_info: {"golden_diff": "diff --git a/backend/scripts/migrate_hbase.py b/backend/scripts/migrate_hbase.py\n--- a/backend/scripts/migrate_hbase.py\n+++ b/backend/scripts/migrate_hbase.py\n@@ -11,6 +11,8 @@\n import logging\n import logging.config\n \n+from starbase import Table\n+\n from medtagger.clients.hbase_client import HBaseClient\n from utils import get_connection_to_hbase, user_agrees\n \n@@ -22,35 +24,59 @@\n args = parser.parse_args()\n \n \n-HBASE_SCHEMA = HBaseClient.HBASE_SCHEMA\n-connection = get_connection_to_hbase()\n-existing_tables = set(connection.tables())\n-schema_tables = set(HBASE_SCHEMA)\n-tables_to_drop = list(existing_tables - schema_tables)\n-for table_name in tables_to_drop:\n+def create_new_table(table: Table) -> None:\n+    \"\"\"Create new table once user agrees on that.\"\"\"\n+    table_name = table.name\n+    if args.yes or user_agrees('Do you want to create table \"{}\"?'.format(table_name)):\n+        list_of_columns = HBaseClient.HBASE_SCHEMA[table_name]\n+        logger.info('Creating table \"%s\" with columns %s.', table_name, list_of_columns)\n+        table.create(*list_of_columns)\n+        table.enable_if_exists_checks()\n+\n+\n+def update_table_schema(table: Table) -> None:\n+    \"\"\"Update table schema once user agrees on that.\"\"\"\n+    table_name = table.name\n+    existing_column_families = set(table.columns())\n+    schema_column_families = set(HBaseClient.HBASE_SCHEMA[table_name])\n+    columns_to_add = list(schema_column_families - existing_column_families)\n+    columns_to_drop = list(existing_column_families - schema_column_families)\n+\n+    if columns_to_add:\n+        if args.yes or user_agrees('Do you want to add columns {} to \"{}\"?'.format(columns_to_add, table_name)):\n+            table.add_columns(*columns_to_add)\n+\n+    if columns_to_drop:\n+        if args.yes or user_agrees('Do you want to drop columns {} from \"{}\"?'.format(columns_to_drop, table_name)):\n+            table.drop_columns(*columns_to_drop)\n+\n+\n+def drop_table(table: Table) -> None:\n+    \"\"\"Drop table once user agrees on that.\"\"\"\n+    table_name = table.name\n     if args.yes or user_agrees('Do you want to drop table \"{}\"?'.format(table_name)):\n         logger.info('Dropping table \"%s\".', table_name)\n-        table = connection.table(table_name)\n         table.drop()\n \n-for table_name in HBASE_SCHEMA:\n-    table = connection.table(table_name)\n-    if not table.exists():\n-        if args.yes or user_agrees('Do you want to create table \"{}\"?'.format(table_name)):\n-            list_of_columns = HBASE_SCHEMA[table_name]\n-            logger.info('Creating table \"%s\" with columns %s.', table_name, list_of_columns)\n-            table.create(*list_of_columns)\n-            table.enable_if_exists_checks()\n-    else:\n-        existing_column_families = set(table.columns())\n-        schema_column_families = set(HBASE_SCHEMA[table_name])\n-        columns_to_add = list(schema_column_families - existing_column_families)\n-        columns_to_drop = list(existing_column_families - schema_column_families)\n-\n-        if columns_to_add:\n-            if args.yes or user_agrees('Do you want to add columns {} to \"{}\"?'.format(columns_to_add, table_name)):\n-                table.add_columns(*columns_to_add)\n-\n-        if columns_to_drop:\n-            if args.yes or user_agrees('Do you want to drop columns {} from \"{}\"?'.format(columns_to_drop, table_name)):\n-                table.drop_columns(*columns_to_drop)\n+\n+def main() -> None:\n+    \"\"\"Run main functionality of this script.\"\"\"\n+    connection = get_connection_to_hbase()\n+    existing_tables = set(connection.tables())\n+    schema_tables = set(HBaseClient.HBASE_SCHEMA)\n+    tables_to_drop = list(existing_tables - schema_tables)\n+\n+    for table_name in tables_to_drop:\n+        table = connection.table(table_name)\n+        drop_table(table)\n+\n+    for table_name in HBaseClient.HBASE_SCHEMA:\n+        table = connection.table(table_name)\n+        if not table.exists():\n+            create_new_table(table)\n+        else:\n+            update_table_schema(table)\n+\n+\n+if __name__ == '__main__':\n+    main()\n", "issue": "Add \"radon\" tool to the Backend and enable it in CI\n## Expected Behavior\r\n\r\nPython code in backend should be validated by \"radon\" tool in CI.\r\n\r\n## Actual Behavior\r\n\r\nMedTagger backend uses a few linters already but we should add more validators to increate automation and code quality.\n", "before_files": [{"content": "\"\"\"Script that can migrate existing HBase schema or prepare empty database with given schema.\n\nHow to use it?\n--------------\nRun this script just by executing following line in the root directory of this project:\n\n    (venv) $ python3.6 scripts/migrate_hbase.py\n\n\"\"\"\nimport argparse\nimport logging\nimport logging.config\n\nfrom medtagger.clients.hbase_client import HBaseClient\nfrom utils import get_connection_to_hbase, user_agrees\n\nlogging.config.fileConfig('logging.conf')\nlogger = logging.getLogger(__name__)\n\nparser = argparse.ArgumentParser(description='HBase migration.')\nparser.add_argument('-y', '--yes', dest='yes', action='store_const', const=True)\nargs = parser.parse_args()\n\n\nHBASE_SCHEMA = HBaseClient.HBASE_SCHEMA\nconnection = get_connection_to_hbase()\nexisting_tables = set(connection.tables())\nschema_tables = set(HBASE_SCHEMA)\ntables_to_drop = list(existing_tables - schema_tables)\nfor table_name in tables_to_drop:\n    if args.yes or user_agrees('Do you want to drop table \"{}\"?'.format(table_name)):\n        logger.info('Dropping table \"%s\".', table_name)\n        table = connection.table(table_name)\n        table.drop()\n\nfor table_name in HBASE_SCHEMA:\n    table = connection.table(table_name)\n    if not table.exists():\n        if args.yes or user_agrees('Do you want to create table \"{}\"?'.format(table_name)):\n            list_of_columns = HBASE_SCHEMA[table_name]\n            logger.info('Creating table \"%s\" with columns %s.', table_name, list_of_columns)\n            table.create(*list_of_columns)\n            table.enable_if_exists_checks()\n    else:\n        existing_column_families = set(table.columns())\n        schema_column_families = set(HBASE_SCHEMA[table_name])\n        columns_to_add = list(schema_column_families - existing_column_families)\n        columns_to_drop = list(existing_column_families - schema_column_families)\n\n        if columns_to_add:\n            if args.yes or user_agrees('Do you want to add columns {} to \"{}\"?'.format(columns_to_add, table_name)):\n                table.add_columns(*columns_to_add)\n\n        if columns_to_drop:\n            if args.yes or user_agrees('Do you want to drop columns {} from \"{}\"?'.format(columns_to_drop, table_name)):\n                table.drop_columns(*columns_to_drop)\n", "path": "backend/scripts/migrate_hbase.py"}]}