Skip to content

Commit 497336d

Browse files
committed
Add script for updating CastXML version
1 parent 8a974d6 commit 497336d

File tree

4 files changed

+224
-2
lines changed

4 files changed

+224
-2
lines changed

CastXMLUrls.cmake

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
12
#-----------------------------------------------------------------------------
23
# CastXML binaries
4+
35
set(linux32_binary_url "NA") # Linux 32-bit binaries not available
46
set(linux32_binary_sha512 "NA")
57

@@ -13,4 +15,4 @@ set(win32_binary_url "NA") # Windows 32-bit binaries not available
1315
set(win32_binary_sha512 "NA")
1416

1517
set(win64_binary_url "https://data.kitware.com/api/v1/file/5ee7eb539014a6d84ec1f22a/download")
16-
set(win64_binary_sha512 "fa7a38dbdb71e0484cfeb255aef6d085abf23496a85051e3dccac593d9eec042fad5be72110d7f3528b424d90fbf5b5053c31f054470d691a7109c1f13776229")
18+
set(win64_binary_sha512 "fa7a38dbdb71e0484cfeb255aef6d085abf23496a85051e3dccac593d9eec042fad5be72110d7f3528b424d90fbf5b5053c31f054470d691a7109c1f13776229")

README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
# CastXML
1+
# CastXML Python Distribution
22

33
Introduction
44
============
55

6+
The latest CastXML python wheels provide CastXML 0.3.4 executable.
7+
68
CastXML is a C-family abstract syntax tree XML output tool.
79

810
This project is maintained by [Kitware][kitware] in support of [ITK][itk],
@@ -18,6 +20,11 @@ See the [castxml(1)][manual] manual page for instructions to run the tool.
1820

1921
[manual]: https://github.com/CastXML/CastXML/blob/master/doc/manual/castxml.1.rst#castxml1
2022

