Search code examples
pythoncommand-promptread-the-docs

read-the-docs build fails because of prompt


I am developing a Python package which, on first use, creates a config file for the user. During this setup phase, the user is asked for input during two prompts. Corresponding calls are in the module's __init__.py. Because of this prompt, my builds on readthedocs fail (log).

How can I build my documentation nonetheles? Why is readthedocs trying to compile the code anyways?


Solution

  • The problem is you are importing your module in conf.py:

    project_root = os.path.dirname(cwd)
    sys.path.insert(0, project_root)
    
    import scopus  # <-- imported
    
    # General configuration
    needs_sphinx = '1.3'
    extensions = [
    

    And your project is not constrcuted well. I don't think just importing your module will cause prompt is a good idea.

    import scopus  ->  
    from scopus.utils import *  ->  
    from scopus.utils.startup import *  ->    
    ....
    if 'Authentication' not in config.sections():
        set_authentication(config, CONFIG_FILE)  # <-- cause prompt
    ....
    

    Addtionally, even worse:

    CONFIG_FILE = os.path.expanduser("~/.scopus/config.ini")
    config = configparser.ConfigParser()
    config.optionxform = str
    config.read(CONFIG_FILE)
    

    Reading file system.