Skip to content

Commit 567b01c

Browse files
committed
STYLE: Only output downloadable .zip archives for examples
Keep it simple and do not also generation .tar.gz tarballs. Make sure to also add the .ipynb notebooks.
1 parent f76dc43 commit 567b01c

File tree

3 files changed

+25
-42
lines changed

3 files changed

+25
-42
lines changed

CMake/ITKSphinxExamplesMacros.cmake

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
include(CMakeParseArguments)
22

33
# A high level target that the individual targets depend on.
4-
#add_custom_target( CreateTarballs ALL
5-
# ${CMAKE_COMMAND} -E echo "Done creating individual example tarballs..."
4+
#add_custom_target( CreateDownloadableArchives ALL
5+
# ${CMAKE_COMMAND} -E echo "Done creating individual example downloadable archives..."
66
#)
77

88
# Macro for adding an example.
@@ -11,20 +11,20 @@ include(CMakeParseArguments)
1111
# CMakeLists.txt. That file should be standalone for building the example.
1212
# This macro is intended to be instantiated in the CMakeLists.txt one directory
1313
# above where the example exists. It does things like creating the example
14-
# tarball's in the example output directory, and custom targets for building
14+
# archives's in the example output directory, and custom targets for building
1515
# the Sphinx documentation for an individual example. The Sphinx target will be
1616
# called ${example_name}Doc.
1717
macro(add_example example_name)
1818
if(BUILD_DOCUMENTATION)
1919
if(SPHINX_HTML_OUTPUT)
20-
add_custom_target(${example_name}Tarball
21-
COMMAND ${PYTHON_EXECUTABLE} ${ITKSphinxExamples_SOURCE_DIR}/Utilities/CreateTarball.py
20+
add_custom_target(${example_name}DownloadableArchive
21+
COMMAND ${PYTHON_EXECUTABLE} ${ITKSphinxExamples_SOURCE_DIR}/Utilities/CreateDownloadableArchive.py
2222
${example_name} ${SPHINX_DESTINATION}
2323
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
24-
COMMENT "Creating tarballs for ${example_name}"
24+
COMMENT "Creating downloadable archive for ${example_name}"
2525
DEPENDS copy_sources
2626
)
27-
add_dependencies(CreateTarballs ${example_name}Tarball)
27+
add_dependencies(CreateDownloadableArchives ${example_name}DownloadableArchive)
2828
endif()
2929
endif()
3030

CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -262,8 +262,8 @@ if(BUILD_DOCUMENTATION)
262262
add_dependencies(gitstats copy_sources)
263263

264264
# A high level target that the individual targets depend on.
265-
add_custom_target(CreateTarballs ALL
266-
${CMAKE_COMMAND} -E echo "Done creating individual example tarballs..."
265+
add_custom_target(CreateDownloadableArchives ALL
266+
${CMAKE_COMMAND} -E echo "Done creating individual example downloadable archives..."
267267
)
268268

269269
if(NOT ITKDoxygenXML_DIR)
@@ -282,7 +282,7 @@ if(BUILD_DOCUMENTATION)
282282
set(SPHINX_CONF_DIR ${ITKSphinxExamples_BINARY_DIR}/Formatting)
283283
set(SPHINX_INPUT_DIR ${ITKSphinxExamples_BINARY_DIR})
284284
set(SPHINX_DESTINATION ${ITKSphinxExamples_BINARY_DIR})
285-
set(SPHINX_DEPENDENCIES gitstats ITKDoxygenXML ITKSphinxExamplesData ITKDoxygenTAG CreateTarballs)
285+
set(SPHINX_DEPENDENCIES gitstats ITKDoxygenXML ITKSphinxExamplesData ITKDoxygenTAG CreateDownloadableArchives)
286286

287287
option(DOC_WITH_LOCAL_DOXYGEN "Generate documentation with local doxygen" OFF)
288288
mark_as_advanced(DOC_WITH_LOCAL_DOXYGEN)
Lines changed: 15 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env python
22

3-
""" Build tarballs for the examples.
3+
""" Build archives for the examples.
44
55
Build the .tar.gz and .zip for the example, and copy them along with the
66
supporting files into the html output.
@@ -12,7 +12,6 @@
1212
import os
1313
import shutil
1414
import sys
15-
import tarfile
1615
import zipfile
1716
from pathlib import Path
1817

@@ -26,6 +25,7 @@
2625

2726
example_name = sys.argv[1]
2827
base_dir = cwd.parent.parent.parent
28+
example_dir = str(cwd / example_name)
2929
example_relative_path = cwd.relative_to(base_dir) / example_name
3030
html_output_dir = str(Path(sys.argv[2]) / "html" / example_relative_path)
3131

@@ -38,68 +38,51 @@
3838
files_to_copy_to_html_output.extend(glob.glob(os.path.join(example_dir, "*.cxx")))
3939
files_to_copy_to_html_output.extend(glob.glob(os.path.join(example_dir, "*.html")))
4040
files_to_copy_to_html_output.extend(glob.glob(os.path.join(example_dir, "*.py")))
41+
files_to_copy_to_html_output.extend(glob.glob(os.path.join(example_dir, "*.ipynb")))
4142
files_to_copy_to_html_output.extend(glob.glob(os.path.join(example_dir, "*.rst")))
4243
for path in files_to_copy_to_html_output:
4344
shutil.copy2(path, html_output_dir)
4445

4546

46-
# Tarballs for users to download from the website.
47-
files_for_tarball = files_to_copy_to_html_output
47+
# archives for users to download from the website.
48+
files_for_archive = files_to_copy_to_html_output
4849

4950
# Add a directory to build the project.
5051
build_dir = os.path.join(example_dir, "build")
5152
if not os.path.exists(build_dir):
5253
os.mkdir(build_dir)
53-
files_for_tarball.append(build_dir)
54+
files_for_archive.append(build_dir)
5455

5556
# Substitude CMAKE_CURRENT_BINARY_DIR for CMAKE_CURRENT_SOURCE_DIR in the
56-
# tarball CMakeLists.txt. This so the input images can be found.
57-
tarball_cmakelist = os.path.join(example_dir, "CMakeLists.txt.tarball")
58-
with open(tarball_cmakelist, "w") as new_list_file:
57+
# archive CMakeLists.txt. This so the input images can be found.
58+
archive_cmakelist = os.path.join(example_dir, "CMakeLists.txt.archive")
59+
with open(archive_cmakelist, "w") as new_list_file:
5960
with open(os.path.join(example_dir, "CMakeLists.txt"), "r") as old_list_file:
6061
for line in old_list_file:
6162
newline = line.replace(
6263
"CMAKE_CURRENT_BINARY_DIR", "CMAKE_CURRENT_SOURCE_DIR"
6364
)
6465
new_list_file.write(newline)
65-
files_for_tarball = files_for_tarball[1:]
66-
files_for_tarball.append(tarball_cmakelist)
66+
files_for_archive = files_for_archive[1:]
67+
files_for_archive.append(archive_cmakelist)
6768

6869
inputs = glob.glob(os.path.join(example_dir, "*.sha512"))
6970
for path in inputs:
70-
files_for_tarball.append(path[:-7])
71+
files_for_archive.append(path[:-7])
7172

7273
# Remove duplicates.
73-
files_for_tarball = set(files_for_tarball)
74-
75-
with tarfile.open(
76-
os.path.join(html_output_dir, example_name + ".tar.gz"), "w:gz", dereference=True
77-
) as tarfile:
78-
example_dir_idx = example_dir.index(example_name)
79-
80-
def strip_path(tarinfo):
81-
tarinfo.name = tarinfo.name[example_dir_idx - 1 :]
82-
# Put the inputs and outputs into the build directory because the test
83-
# will not be able to find them otherwise.
84-
basename = os.path.basename(tarinfo.name)
85-
if basename == "CMakeLists.txt.tarball":
86-
head, tail = os.path.split(tarinfo.name)
87-
tarinfo.name = os.path.join(head, "CMakeLists.txt")
88-
return tarinfo
89-
90-
for path in files_for_tarball:
91-
tarfile.add(path, filter=strip_path)
74+
files_for_archive = set(files_for_archive)
9275

9376
with zipfile.ZipFile(
9477
os.path.join(html_output_dir, example_name + ".zip"), "w"
9578
) as zipfile:
9679
example_dir_idx = example_dir.index(example_name)
97-
for path in files_for_tarball:
80+
for path in files_for_archive:
9881
arcname = path[example_dir_idx - 1 :]
9982
# Put the inputs and outputs into the build directory because the test
10083
# will not be able to find them otherwise.
10184
basename = os.path.basename(arcname)
102-
if basename == "CMakeLists.txt.tarball":
85+
if basename == "CMakeLists.txt.archive":
10386
head, tail = os.path.split(arcname)
10487
arcname = os.path.join(head, "CMakeLists.txt")
10588
zipfile.write(path, arcname)

0 commit comments

Comments
 (0)