aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2021-12-07 16:19:23 +0100
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2021-12-08 12:12:16 +0100
commit8cbfe9aa6f46483968b8273aa45deaad12bffbfd (patch)
treeb89fc50239cb31c48ca5f5b8a5a40587f029560d /tools
parent298b607b38cf44f346d5fb98e6bb36c184e2b5fb (diff)
example_gallery: Handle dummy projects in the doc directory
Make it possible to have a dummy pyproject file with entries pointing to the parent directory in the doc directory as not to clash with a CMakeLists.txt in the examples directory. Separate the code paths for the pyproject_file and the actual examples directory for this purpose. Pick-to: 6.2 Change-Id: I0a1e583bff8cbb8243ba7526b8b2908f6a3e6e9c Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
Diffstat (limited to 'tools')
-rw-r--r--tools/example_gallery/main.py40
1 files changed, 21 insertions, 19 deletions
diff --git a/tools/example_gallery/main.py b/tools/example_gallery/main.py
index 6b02cb4c0..d6e6468bd 100644
--- a/tools/example_gallery/main.py
+++ b/tools/example_gallery/main.py
@@ -153,7 +153,7 @@ def remove_licenses(s):
return "\n".join(new_s)
-def get_code_tabs(files, project_file):
+def get_code_tabs(files, project_dir):
content = "\n"
for i, project_file in enumerate(files):
@@ -167,7 +167,7 @@ def get_code_tabs(files, project_file):
content += add_indent(f".. code-block:: {lexer}", 1)
content += "\n"
- _path = f_path.resolve().parents[0] / project_file
+ _path = project_dir / project_file
_file_content = ""
try:
with open(_path, "r") as _f:
@@ -181,9 +181,9 @@ def get_code_tabs(files, project_file):
return content
-def get_header_title(f_path):
- _title = f_path.stem
- url_name = "/".join(f_path.parts[f_path.parts.index("examples")+1:-1])
+def get_header_title(example_dir):
+ _title = str(example_dir)
+ url_name = "/".join(example_dir.parts[example_dir.parts.index("examples")+1:])
url = f"{BASE_URL}/{url_name}"
return (
"..\n This file was auto-generated by the 'examples_gallery' "
@@ -197,8 +197,8 @@ def get_header_title(f_path):
if __name__ == "__main__":
# Only examples with a '.pyproject' file will be listed.
DIR = Path(__file__).parent
- EXAMPLES_DOC = Path(f"{DIR}/../../sources/pyside6/doc/examples")
- EXAMPLES_DIR = Path(f"{DIR}/../../examples/")
+ EXAMPLES_DOC = Path(f"{DIR}/../../sources/pyside6/doc/examples").resolve()
+ EXAMPLES_DIR = Path(f"{DIR}/../../examples/").resolve()
BASE_URL = "https://code.qt.io/cgit/pyside/pyside-setup.git/tree/examples"
columns = 5
gallery = ""
@@ -219,11 +219,14 @@ if __name__ == "__main__":
if not EXAMPLES_DOC.is_dir():
EXAMPLES_DOC.mkdir()
- for f_path in EXAMPLES_DIR.glob("**/*.pyproject"):
- if str(f_path).endswith("examples.pyproject"):
+ for pyproject_file in EXAMPLES_DIR.glob("**/*.pyproject"):
+ if pyproject_file.name == "examples.pyproject":
continue
+ example_dir = pyproject_file.parent
+ if example_dir.name == "doc": # Dummy pyproject in doc dir (scriptableapplication)
+ example_dir = example_dir.parent
- parts = f_path.parts[len(EXAMPLES_DIR.parts):-1]
+ parts = example_dir.parts[len(EXAMPLES_DIR.parts):]
module_name = parts[0]
example_name = parts[-1]
@@ -241,7 +244,7 @@ if __name__ == "__main__":
# Check for a 'doc' directory inside the example
has_doc = False
img_doc = None
- original_doc_dir = Path(f_path.parent / "doc")
+ original_doc_dir = Path(example_dir / "doc")
if original_doc_dir.is_dir():
has_doc = True
images = [i for i in original_doc_dir.glob("*") if i.is_file() and check_img_ext(i)]
@@ -262,7 +265,7 @@ if __name__ == "__main__":
"module": module_name,
"extra": extra_names,
"rst": rst_file,
- "abs_path": str(f_path),
+ "abs_path": str(example_dir),
"has_doc": has_doc,
"img_doc": img_doc,
}
@@ -270,11 +273,11 @@ if __name__ == "__main__":
files = []
try:
- with open(str(f_path), "r") as pyf:
+ with pyproject_file.open("r") as pyf:
pyproject = json.load(pyf)
files = pyproject["files"]
except (json.JSONDecodeError, KeyError) as e:
- print(f"example_gallery: error reading {f_path}: {e}")
+ print(f"example_gallery: error reading {pyproject_file}: {e}")
raise
if files:
@@ -282,8 +285,7 @@ if __name__ == "__main__":
with open(rst_file_full, "w") as out_f:
if has_doc:
- doc_path = Path(f_path.parent) / "doc"
- doc_rst = doc_path / f"{example_name}.rst"
+ doc_rst = original_doc_dir / f"{example_name}.rst"
with open(doc_rst) as doc_f:
content_f = doc_f.read()
@@ -291,7 +293,7 @@ if __name__ == "__main__":
# Copy other files in the 'doc' directory, but
# excluding the main '.rst' file and all the
# directories.
- for _f in doc_path.glob("*"):
+ for _f in original_doc_dir.glob("*"):
if _f == doc_rst or _f.is_dir():
continue
src = _f
@@ -301,8 +303,8 @@ if __name__ == "__main__":
if not opt_quiet:
print("Written resource:", resource_written)
else:
- content_f = get_header_title(f_path)
- content_f += get_code_tabs(files, out_f)
+ content_f = get_header_title(example_dir)
+ content_f += get_code_tabs(files, pyproject_file.parent)
out_f.write(content_f)
if not opt_quiet: