oprypin / mkdocs-gen-files

MkDocs plugin to programmatically generate documentation pages during the build
https://oprypin.github.io/mkdocs-gen-files
MIT License
107 stars 10 forks source link

[Question] What process runs the `make_pages.py` script? #18

Closed CBroz1 closed 1 year ago

CBroz1 commented 1 year ago

In short, I'm looking for the command that triggers the make_pages.py to improve my error handling when building with docker.

For context, I'm using the make_pages.py script to git clone multiple repos when I build the docs. I'm using the structure below, which works for repos that exist, and correctly fails for repos that don't exist, but can't handle private repos. I'd like to keep some repos private until I'm ready to publish, and just rebuild at that time.

import mkdocs_gen_files
from pathlib import Path
import subprocess

for REPO in my_list:
  if not Path(REPO).is_dir():
    try:
        subprocess.run(
            f"git clone https://github.com/{ORG}/{REPO}.git /main/".split(
                " "
            ),
            check=True,
        )
       # Other mv/rm commands removed for simplification
    except subprocess.CalledProcessError:
        pass  

If the repo doesn't exist, my except works well. If it's private, however, I see the following in my docker console

fatal: could not read Username for 'https://github.com/': No such device or address

I'm trying to track down the parent process to replicate the error better except the error type. If I try launching make_pages from a python terminal, it prompts me to enter in credentials.

CBroz1 commented 1 year ago

As a temporary fix, I plan to add a timeout to my subprocess.run call.

oprypin commented 1 year ago

Hi. When you run mkdocs, that's just a wrapper for python -m mkdocs. There's only one process involved - that's Python. So there's nothing weird about processes here. But I think the part that's missing from the other setup is that in one case you have a real terminal backing the process, and in the other case it's a piped output. To also get that effect, instead of mkdocs build you could run mkdocs build | cat or some other way to remove the terminal.

As a separate comment, mkdocs-gen-files is not a solution intended for just adding custom Python code into a mkdocs build. You should be using mkdocs_gen_files.open at least once, otherwise its functionality remains almost entirely unused. import mkdocs_gen_files could be dropped from your script with no difference. Instead, just use MkDocs' hooks: config in a similar way: https://www.mkdocs.org/user-guide/configuration/#hooks -then you'll just need to wrap your main code into def on_config(config):

oprypin commented 1 year ago

I closed the issue but we can still continue to discuss if something is unclear

CBroz1 commented 1 year ago

Thanks for your insights @oprypin! I'll try piping to cat to see what I find. Sorry for the miscommunication - I oversimplified above. Our full script does run mkdocs_gen_files.open after the snippet I posted above.