Skip to content

Commit

Permalink
fixing up script to generate release notes
Browse files Browse the repository at this point in the history
  • Loading branch information
gtfierro committed Aug 22, 2024
1 parent f7faf10 commit 6efe073
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 9 deletions.
5 changes: 3 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ description = "Add your description here"
authors = [
{ name = "Gabe Fierro", email = "[email protected]" }
]
readme = "README.md"
requires-python = ">= 3.9"
[tool.uv]
dev-dependencies = [
"rdflib>=7.0.0",
Expand All @@ -23,9 +25,8 @@ dev-dependencies = [
"brickschema[topquadrant]>=0.7.6a2",
"scipy>=1.13.1",
"sentence-transformers>=3.0.1",
"numpy>=2.0.1",
]
readme = "README.md"
requires-python = ">= 3.9"

[build-system]
requires = ["hatchling"]
Expand Down
51 changes: 44 additions & 7 deletions tools/compare_versions/compare_versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

dirname = Path(__file__).resolve().parent.parent.parent
sys.path.append(str(dirname))
from bricksrc.deprecations import deprecations

import semver
from rdflib import Graph, OWL, RDF, RDFS, Namespace, SKOS
Expand All @@ -28,11 +27,12 @@ def get_root(version):
short_version = get_short_version(version)
if short_version == "1.3":
return "https://brickschema.org/schema/Brick#Class"
if short_version == "1.4":
return "https://brickschema.org/schema/Brick#Entity"
if semver.compare(version, "1.0.3") > 0: # if current version is newer than 1.0.3
return f"https://brickschema.org/schema/{short_version}/Brick#Class"
return f"https://brickschema.org/schema/{short_version}/BrickFrame#TagSet"
if semver.compare(version, "1.0.3") <= 0: # if current version is older than 1.0.3
return f"https://brickschema.org/schema/{short_version}/BrickFrame#TagSet"
# 1.4 and later
return "https://brickschema.org/schema/Brick#Entity"


argparser = argparse.ArgumentParser()
Expand Down Expand Up @@ -175,6 +175,23 @@ def prep_concept(graph, concept):
distance_matrix = 1 - similarities
row_ind, col_ind = linear_sum_assignment(distance_matrix)

# fetch all deprecations from Brick
deprecations = {}
qstr = """
SELECT ?s ?version ?message ?replacement WHERE {
?s owl:deprecated true .
?s brick:deprecatedInVersion ?version .
?s brick:deprecationMitigationMessage ?message .
?s brick:isReplacedBy ?replacement .
}
"""
for row in new_brick.query(qstr):
deprecations[row[0]] = {
"version": row[1],
"message": row[2],
"replacement": row[3],
}

mapping = {}
for i, j in zip(row_ind, col_ind):
score = similarities[i, j]
Expand All @@ -189,6 +206,26 @@ def prep_concept(graph, concept):
with open(history_dir / "mapping.json", "w") as fp:
json.dump(mapping, fp)

# write deprecations to json file
with open(history_dir / "deprecations.json", "w") as fp:
json.dump(deprecations, fp)
# remove deprecations that are not new
for row in old_brick.query(qstr):
if row[0] in deprecations:
del deprecations[row[0]]

# output the Markdown-formatted release notes

# output added classes
with open(history_dir / "release_notes.md", "w") as fp:
fp.write("## Added Concepts\n\n```\n")
for c in sorted(set(new_classes) - set(old_classes)):
fp.write(f"{c}")
fp.write("\n```\n")

fp.write("\n\n## Removed Concepts\n\n```\n")
for c in sorted(set(old_classes) - set(new_classes)):
fp.write(f"{c}")
fp.write("\n```\n")

fp.write("\n\n## Deprecations\n\n")
fp.write("<details>\n<summary>Deprecations JSON</summary>\n\n```json\n")
json.dump(deprecations, fp, indent=2)
fp.write("\n```\n")

0 comments on commit 6efe073

Please sign in to comment.