@@ -1174,6 +1174,29 @@ def load_graph(sources: List[BuildSource], manager: BuildManager) -> Graph:
11741174 return graph
11751175
11761176
1177+ # The key property of the ordering here that we really need is that
1178+ # .sql.base is processed before .sql.schema.
1179+ # TODO: We shouldn't need this special case.
1180+ SQLALCHEMY_HACK = [
1181+ 'sqlalchemy.sql.base' ,
1182+ 'sqlalchemy.sql.type_api' ,
1183+ 'sqlalchemy.sql.elements' ,
1184+ 'sqlalchemy.sql.sqltypes' ,
1185+ 'sqlalchemy.sql.ddl' ,
1186+ 'sqlalchemy.sql.selectable' ,
1187+ 'sqlalchemy.sql.schema' ,
1188+ 'sqlalchemy.sql.functions' ,
1189+ 'sqlalchemy.sql.dml' ,
1190+ 'sqlalchemy.sql.expression' ,
1191+ 'sqlalchemy.sql' ,
1192+ 'sqlalchemy.pool' ,
1193+ 'sqlalchemy.schema' ,
1194+ 'sqlalchemy.types' ,
1195+ 'sqlalchemy' ,
1196+ ]
1197+ SQLALCHEMY_HACK_SET = frozenset (SQLALCHEMY_HACK )
1198+
1199+
11771200def process_graph (graph : Graph , manager : BuildManager ) -> None :
11781201 """Process everything in dependency order."""
11791202 sccs = sorted_components (graph )
@@ -1188,6 +1211,23 @@ def process_graph(graph: Graph, manager: BuildManager) -> None:
11881211 if 'builtins' in ascc :
11891212 scc .remove ('builtins' )
11901213 scc .append ('builtins' )
1214+ elif ascc == SQLALCHEMY_HACK_SET :
1215+ # TODO: This is a really gross hack to deal with the
1216+ # unfortunate reality that the scqlalchemy package
1217+ # contains a cycle where our usual approach isn't enough.
1218+ # There is probably a better way to handle it but I need a
1219+ # break. For example, if you look at each subpackage,
1220+ # *within* the subpackage there's a clear ordering, and we
1221+ # could handle that by running the SCC+topsort algorithm
1222+ # over that subgraph.
1223+ manager .log ("Replacing %s with %s" % (scc , SQLALCHEMY_HACK_SET ))
1224+ scc = SQLALCHEMY_HACK
1225+ # Here's how I came up with the ordering in SQLALCHEMY_HACK:
1226+ # sub_graph = {id: graph[id]
1227+ # for id in scc if id.startswith('sqlalchemy.sql.')}
1228+ # sub_sccs = sorted_components(sub_graph)
1229+ # for sub_scc in sub_sccs:
1230+ # print(sub_scc)
11911231 stale_scc = {id for id in scc if not graph [id ].is_fresh ()}
11921232 fresh = not stale_scc
11931233 deps = set ()
0 commit comments