23+
Maintainers
24+
===========
25+
26+
* [How to update CastXML version ?](https://github.com/CastXML/CastXML-python-distributions/blob/master/docs/update_ninja_version.rst)
27+
2128
License
2229
=======
2330

docs/update_castxml_version.rst

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
.. _updating_castxml_version:
2+
3+
============================
4+
Updating the CastXML version
5+
============================
6+
7+
A developer should use the following steps to update the version ``X.Y.Z``
8+
of CastXML associated with the current CastXML python distributions.
9+
10+
Available CastXML archives can be found `here <https://data.kitware.com/#folder/57b5de948d777f10f2696370>`_.
11+
12+
1. Install `girder-client`::
13+
14+
$ pip install girder-client
15+
16+
2. Execute `scripts/update_castxml_version.py` command line tool with the desired
17+
``X.Y.Z`` CastXML version available for download. For example::
18+
19+
$ release=0.3.4
20+
$ python scripts/update_castxml_version.py ${release}
21+
22+
Collecting URLs and SHAs from 'https://data.kitware.com/#folder/57b5de948d777f10f2696370'
23+
Collecting URLs and SHAs from 'https://data.kitware.com/#folder/57b5de948d777f10f2696370' - done
24+
Updating 'CastXMLUrls.cmake' with CastXML version 0.3.4
25+
Updating 'CastXMLUrls.cmake' with CastXML version 0.3.4 - done
26+
Updating README.md
27+
Updating README.md - done
28+
Updating docs/update_castxml_version.rst
29+
Updating docs/update_castxml_version.rst - done
30+
Updating tests/test_distribution.py
31+
Updating tests/test_distribution.py - done
32+
33+
3. Create a topic named `update-to-castxml-X.Y.Z` and commit the changes.
34+
For example::
35+
36+
release=0.3.4
37+
git checkout -b update-to-castxml-${release}
38+
git add CastXMLUrls.cmake README.md docs/update_castxml_version.rst tests/test_distribution.py
39+
git commit -m "Update to CastXML ${release}"
40+
41+
4. Create a `Pull Request`.
42+
43+
5. If all CI tests are passing, merge the topic and consider `making a new
44+
release <https://github.com/CastXML/CastXML-python-distributions/blob/master/docs/make_a_release.rst>`_.

scripts/update_castxml_version.py

Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
"""Command line executable allowing to update CastXMLUrls.cmake
2+
given a CMake version.
3+
"""
4+
5+
import argparse
6+
import contextlib
7+
import os
8+
import re
9+
import textwrap
10+
11+
try:
12+
import girder_client
13+
except ImportError:
14+
raise SystemExit(
15+
"girder_client not available: "
16+
"consider installing it running 'pip install girder-client'"
17+
)
18+
19+
ROOT_DIR = os.path.join(os.path.dirname(__file__), "..")
20+
21+
22+
@contextlib.contextmanager
23+
def _log(txt, verbose=True):
24+
if verbose:
25+
print(txt)
26+
yield
27+
if verbose:
28+
print("%s - done" % txt)
29+
30+
31+
def get_archive_urls_and_shas(version, verbose=False):
32+
33+
host_url = 'https://data.kitware.com'
34+
folder_id = '57b5de948d777f10f2696370'
35+
36+
with _log("Collecting URLs and SHAs from '%s/#folder/%s'" % (host_url, folder_id)):
37+
38+
api_url = '%s/api/v1' % host_url
39+
gc = girder_client.GirderClient(apiUrl=api_url)
40+
41+
folders = gc.listFolder('57b5de948d777f10f2696370')
42+
archive_folder_ids = [folder['_id'] for folder in folders if folder['name'] == "v%s" % version]
43+
assert len(archive_folder_ids) == 1
44+
45+
items = gc.listItem(archive_folder_ids[0])
46+
47+
expected_files = {
48+
"castxml-linux.tar.gz": "linux64_binary",
49+
"castxml-macosx.tar.gz": "macosx_binary",
50+
"castxml-windows.zip": "win64_binary",
51+
}
52+
53+
# Get download URL and SHA512 for each file
54+
urls_and_shas = {}
55+
for item in items:
56+
files = list(gc.listFile(item['_id']))
57+
assert len(files) == 1
58+
file_id = files[0]['_id']
59+
file = files[0]['name']
60+
sha = files[0]['sha512']
61+
url = '%s/file/%s/download' % (api_url, file_id)
62+
if file in expected_files:
63+
identifier = expected_files[file]
64+
urls_and_shas[identifier] = (url, sha)
65+
if verbose:
66+
print("[%s]\n%s\n%s\n" % (identifier, url, sha))
67+
68+
assert len(urls_and_shas) == len(expected_files)
69+
70+
return urls_and_shas
71+
72+
73+
def generate_cmake_variables(urls_and_shas):
74+
template_inputs = {}
75+
76+
for var_prefix, urls_and_shas in urls_and_shas.items():
77+
template_inputs["%s_url" % var_prefix] = urls_and_shas[0]
78+
template_inputs["%s_sha512" % var_prefix] = urls_and_shas[1]
79+
80+
cmake_variables = textwrap.dedent("""
81+
#-----------------------------------------------------------------------------
82+
# CastXML binaries
83+
84+
set(linux32_binary_url "NA") # Linux 32-bit binaries not available
85+
set(linux32_binary_sha512 "NA")
86+
87+
set(linux64_binary_url "{linux64_binary_url}")
88+
set(linux64_binary_sha512 "{linux64_binary_sha512}")
89+
90+
set(macosx_binary_url "{macosx_binary_url}")
91+
set(macosx_binary_sha512 "{macosx_binary_sha512}")
92+
93+
set(win32_binary_url "NA") # Windows 32-bit binaries not available
94+
set(win32_binary_sha512 "NA")
95+
96+
set(win64_binary_url "{win64_binary_url}")
97+
set(win64_binary_sha512 "{win64_binary_sha512}")
98+
""").format(**template_inputs)
99+
100+
return cmake_variables
101+
102+
103+
def update_urls_script(version):
104+
content = generate_cmake_variables(
105+
get_archive_urls_and_shas(version))
106+
urls_filename = "CastXMLUrls.cmake"
107+
urls_filepath = os.path.join(ROOT_DIR, urls_filename)
108+
109+
msg = "Updating '%s' with CastXML version %s" % (urls_filename, version)
110+
with _log(msg), open(urls_filepath, "w") as urls_file:
111+
urls_file.write(content)
112+
113+
114+
def _update_file(filepath, regex, replacement, verbose=True):
115+
msg = "Updating %s" % os.path.relpath(filepath, ROOT_DIR)
116+
with _log(msg, verbose=verbose):
117+
pattern = re.compile(regex)
118+
with open(filepath, 'r') as doc_file:
119+
lines = doc_file.readlines()
120+
updated_content = []
121+
for line in lines:
122+
updated_content.append(
123+
re.sub(pattern, replacement, line))
124+
with open(filepath, "w") as doc_file:
125+
doc_file.writelines(updated_content)
126+
127+
128+
def update_docs(version):
129+
pattern = re.compile(r"CastXML \d\.\d\.\d")
130+
replacement = "CastXML %s" % version
131+
_update_file(
132+
os.path.join(ROOT_DIR, "README.md"),
133+
pattern, replacement)
134+
135+
pattern = re.compile(r"\d\.\d\.\d")
136+
replacement = version
137+
_update_file(
138+
os.path.join(ROOT_DIR, "docs/update_castxml_version.rst"),
139+
pattern, replacement)
140+
141+
142+
def update_tests(version):
143+
pattern = re.compile(r'expected_version = "\d.(\d)+.\d"')
144+
replacement = 'expected_version = "%s"' % version
145+
_update_file(os.path.join(
146+
ROOT_DIR, "tests/test_distribution.py"), pattern, replacement)
147+
148+
149+
def main():
150+
parser = argparse.ArgumentParser(description=__doc__)
151+
parser.add_argument(
152+
'version', metavar='CASTXML_VERSION', type=str,
153+
help='CastXML version of the form X.Y.Z'
154+
)
155+
parser.add_argument(
156+
'--collect-only', action='store_true',
157+
help='If specified, only display the archive URLs and associated hashsums'
158+
)
159+
args = parser.parse_args()
160+
if args.collect_only:
161+
get_archive_urls_and_shas(args.version, verbose=True)
162+
else:
163+
update_urls_script(args.version)
164+
update_docs(args.version)
165+
update_tests(args.version)
166+
167+
168+
if __name__ == "__main__":
169+
main()

0 commit comments

Comments
 (0)