aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2021-11-26 18:20:21 +0100
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2021-11-27 16:21:09 +0000
commit6c989ac4cea929e5b4390f9a98f0b5c596695cae (patch)
tree9caeea4758608df6416b2e7d8c6c6b754ec717c4
parent1b6ce6a3645a75732d31d3ddd070e21b19b7b24e (diff)
snippets_translate: Handle header files as well
Use suffix .h.py for them to distinguish them from .cpp files. Task-number: PYSIDE-1721 Change-Id: Iea4bfa770833f319b65c1ea7f83fb1a325ce8c62 Reviewed-by: Christian Tismer <tismer@stackless.com> (cherry picked from commit 6fd1e6619b0aeef1f7e916e474693157450e765f) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--sources/shiboken6/generator/qtdoc/qtxmltosphinx.cpp10
-rw-r--r--tools/snippets_translate/main.py11
2 files changed, 10 insertions, 11 deletions
diff --git a/sources/shiboken6/generator/qtdoc/qtxmltosphinx.cpp b/sources/shiboken6/generator/qtdoc/qtxmltosphinx.cpp
index dba24f2fe..78e91ce93 100644
--- a/sources/shiboken6/generator/qtdoc/qtxmltosphinx.cpp
+++ b/sources/shiboken6/generator/qtdoc/qtxmltosphinx.cpp
@@ -489,10 +489,12 @@ QString QtXmlToSphinx::readFromLocations(const QStringList &locations, const QSt
const QString &identifier, QString *errorMessage)
{
QString resolvedPath;
- if (path.endsWith(QLatin1String(".cpp"))) {
- const QString pySnippet = path.left(path.size() - 3) + QLatin1String("py");
- resolvedPath = resolveFile(locations, pySnippet);
- }
+ // Try Python snippets first.
+ if (path.endsWith(u".cpp"))
+ resolvedPath = resolveFile(locations, path.left(path.size() - 3) + u"py"_qs);
+ else if (path.endsWith(u".h"))
+ resolvedPath = resolveFile(locations, path + u".py"_qs);
+
if (resolvedPath.isEmpty())
resolvedPath = resolveFile(locations, path);
if (resolvedPath.isEmpty()) {
diff --git a/tools/snippets_translate/main.py b/tools/snippets_translate/main.py
index 792328933..53a941a8c 100644
--- a/tools/snippets_translate/main.py
+++ b/tools/snippets_translate/main.py
@@ -277,7 +277,8 @@ def translate_file(file_path, final_path, debug, write):
if write:
# Open the final file
- target_file = final_path.with_suffix(".py")
+ new_suffix = ".h.py" if final_path.name.endswith(".h") else ".py"
+ target_file = final_path.with_suffix(new_suffix)
# Directory where the file will be placed, if it does not exists
# we create it. The option 'parents=True' will create the parents
@@ -338,13 +339,9 @@ def copy_file(file_path, py_path, category, category_path, write=False, debug=Fa
else:
log.info(f"{status_msg:10s} {final_path}")
- # Change .cpp to .py
- # TODO:
- # - What do we do with .h in case both .cpp and .h exists with
- # the same name?
-
+ # Change .cpp to .py, .h to .h.py
# Translate C++ code into Python code
- if final_path.name.endswith(".cpp"):
+ if final_path.name.endswith(".cpp") or final_path.name.endswith(".h"):
translate_file(file_path, final_path, debug, write)
return status