Repository: qutebrowser/qutebrowser
Pull request: Fixed paths in asciidoc2html
closes #5558 

Problem statement:
Running asciidoc2html.py from outside folder
**Version info**:
qutebrowser v1.13.0                            
Git commit: 6e9f24bc8-dirty on master (2020-07-01 15:34:57 +0200)
Backend: QtWebEngine (Chromium 80.0.3987.163)
Qt: 5.15.0  

**Does the bug happen if you start with `--temp-basedir`?**:

**Description**
If one runs `scripts/asciidoc2html.py` (or `script/mkvenv.py`) outside of the folder, this fails since the path are not relative to the root of the repo.

**How to reproduce**
Run `scripts/mkvenv.py` from outside the repo root.

Hints from issue discussion:

Commit message: Fixed paths in asciidoc2html

Patch to review:
diff --git a/scripts/asciidoc2html.py b/scripts/asciidoc2html.py
index e337c54db30..3917ea05397 100755
--- a/scripts/asciidoc2html.py
+++ b/scripts/asciidoc2html.py
@@ -35,7 +35,8 @@
 
 from scripts import utils
 
-DOC_DIR = pathlib.Path("qutebrowser/html/doc")
+REPO_ROOT = pathlib.Path(__file__).parent.parent
+DOC_DIR = pathlib.Path(REPO_ROOT, "qutebrowser/html/doc")
 
 
 class AsciiDoc:
@@ -79,9 +80,9 @@ def build(self) -> None:
 
     def _build_docs(self) -> None:
         """Render .asciidoc files to .html sites."""
