Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

yosys docs vs. downstream distro-package maintainability #4725

Open
gsomlo opened this issue Nov 9, 2024 · 8 comments · May be fixed by #4730
Open

yosys docs vs. downstream distro-package maintainability #4725

gsomlo opened this issue Nov 9, 2024 · 8 comments · May be fixed by #4730
Assignees

Comments

@gsomlo
Copy link
Contributor

gsomlo commented Nov 9, 2024

Link to page

http://mirror.ini.cmu.edu/0003-fedora-yosys-doc-offline-patch.patch

Build number

a66e94c ("Docs: Switch to furo-ys")

Issue

Hi,

I maintain the yosys package in Fedora, and I'm running into a bit of trouble building the documentation portion of the package.

As you may be aware, distro-packaging requires the assumption of everything being available for an offline build at compile time (i.e., fetching things from a live internet server during build via e.g. wget or curl is forbidden). Also, bundling other existing packages is (heavily) frowned upon.

Side note: since yosys is the primary "consumer" of abc, we were able to justify packaging the yosys fork of abc in Fedora instead of the "true" upstream one, so that's one bullet dodged, but now I'm running into trouble with the documentation portion of the package:

First, I had to patch out the various badge.svg images which are fetched directly over the Internet during build time (this is the patch I'm applying for reference). So far, so good (the resulting pdf file may look a bit rough as a result, but the important content is still there).

However, with commit a66e94c5d ("Docs: Switch to furo-ys") I'm finally finding myself in a bit of a pickle.

Normally, python dependencies should be their own .rpm package, and funny enough, there's a python3-furo RPM already in the Fedora repositories. Unfortunately, use of the furo_ys fork presents a challenge for distro-packaging yosys:

  • since the docs are shipped as part of the package, they should be built from source; side-loading a pdf doc file built elsewhere violates at least the spirit, if not the letter as well, of the Fedora packaging guidelines

  • since building the docs now depends on furo-ys, that should come as its own RPM (and the "standard" furo actually does, but here we're using a fork, and this time I can't argue that the standard package should be replaced with furo-ys :(

  • I could try to bundle furo-ys sources with the yosys source RPM, build it, install it and then use it during make docs portion of building yosys, but at this point things start to look rather contrived, and doing any more of this sort of thing would quickly become unsustainable

I'm wondering if there's another way that would ease downstream distro packaging without imposing too much additional hardship on maintaining the upstream documentation (e.g. limiting/eliminating "live" dependencies fetched over the network at build time, and also limiting/eliminating forked/bundled dependencies as much as possible) -- to the extent that downstream packages are considered useful by upstream maintainers.

Any ideas or advice much appreciated!

Thanks,
--Gabriel

Expected

No response

@gsomlo gsomlo added the pending-verification This issue is pending verification and/or reproduction label Nov 9, 2024
@KrystalDelusion
Copy link
Member

Firstly, thanks for your work maintaining the Fedora package!

I didn't actually expect the pdf version of the docs to download the status badges at compile time, and should probably be html only. I will look into that and hopefully make your patch unnecessary :)

When we switched to using the Furo-ys fork there was a discussion about whether or not we want to maintain a pypi package but this was decided against since the fork is really only intended for YosysHQ use for consistent branding and reducing code duplication across our various projects. However most of that is focused on the html version of the docs used for the readthedocs. My suggestion would be to ignore furo-ys completely. I believe Furo only affects the html theming (html_theme = 'furo-ys' in conf.py), so for building the pdf that shouldn't make a difference. As a python package, furo_ys does currently provide the YoscryptLexer used to format yosys script code blocks; causing these to render without syntax highlighting is a regression but I think an acceptable one if it means saving on the hassle of figuring out how to include the forked package. Note that if you are using the existing makefiles to build the documentation it will fail on warnings, and missing the YoscryptLexer will raise a number of warnings; so you might want to override the SPHINXOPTS variable.

One other thing I will note is that docs/source/conf.py currently only checks for if os.getenv("READTHEDOCS"): to determine if it is a preview-style build or a release-style build. The former renders todo blocks which should be skipped for a release-style build (which I imagine the Fedora package as being), and can also affect the rendering of the version number (e.g. 0.47 vs 0.47-dev which we use to distinguish between latest and stable on read the docs). I would be more than happy to include another environment variable check or similar that can be used for packages like this if you have any suggestions of what that would be, rather than requiring you to patch it specifically for Fedora.

@KrystalDelusion
Copy link
Member

If you want to modify the YoscryptLexer import to not error on a failed import instead of just patching it out I would also happily upstream that.

@gsomlo
Copy link
Contributor Author

gsomlo commented Nov 10, 2024

Hi @KrystalDelusion

Thanks for the quick reply! I am indeed only concerned with the ability to build the pdf manual in an isolated, off-line container (I was going to ask if picking some other format besides pdf would be a better option, but glad to hear pdf is still your recommendation :)

Right now, my command line is:

make ABCEXTERNAL=/bin/abc DOC_TARGET=latexpdf docs

(note: as mentioned earlier, /bin/abc is provided by the yosyshq-abc fedora package (built from the current yosyshq fork), and is required to match the version of the yosys being built).

The error I get is this:

[...]
make[1]: Entering directory '/builddir/build/BUILD/yosys-0.47-build/yosys-f20f913223c42fce6ecc4382b281cf67952e0a72/docs'
sphinx-build -b latex -d build/doctrees  -W --keep-going source build/latex
Running Sphinx v7.3.7

Exception occurred:
  File "/builddir/build/BUILD/yosys-0.47-build/yosys-f20f913223c42fce6ecc4382b281cf67952e0a72/docs/source/conf.py", line 90, in setup
    from furo_ys.lexers.YoscryptLexer import YoscryptLexer
ModuleNotFoundError: No module named 'furo_ys'
[...]

I'll have to study the sources and build scripts (and probably acquire some sort of superficial familiarity with sphinx) to get to the bottom of how I could express that "furo-ys shouldn't be required/expected when $DOC_TARGET is set to latexpdf". Once I figure it out, I'll post a PR and link it to this issue (Please feel free to pre-empt me if you know of a super-quick, obvious way to accomplish that :)

Also thanks in advance for looking into the badges (not) being pulled in while DOC_TARGET=latexpdf!

Best,
--Gabriel

@gsomlo
Copy link
Contributor Author

gsomlo commented Nov 10, 2024

oh, based on your earlier suggestions I'm experimenting with something along these lines:

diff --git a/docs/source/conf.py b/docs/source/conf.py
index 0de8cd445..c1f732901 100644
--- a/docs/source/conf.py
+++ b/docs/source/conf.py
@@ -87,5 +87,6 @@ def setup(app: Sphinx) -> None:
     from util.RtlilLexer import RtlilLexer
     app.add_lexer("RTLIL", RtlilLexer)

-    from furo_ys.lexers.YoscryptLexer import YoscryptLexer
-    app.add_lexer("yoscrypt", YoscryptLexer)
+    if os.getenv("DOC_TARGET") != "latexpdf":
+        from furo_ys.lexers.YoscryptLexer import YoscryptLexer
+        app.add_lexer("yoscrypt", YoscryptLexer)

I'll see if this takes care of things for me, then I'll ask you if it's something you might find palatable for the general case... :D

@KrystalDelusion
Copy link
Member

I would probably suggest something like the following

    try:
        from furo_ys.lexers.YoscryptLexer import YoscryptLexer
        app.add_lexer("yoscrypt", YoscryptLexer)
    except ModuleNotFoundError:
        from pygments.lexers.special import TextLexer
        app.add_lexer("yoscrypt", TextLexer)

The except should also prevent any errors due to yoscrypt being left undefined without having to change SPHINXOPTS.

@gsomlo
Copy link
Contributor Author

gsomlo commented Nov 11, 2024

Thanks, that worked perfectly. I guess you don't need me to put in a PR anymore (but LMK if there's some workflow related reason why that might still be helpful)

@KrystalDelusion KrystalDelusion removed the pending-verification This issue is pending verification and/or reproduction label Nov 12, 2024
@KrystalDelusion KrystalDelusion self-assigned this Nov 12, 2024
KrystalDelusion added a commit that referenced this issue Nov 12, 2024
This is mainly intended for (latex)pdf builds which do not use the furo-ys html theme, where the yosys script syntax highlighting can safely fallback to plaintext.  This effectively makes `furo-ys` an optional dependency to simplify distro-package maintainability.
See also #4725.
@KrystalDelusion KrystalDelusion linked a pull request Nov 12, 2024 that will close this issue
3 tasks
@KrystalDelusion KrystalDelusion linked a pull request Nov 12, 2024 that will close this issue
3 tasks
@KrystalDelusion
Copy link
Member

Do you know if there are any common environment variables that are used during package builds like this? Ideally something not Fedora specific. Or would a yosys specific flag be better? I am looking for something that would fit in the following code before the final else in order to prevent including todos for packaged documentation.

# set version
if os.getenv("READTHEDOCS"):
rtds_version = os.getenv("READTHEDOCS_VERSION")
if rtds_version == "latest":
release = yosys_ver + "-dev"
todo_include_todos = False
elif rtds_version.startswith("docs"):
release = rtds_version
todo_include_todos = True
else:
release = yosys_ver
todo_include_todos = False
else:
release = yosys_ver
todo_include_todos = True

@gsomlo
Copy link
Contributor Author

gsomlo commented Nov 12, 2024

I haven't stared at conf.py long enough to understand how adding a new branch to that outer if os.getenv(...) test would work in concert with the (working, at least for me) patch in #4725 (comment). But here (mock-build-env.log) is the output of running env just before the command building the (pdf) documentation as part of the RPM package via the following line:

make ABCEXTERNAL=%{_bindir}/abc DOC_TARGET=latexpdf docs

With any luck, one of those might make sense...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants