Skip to content

Commit bdf411a

Browse files
committed
Bulk generator: Make 'database_results' a map to simplify away the explicit sorting.
1 parent cdd869a commit bdf411a

File tree

1 file changed

+4
-19
lines changed

1 file changed

+4
-19
lines changed

misc/scripts/models-as-data/bulk_generate_mad.py

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ def download_dca_databases(
318318
Returns:
319319
List of (project_name, database_dir) pairs, where database_dir is None if the download failed.
320320
"""
321-
database_results = []
321+
database_results = {}
322322
print("\n=== Finding projects ===")
323323
response = get_json_from_github(
324324
f"https://raw.githubusercontent.com/github/codeql-dca-main/data/{experiment_name}/reports/downloads.json",
@@ -365,28 +365,13 @@ def download_dca_databases(
365365
with tarfile.open(artifact_tar_location, "r:gz") as tar_ref:
366366
# And we just untar it to the same directory as the zip file
367367
tar_ref.extractall(artifact_unzipped_location)
368-
database_results.append(
369-
(
370-
project_map[pretty_name],
371-
os.path.join(
372-
artifact_unzipped_location, remove_extension(entry)
373-
),
374-
)
368+
database_results[pretty_name] = os.path.join(
369+
artifact_unzipped_location, remove_extension(entry)
375370
)
376371

377372
print(f"\n=== Extracted {len(database_results)} databases ===")
378373

379-
def compare(a, b):
380-
a_index = next(
381-
i for i, project in enumerate(projects) if project["name"] == a[0]["name"]
382-
)
383-
b_index = next(
384-
i for i, project in enumerate(projects) if project["name"] == b[0]["name"]
385-
)
386-
return a_index - b_index
387-
388-
# Sort the database results based on the order in the projects file
389-
return sorted(database_results, key=cmp_to_key(compare))
374+
return [(project, database_results[project["name"]]) for project in projects]
390375

391376

392377
def get_mad_destination_for_project(config, name: str) -> str:

0 commit comments

Comments
 (0)