glyph / automat

Self-service finite-state machines for the programmer on the go.
MIT License
591 stars 65 forks source link

Docs Don't Build Outside of a Git Checkout #162

Open damaestro opened 21 hours ago

damaestro commented 21 hours ago

When downloading a repo archive or the source from PyPI, the docs wont build due to not being able to run git commands.

+ PYTHONPATH=src
+ sphinx-build docs html
Running Sphinx v7.3.7

Configuration error:
There is a programmable error in your configuration file:

Traceback (most recent call last):
  File "/usr/lib/python3.13/site-packages/sphinx/config.py", line 509, in eval_config_file
    exec(code, namespace)  # NoQA: S102
    ~~~~^^^^^^^^^^^^^^^^^
  File "/builddir/build/BUILD/python-Automat-24.8.1-build/automat-24.8.1/docs/conf.py", line 47, in <module>
    _git_reference = subprocess.run(
                     ~~~~~~~~~~~~~~^
        ["git", "rev-parse", "--abbrev-ref", "HEAD"],
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    ...<3 lines>...
        check=True,
        ^^^^^^^^^^^
    ).stdout
    ^
  File "/usr/lib64/python3.13/subprocess.py", line 577, in run
    raise CalledProcessError(retcode, process.args,
                             output=stdout, stderr=stderr)
subprocess.CalledProcessError: Command '['git', 'rev-parse', '--abbrev-ref', 'HEAD']' returned non-zero exit status 128.
glyph commented 14 hours ago

The docs are attempting to build their own viewsource URL that corresponds to the place that the code is coming from. It seems to me that the right way to do this for a source checkout is to interrogate the version that the source claims to be respresenting, then compute a viewsource URL derived from the named tag it should correspond to.

Alternately, move all git command executions onto the path where they will actually be used, i.e. ensure that we do not invoke them at all on the READTHEDOCS_VERSION code path, then builders can use that?

I am open to other suggestions.

damaestro commented 9 hours ago

An option to be able to pass in the tag/version would also be fine. That's basically what I've done manually in a downstream patch. If we could just pass the package version to the sphinx-build command and then the git commands are not attempted that would work.