aboutsummaryrefslogtreecommitdiffstats
path: root/tools/example_gallery/main.py
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2024-08-20 14:34:23 +0200
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2024-08-21 10:28:11 +0200
commit59b8417c42cffde93c477351a2a22c290e59c106 (patch)
tree77e80445e44c691940263bac1665f4000ab9618d /tools/example_gallery/main.py
parentac16495bb7f38bfd0aa7bf1a410648220dcee9e1 (diff)
example_gallery: Handle examples which have the pyproject file in the "doc" dir
Examples like samplebinding, etc. have a CMakeLists.txt and only a dummy pyproject file in the "doc" dir, which caused the zipping to fail. Modify make_zip_archive() to take the complete target path as an argument and remove the move command. Change one level up if the pyproject file is in "doc". Pick-to: 6.7 Change-Id: Ibf6064e6e0e6a4e24e25348d3a4b52d361ae9560 Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
Diffstat (limited to 'tools/example_gallery/main.py')
-rw-r--r--tools/example_gallery/main.py13
1 files changed, 6 insertions, 7 deletions
diff --git a/tools/example_gallery/main.py b/tools/example_gallery/main.py
index d835bf4ac..40a6eeaeb 100644
--- a/tools/example_gallery/main.py
+++ b/tools/example_gallery/main.py
@@ -266,14 +266,14 @@ def remove_licenses(s):
return "\n".join(new_s)
-def make_zip_archive(zip_name, src, skip_dirs=None):
+def make_zip_archive(zip_file, src, skip_dirs=None):
src_path = Path(src).expanduser().resolve(strict=True)
if skip_dirs is None:
skip_dirs = []
if not isinstance(skip_dirs, list):
print("Error: A list needs to be passed for 'skip_dirs'")
return
- with zipfile.ZipFile(src_path.parents[0] / Path(zip_name), 'w', zipfile.ZIP_DEFLATED) as zf:
+ with zipfile.ZipFile(zip_file, 'w', zipfile.ZIP_DEFLATED) as zf:
for file in src_path.rglob('*'):
skip = False
_parts = file.relative_to(src_path).parts
@@ -298,11 +298,10 @@ def get_code_tabs(files, project_dir, file_format):
content = "\n"
# Prepare ZIP file, and copy to final destination
- zip_name = f"{project_dir.name}.zip"
- make_zip_archive(zip_name, project_dir, skip_dirs=["doc"])
- zip_src = f"{project_dir}.zip"
- zip_dst = EXAMPLES_DOC / zip_name
- shutil.move(zip_src, zip_dst)
+ # Handle examples which only have a dummy pyproject file in the "doc" dir
+ zip_root = project_dir.parent if project_dir.name == "doc" else project_dir
+ zip_name = f"{zip_root.name}.zip"
+ make_zip_archive(EXAMPLES_DOC / zip_name, zip_root, skip_dirs=["doc"])
if file_format == Format.RST:
content += f":download:`Download this example <{zip_name}>`\n\n"