From ce55af8da31095beb6b7f973f0fd19a08f66305b Mon Sep 17 00:00:00 2001 From: Laurent Rineau Date: Thu, 6 Jun 2024 21:35:54 +0200 Subject: [PATCH 1/2] fix pylint errors --- Documentation/doc/scripts/generate_how_to_cite.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Documentation/doc/scripts/generate_how_to_cite.py b/Documentation/doc/scripts/generate_how_to_cite.py index 4873b7065e7..04576120aa7 100644 --- a/Documentation/doc/scripts/generate_how_to_cite.py +++ b/Documentation/doc/scripts/generate_how_to_cite.py @@ -123,14 +123,14 @@ def gen_bib_entry(title, authors, bib, anchor): return res def gen_txt_entry(title, authors, bib, anchor,k): - title_r=title.replace("Kernel","%Kernel").replace("Interval","%Interval").replace("Matrix","%Matrix").replace("Kinetic","%Kinetic").replace("CGAL","\cgal").replace("Range","%Range") - authors=authors.replace("CGAL","\cgal") + title_r=title.replace("Kernel","%Kernel").replace("Interval","%Interval").replace("Matrix","%Matrix").replace("Kinetic","%Kinetic").replace("CGAL",r'\cgal').replace("Range","%Range") + authors=authors.replace("CGAL",r'\cgal') res="\n\ \n\ ["+str(k)+"]\n\ \n\ \n "+authors+".\n "+title_r+".\n\ - In \cgal User and Reference Manual. \cgal Editorial Board,\n\ + In \\cgal User and Reference Manual. \\cgal Editorial Board,\n\ ${CGAL_CREATED_VERSION_NUM} edition, ${CGAL_BUILD_YEAR4}.\n\ [ bib | \n\ http ]\n\ @@ -199,7 +199,7 @@ for line in f: for pkg_line in pkgdesc: match = pattern_title_and_anchor.match(pkg_line) if match: - title=match.group(1).replace("\,",",") + title=match.group(1).replace(r'\,',",") anchor=match.group(2) continue match = pattern_author.match(pkg_line) @@ -210,9 +210,9 @@ for line in f: if match: bib=match.group(1) continue - assert len(bib)>0, "Did you forget a \cgalPkgBib{} in %r?" % filename - assert len(authors)>0, "Did you forget a \cgalPkgAuthors{} in %r?" % filename - assert len(anchor)>0, "Did you forget the anchor in \cgalPkgDescriptionBegin{} in %r?" % filename + assert len(bib)>0, "Did you forget a \\cgalPkgBib{} in %r?" % filename + assert len(authors)>0, "Did you forget a \\cgalPkgAuthors{} in %r?" % filename + assert len(anchor)>0, "Did you forget the anchor in \\cgalPkgDescriptionBegin{} in %r?" % filename result_txt+=gen_txt_entry(title, authors, bib, anchor,k) # convert title and author to bibtex format title=protect_upper_case(title) From 7eff8e0ee8ffda1919b87673d9b38d80a2f649cc Mon Sep 17 00:00:00 2001 From: Laurent Rineau Date: Thu, 6 Jun 2024 21:51:41 +0200 Subject: [PATCH 2/2] reformat, fix other pytlint warnings --- .../doc/scripts/generate_how_to_cite.py | 299 ++++++++++++------ 1 file changed, 201 insertions(+), 98 deletions(-) diff --git a/Documentation/doc/scripts/generate_how_to_cite.py b/Documentation/doc/scripts/generate_how_to_cite.py index 04576120aa7..ece849f18a9 100644 --- a/Documentation/doc/scripts/generate_how_to_cite.py +++ b/Documentation/doc/scripts/generate_how_to_cite.py @@ -9,7 +9,7 @@ import os ### Constants ### -result_bib=r"""@book{ cgal:eb-${CGAL_RELEASE_YEAR_ID} +RESULT_BIB = r"""@book{ cgal:eb-${CGAL_RELEASE_YEAR_ID} , title = "{CGAL} User and Reference Manual" , author = "{The CGAL Project}" , publisher = "{CGAL Editorial Board}" @@ -18,7 +18,7 @@ result_bib=r"""@book{ cgal:eb-${CGAL_RELEASE_YEAR_ID} , url = "https://doc.cgal.org/${CGAL_CREATED_VERSION_NUM}/Manual/packages.html" }""" -result_txt=r"""// This file was generated by generate_how_to_cite.py. You shouldn't modify it directly. +RESULT_TXT = r"""// This file was generated by generate_how_to_cite.py. You shouldn't modify it directly. /*! \page how_to_cite_cgal Acknowledging %CGAL @@ -73,13 +73,13 @@ The \cgal Project. """ -result_txt_footer=r""" +RESULT_TXT_FOOTER = r"""
*/ """ -pre_html=r""" +PRE_HTML = r""" @@ -90,11 +90,11 @@ pre_html=r""" """ -post_html=r""" +POST_HTML = r""" """ -result_html=r"""

how_to_cite_cgal.bib

+RESULT_HTML = r"""

how_to_cite_cgal.bib

 @book{cgal:eb-${CGAL_RELEASE_YEAR_ID},
   title = {{CGAL} User and Reference Manual},
   author = {{The CGAL Project}},
@@ -109,122 +109,225 @@ result_html=r"""

how_to_cite_cgal.bib

\n\ -\n\ -["+str(k)+"]\n\ +def gen_bib_entry(title, authors, bib, anchor): + res = ( + "\n\ +@incollection{" + + bib + + '-${CGAL_RELEASE_YEAR_ID}\n\ +, author = "' + + authors + + '"\n\ +, title = "' + + title + + '"\n\ +, publisher = "{CGAL Editorial Board}"\n\ +, edition = "{${CGAL_CREATED_VERSION_NUM}}"\n\ +, booktitle = "{CGAL} User and Reference Manual"\n\ +, url = "https://doc.cgal.org/${CGAL_CREATED_VERSION_NUM}/Manual/packages.html#' + + anchor + + '"\n\ +, year = ${CGAL_BUILD_YEAR4}\n\ +}\n' + ) + return res + + +def gen_txt_entry(title, authors, bib, anchor, k): + title_r = ( + title.replace("Kernel", "%Kernel") + .replace("Interval", "%Interval") + .replace("Matrix", "%Matrix") + .replace("Kinetic", "%Kinetic") + .replace("CGAL", r"\cgal") + .replace("Range", "%Range") + ) + authors = authors.replace("CGAL", r"\cgal") + res = ( + '\n\ +\n\ +[' + + str(k) + + ']\n\ \n\ -\n "+authors+".\n "+title_r+".\n\ +\n ' + + authors + + ".\n " + + title_r + + '.\n\ In \\cgal User and Reference Manual. \\cgal Editorial Board,\n\ ${CGAL_CREATED_VERSION_NUM} edition, ${CGAL_BUILD_YEAR4}.\n\ -[ bib | \n\ -http ]\n\ +[ bib | \n\ +http ]\n\ \n\ \n\ -\n\n\n" - return res +\n\n\n' + ) + return res + def gen_html_entry(title, authors, bib, anchor): - res="
\n\
-@incollection{"+bib+"-${CGAL_RELEASE_YEAR_ID},\n\
-  author = {"+authors+"},\n\
-  title = {"+title+"},\n\
+    res = (
+        '
\n\
+@incollection{'
+        + bib
+        + "-${CGAL_RELEASE_YEAR_ID},\n\
+  author = {"
+        + authors
+        + "},\n\
+  title = {"
+        + title
+        + '},\n\
   publisher = {{CGAL Editorial Board}},\n\
   edition = {{${CGAL_CREATED_VERSION_NUM}}},\n\
   booktitle = {{CGAL} User and Reference Manual},\n\
-  url = {https://doc.cgal.org/${CGAL_CREATED_VERSION_NUM}/Manual/packages.html#"+anchor+"},\n\
+  url = {https://doc.cgal.org/${CGAL_CREATED_VERSION_NUM}/Manual/packages.html#'
+        + anchor
+        + "},\n\
   year = ${CGAL_BUILD_YEAR4}\n\
 }\n\
 
\n\n" - return res + ) + return res + def protect_upper_case(title): - return title.replace("dD","{dD}").replace("2D","{2D}").replace("3D","{3D}").replace("CGAL","{CGAL}").replace("Qt","{Qt}").replace("Boost","{Boost}") + return ( + title.replace("dD", "{dD}") + .replace("2D", "{2D}") + .replace("3D", "{3D}") + .replace("CGAL", "{CGAL}") + .replace("Qt", "{Qt}") + .replace("Boost", "{Boost}") + ) + def protect_accentuated_letters(authors): - res=authors.replace("é",r"{\'e}").replace("è",r"{\`e}").replace("É",r"{\'E}").replace("ä",r"{\"a}").replace("ö",r"{\"o}").replace("ñ",r"{\~n}").replace("ã",r"{\~a}").replace("ë",r"{\"e}").replace("ı",r"{\i}").replace("Ş",r"{\c{S}}").replace("ş",r"{\c{s}}").replace("%","").replace("đ",r"{\-d}") - try: - res.encode('ascii') - except UnicodeEncodeError: - stderr.write("WARNING: a non-ASCII character has been found in author string for bibtex (probably a non-handled accentuated letter)." - "Check the new package added and update the function protect_accentuated_letters in Documentation/scripts/generate_how_to_cite.py\n\n") - return res + res = ( + authors.replace("é", r"{\'e}") + .replace("è", r"{\`e}") + .replace("É", r"{\'E}") + .replace("ä", r"{\"a}") + .replace("ö", r"{\"o}") + .replace("ñ", r"{\~n}") + .replace("ã", r"{\~a}") + .replace("ë", r"{\"e}") + .replace("ı", r"{\i}") + .replace("Ş", r"{\c{S}}") + .replace("ş", r"{\c{s}}") + .replace("%", "") + .replace("đ", r"{\-d}") + ) + try: + res.encode("ascii") + except UnicodeEncodeError: + stderr.write( + "WARNING: a non-ASCII character has been found in author string for bibtex (probably a non-handled accentuated letter)." + "Check the new package added and update the function protect_accentuated_letters in Documentation/scripts/generate_how_to_cite.py\n\n" + ) + return res -def make_doc_path(pkg, arg): - if BRANCH_BUILD: - return os.path.join(SOURCE_DIR, pkg, "doc", pkg, arg) - else: - return os.path.join(SOURCE_DIR, "doc", pkg, arg) -### Start of the main function ### +def make_doc_path(pkg, arg, source_dir, branch_build): + if branch_build: + return os.path.join(source_dir, pkg, "doc", pkg, arg) + else: + return os.path.join(source_dir, "doc", pkg, arg) -assert len(argv) == 4, "require exactly three arguments: source_dir, build_dir, branch_build" + ### Start of the main function ### -SOURCE_DIR = argv[1] -BUILD_DIR = argv[2] -BRANCH_BUILD = argv[3] -pattern = re.compile(r"\\package_listing{([^}]*)}") +def main(): + assert ( + len(argv) == 4 + ), "require exactly three arguments: source_dir, build_dir, branch_build" -pattern_title_and_anchor = re.compile(r"\\cgalPkgDescriptionBegin{([^}]*),\s?([^}]*)}") -pattern_author = re.compile(r"\\cgalPkgAuthors?{([^}]*)}") -pattern_bib = re.compile(r"\\cgalPkgBib{([^}]*)}") + source_dir = argv[1] + build_dir = argv[2] + branch_build = argv[3] -f = codecs.open(make_doc_path("Documentation", "packages.txt"), 'r', encoding='utf-8') -k=2 -for line in f: - match = pattern.match(line) - if(match): - pkg = match.group(1) - filename = make_doc_path(pkg, "PackageDescription.txt") - pkgdesc = codecs.open(filename, 'r', encoding='utf-8') - authors="" - bib="" - anchor="" - for pkg_line in pkgdesc: - match = pattern_title_and_anchor.match(pkg_line) + result_txt = RESULT_TXT + result_bib = RESULT_BIB + result_html = RESULT_HTML + + pattern = re.compile(r"\\package_listing{([^}]*)}") + + pattern_title_and_anchor = re.compile( + r"\\cgalPkgDescriptionBegin{([^}]*),\s?([^}]*)}" + ) + pattern_author = re.compile(r"\\cgalPkgAuthors?{([^}]*)}") + pattern_bib = re.compile(r"\\cgalPkgBib{([^}]*)}") + + f = codecs.open( + make_doc_path("Documentation", "packages.txt", source_dir, branch_build), + "r", + encoding="utf-8", + ) + k = 2 + for line in f: + match = pattern.match(line) if match: - title=match.group(1).replace(r'\,',",") - anchor=match.group(2) - continue - match = pattern_author.match(pkg_line) - if match: - authors=match.group(1).replace(", and"," and").replace(","," and") - continue - match = pattern_bib.match(pkg_line) - if match: - bib=match.group(1) - continue - assert len(bib)>0, "Did you forget a \\cgalPkgBib{} in %r?" % filename - assert len(authors)>0, "Did you forget a \\cgalPkgAuthors{} in %r?" % filename - assert len(anchor)>0, "Did you forget the anchor in \\cgalPkgDescriptionBegin{} in %r?" % filename - result_txt+=gen_txt_entry(title, authors, bib, anchor,k) - # convert title and author to bibtex format - title=protect_upper_case(title) - authors=protect_accentuated_letters(authors) - result_bib+=gen_bib_entry(title, authors, bib, anchor) - result_html+=gen_html_entry(title, authors, bib, anchor) - k+=1 + pkg = match.group(1) + filename = make_doc_path( + pkg, "PackageDescription.txt", source_dir, branch_build + ) + pkgdesc = codecs.open(filename, "r", encoding="utf-8") + authors = "" + bib = "" + anchor = "" + for pkg_line in pkgdesc: + match = pattern_title_and_anchor.match(pkg_line) + if match: + title = match.group(1).replace(r"\,", ",") + anchor = match.group(2) + continue + match = pattern_author.match(pkg_line) + if match: + authors = ( + match.group(1).replace(", and", " and").replace(",", " and") + ) + continue + match = pattern_bib.match(pkg_line) + if match: + bib = match.group(1) + continue + assert len(bib) > 0, "Did you forget a \\cgalPkgBib{} in %r?" % filename + assert len(authors) > 0, ( + "Did you forget a \\cgalPkgAuthors{} in %r?" % filename + ) + assert len(anchor) > 0, ( + "Did you forget the anchor in \\cgalPkgDescriptionBegin{} in %r?" + % filename + ) + result_txt += gen_txt_entry(title, authors, bib, anchor, k) + # convert title and author to bibtex format + title = protect_upper_case(title) + authors = protect_accentuated_letters(authors) + result_bib += gen_bib_entry(title, authors, bib, anchor) + result_html += gen_html_entry(title, authors, bib, anchor) + k += 1 -f = codecs.open(BUILD_DIR+"/how_to_cite_cgal.bib.in", 'w', encoding='utf-8') -f.write(result_bib) -result_txt+=result_txt_footer -f = codecs.open(BUILD_DIR+"/how_to_cite_cgal.txt.in", 'w', encoding='utf-8') -f.write(result_txt) -f = codecs.open(BUILD_DIR+"/how_to_cite.html.in", 'w', encoding='utf-8') -f.write(pre_html + result_html + post_html) + f = codecs.open(build_dir + "/how_to_cite_cgal.bib.in", "w", encoding="utf-8") + f.write(result_bib) + result_txt += RESULT_TXT_FOOTER + f = codecs.open(build_dir + "/how_to_cite_cgal.txt.in", "w", encoding="utf-8") + f.write(result_txt) + f = codecs.open(build_dir + "/how_to_cite.html.in", "w", encoding="utf-8") + f.write(PRE_HTML + result_html + POST_HTML) + + +if __name__ == "__main__": + main()