From a80d2d38db3dc15981c1909421d9e96173fd9b38 Mon Sep 17 00:00:00 2001 From: Julin S <48789920+ju-sh@users.noreply.github.com> Date: Sun, 21 Jun 2020 16:09:23 +0530 Subject: [PATCH 1/4] Fix 3.5 incompatibility in script --- scripts/asciidoc2html.py | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/scripts/asciidoc2html.py b/scripts/asciidoc2html.py index 2f64eac52..72be2ac21 100755 --- a/scripts/asciidoc2html.py +++ b/scripts/asciidoc2html.py @@ -68,7 +68,7 @@ class AsciiDoc: def cleanup(self) -> None: """Clean up the temporary home directory for asciidoc.""" if self._homedir is not None and not self._failed: - shutil.rmtree(self._homedir) + shutil.rmtree(str(self._homedir)) def build(self) -> None: """Build either the website or the docs.""" @@ -98,12 +98,12 @@ class AsciiDoc: for src, dst in files: assert self._tempdir is not None # for mypy modified_src = self._tempdir / src.name - with open(modified_src, 'w', encoding='utf-8') as modified_f, \ - open(src, 'r', encoding='utf-8') as f: + with open(str(modified_src), 'w', encoding='utf-8') as moded_f, \ + open(str(src), 'r', encoding='utf-8') as f: for line in f: for orig, repl in replacements: line = line.replace(orig, repl) - modified_f.write(line) + moded_f.write(line) self.call(modified_src, dst, *asciidoc_args) def _copy_images(self) -> None: @@ -114,7 +114,7 @@ class AsciiDoc: for filename in ['cheatsheet-big.png', 'cheatsheet-small.png']: src = pathlib.Path('doc') / 'img' / filename dst = dst_path / filename - shutil.copy(src, dst) + shutil.copy(str(src), str(dst)) def _build_website_file(self, root: pathlib.Path, filename: str) -> None: """Build a single website file.""" @@ -130,11 +130,11 @@ class AsciiDoc: outfp = io.StringIO() - with open(modified_src, 'r', encoding='utf-8') as header_file: + with open(str(modified_src), 'r', encoding='utf-8') as header_file: header = header_file.read() header += "\n\n" - with open(src, 'r', encoding='utf-8') as infp: + with open(str(src), 'r', encoding='utf-8') as infp: outfp.write("\n\n") hidden = False found_title = False @@ -259,8 +259,9 @@ class AsciiDoc: subprocess.run(cmdline, check=True, env=env) except (subprocess.CalledProcessError, OSError) as e: self._failed = True - utils.print_col(str(e), 'red') - print("Keeping modified sources in {}.".format(self._homedir)) + utils.print_error(str(e)) + print("Keeping modified sources in {}.".format(self._homedir), + file=sys.stderr) sys.exit(1) @@ -284,9 +285,9 @@ def run(**kwargs) -> None: try: asciidoc.prepare() except FileNotFoundError: - utils.print_col("Could not find asciidoc! Please install it, or use " - "the --asciidoc argument to point this script to the " - "correct python/asciidoc.py location!", 'red') + utils.print_error("Could not find asciidoc! Please install it, or use " + "the --asciidoc argument to point this script to " + "the correct python/asciidoc.py location!") sys.exit(1) try: From 4bf3556178efe1c53418c8f81a83b7c1306bf1bb Mon Sep 17 00:00:00 2001 From: Julin S <48789920+ju-sh@users.noreply.github.com> Date: Mon, 22 Jun 2020 01:23:13 +0530 Subject: [PATCH 2/4] Revert "fix error in asciidoc2html.py script" This reverts commit 64ffce27f9348e14836528c0313d3048669a29c7. --- scripts/asciidoc2html.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/asciidoc2html.py b/scripts/asciidoc2html.py index 72be2ac21..013c7ad4e 100755 --- a/scripts/asciidoc2html.py +++ b/scripts/asciidoc2html.py @@ -121,7 +121,7 @@ class AsciiDoc: src = root / filename assert self._website is not None # for mypy dst = pathlib.Path(self._website) - dst = dst / src.parent.relative_to('.') / (src.stem + ".html") + dst = src.parent.relative_to('.') / (src.stem + ".html") dst.parent.mkdir(exist_ok=True) assert self._tempdir is not None # for mypy From 969a99ce6d3da6a3c2ce679680a1e1b528996add Mon Sep 17 00:00:00 2001 From: Julin S <48789920+ju-sh@users.noreply.github.com> Date: Mon, 22 Jun 2020 01:56:08 +0530 Subject: [PATCH 3/4] use Path.read_text --- scripts/asciidoc2html.py | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/scripts/asciidoc2html.py b/scripts/asciidoc2html.py index 013c7ad4e..c2737b2ce 100755 --- a/scripts/asciidoc2html.py +++ b/scripts/asciidoc2html.py @@ -23,7 +23,6 @@ from typing import List, Optional import re import os -import os.path import sys import subprocess import shutil @@ -32,7 +31,7 @@ import argparse import io import pathlib -sys.path.insert(0, os.path.join(os.path.dirname(__file__), os.pardir)) +sys.path.insert(0, str(pathlib.Path(__file__).parents[1])) from scripts import utils @@ -98,8 +97,8 @@ class AsciiDoc: for src, dst in files: assert self._tempdir is not None # for mypy modified_src = self._tempdir / src.name - with open(str(modified_src), 'w', encoding='utf-8') as moded_f, \ - open(str(src), 'r', encoding='utf-8') as f: + with modified_src.open('w', encoding='utf-8') as moded_f, \ + src.open('r', encoding='utf-8') as f: for line in f: for orig, repl in replacements: line = line.replace(orig, repl) @@ -130,11 +129,10 @@ class AsciiDoc: outfp = io.StringIO() - with open(str(modified_src), 'r', encoding='utf-8') as header_file: - header = header_file.read() - header += "\n\n" + header = modified_src.read_text(encoding='utf-8') + header += "\n\n" - with open(str(src), 'r', encoding='utf-8') as infp: + with src.open('r', encoding='utf-8') as infp: outfp.write("\n\n") hidden = False found_title = False @@ -174,8 +172,8 @@ class AsciiDoc: current_lines = outfp.getvalue() outfp.close() - with open(modified_src, 'w+', encoding='utf-8') as final_version: - final_version.write(title + "\n\n" + header + current_lines) + modified_str = title + "\n\n" + header + current_lines + modified_src.write_text(modified_str, encoding='utf-8') asciidoc_args = ['--theme=qute', '-a toc', '-a toc-placement=manual', '-a', 'source-highlighter=pygments'] From 6cbf7e3976ea51b0375a27974b60768fb01a2c2d Mon Sep 17 00:00:00 2001 From: Julin S <48789920+ju-sh@users.noreply.github.com> Date: Wed, 24 Jun 2020 11:29:27 +0530 Subject: [PATCH 4/4] redo old edit --- scripts/asciidoc2html.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/asciidoc2html.py b/scripts/asciidoc2html.py index c2737b2ce..194293a6e 100755 --- a/scripts/asciidoc2html.py +++ b/scripts/asciidoc2html.py @@ -120,7 +120,7 @@ class AsciiDoc: src = root / filename assert self._website is not None # for mypy dst = pathlib.Path(self._website) - dst = src.parent.relative_to('.') / (src.stem + ".html") + dst = dst / src.parent.relative_to('.') / (src.stem + ".html") dst.parent.mkdir(exist_ok=True) assert self._tempdir is not None # for mypy