-        files = [(pathlib.Path('doc/{}.asciidoc'.format(f)),
+        files = [(pathlib.Path(REPO_ROOT, 'doc/{}.asciidoc'.format(f)),
                   DOC_DIR / (f + ".html")) for f in self.FILES]
-        for src in pathlib.Path('doc/help/').glob('*.asciidoc'):
+        for src in pathlib.Path(REPO_ROOT, 'doc/help/').glob('*.asciidoc'):
             dst = DOC_DIR / (src.stem + ".html")
             files.append((src, dst))
 
@@ -111,7 +112,7 @@ def _copy_images(self) -> None:
         dst_path = DOC_DIR / 'img'
         dst_path.mkdir(exist_ok=True)
         for filename in ['cheatsheet-big.png', 'cheatsheet-small.png']:
-            src = pathlib.Path('doc') / 'img' / filename
+            src = pathlib.Path(REPO_ROOT, 'doc') / 'img' / filename
             dst = dst_path / filename
             shutil.copy(str(src), str(dst))
 
@@ -125,7 +126,7 @@ def _build_website_file(self, root: pathlib.Path, filename: str) -> None:
 
         assert self._tempdir is not None    # for mypy
         modified_src = self._tempdir / src.name
-        shutil.copy('www/header.asciidoc', modified_src)
+        shutil.copy(os.path.join(REPO_ROOT, 'www/header.asciidoc'), modified_src)
 
         outfp = io.StringIO()
 
@@ -181,7 +182,7 @@ def _build_website_file(self, root: pathlib.Path, filename: str) -> None:
 
     def _build_website(self) -> None:
         """Prepare and build the website."""
-        theme_file = (pathlib.Path('www') / 'qute.css').resolve()
+        theme_file = (pathlib.Path(REPO_ROOT, 'www') / 'qute.css').resolve()
         assert self._themedir is not None   # for mypy
         shutil.copy(theme_file, self._themedir)
 
@@ -205,7 +206,7 @@ def _build_website(self) -> None:
 
         for dst, link_name in [
                 ('README.html', 'index.html'),
-                ((pathlib.Path('doc') / 'quickstart.html'),
+                ((pathlib.Path(REPO_ROOT, 'doc') / 'quickstart.html'),
                  'quickstart.html')]:
             assert isinstance(dst, (str, pathlib.Path))    # for mypy
             try:


Code review comments:
diff_hunk: @@ -79,9 +80,9 @@ def build(self) -> None:
 
     def _build_docs(self) -> None:
         """Render .asciidoc files to .html sites."""
-        files = [(pathlib.Path('doc/{}.asciidoc'.format(f)),
+        files = [(pathlib.Path(REPO_ROOT, 'doc/{}.asciidoc'.format(f)),
path: scripts/asciidoc2html.py
text: @user1:
```suggestion
        files = [(REPO_ROOT / 'doc' / '{}.asciidoc'.format(f)),
```

@author:
Done

diff_hunk: @@ -181,7 +182,7 @@ def _build_website_file(self, root: pathlib.Path, filename: str) -> None:
 
     def _build_website(self) -> None:
         """Prepare and build the website."""
-        theme_file = (pathlib.Path('www') / 'qute.css').resolve()
+        theme_file = (pathlib.Path(REPO_ROOT, 'www') / 'qute.css').resolve()
path: scripts/asciidoc2html.py
text: @user1:
```suggestion
        theme_file = REPO_ROOT / 'www' / 'qute.css'
```

@user2:
This line was directly 'translated' (😅) from `os.path` to pathlib.

It used to be `theme_file = os.path.abspath(os.path.join('www', 'qute.css'))`.

Wasn't sure if the `resolve()` could be removed so just wanted to point that out. :-)

@user1:
It might have been needed, but now that we have `REPO_ROOT` as an absolute path, I don't think it is anymore.

diff_hunk: @@ -205,7 +206,7 @@ def _build_website(self) -> None:
 
         for dst, link_name in [
                 ('README.html', 'index.html'),
-                ((pathlib.Path('doc') / 'quickstart.html'),
+                ((pathlib.Path(REPO_ROOT, 'doc') / 'quickstart.html'),
path: scripts/asciidoc2html.py
text: @user1:
```suggestion
                ((REPO_ROOT / 'doc' / 'quickstart.html'),
```

diff_hunk: @@ -35,7 +35,8 @@
 
 from scripts import utils
 
-DOC_DIR = pathlib.Path("qutebrowser/html/doc")
+REPO_ROOT = pathlib.Path(__file__).parent.parent
+DOC_DIR = pathlib.Path(REPO_ROOT, "qutebrowser/html/doc")
path: scripts/asciidoc2html.py
text: @user1:
```suggestion
DOC_DIR = REPO_ROOT / 'qutebrowser' / 'html' / 'doc'
```

@author:
Done

diff_hunk: @@ -125,7 +126,7 @@ def _build_website_file(self, root: pathlib.Path, filename: str) -> None:
 
         assert self._tempdir is not None    # for mypy
         modified_src = self._tempdir / src.name
-        shutil.copy('www/header.asciidoc', modified_src)
+        shutil.copy(os.path.join(REPO_ROOT, 'www/header.asciidoc'), modified_src)
path: scripts/asciidoc2html.py
text: @user1:
```suggestion
        shutil.copy(str(REPO_ROOT / 'www' / 'header.asciidoc'), modified_src)
```

diff_hunk: @@ -79,9 +80,9 @@ def build(self) -> None:
 
     def _build_docs(self) -> None:
         """Render .asciidoc files to .html sites."""
-        files = [(pathlib.Path('doc/{}.asciidoc'.format(f)),
+        files = [(pathlib.Path(REPO_ROOT, 'doc/{}.asciidoc'.format(f)),
                   DOC_DIR / (f + ".html")) for f in self.FILES]
-        for src in pathlib.Path('doc/help/').glob('*.asciidoc'):
+        for src in pathlib.Path(REPO_ROOT, 'doc/help/').glob('*.asciidoc'):
path: scripts/asciidoc2html.py
text: @user1:
```suggestion
        for src in (REPO_ROOT / 'doc' / 'help').glob('*.asciidoc'):
```

diff_hunk: @@ -111,7 +112,7 @@ def _copy_images(self) -> None:
         dst_path = DOC_DIR / 'img'
         dst_path.mkdir(exist_ok=True)
         for filename in ['cheatsheet-big.png', 'cheatsheet-small.png']:
-            src = pathlib.Path('doc') / 'img' / filename
+            src = pathlib.Path(REPO_ROOT, 'doc') / 'img' / filename
path: scripts/asciidoc2html.py
text: @user1:
```suggestion
            src = REPO_ROOT / 'doc' / 'img' / filename
```