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

Fix QLLexer instance as argument to add_lexer #11353

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

mbg
Copy link
Member

@mbg mbg commented Nov 21, 2022

add_lexer requires a type as argument in versions of sphinx >= 2.1 (docs). Currently, an instance of QLLexer is passed to it, which causes the docs build to fail if a version of Sphinx >= 3 is used. This PR fixes this so that the documentation can be built successfully.

@mbg mbg self-assigned this Nov 21, 2022
from qllexer import QLLexer
sphinx.add_lexer("ql", QLLexer())
sphinx.add_lexer("ql", QLLexer)
Copy link
Collaborator

@adityasharad adityasharad Nov 22, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try this. The callable builtin should tell us whether an object is indeed callable. This way we can remain robust to different versions of Sphinx + pygments being installed, without breaking either local or CI usage.

Suggested change
sphinx.add_lexer("ql", QLLexer)
sphinx.add_lexer("ql", QLLexer() if callable(QLLexer) else QLLexer)

There are actually 3 places in the code we make this call:

  • docs/codeql/conf.py (here)
  • docs/codeql/ql-training/conf.py
  • documentation/restructuredtext/codeql-cli/conf.py within the internal repo

Would you mind updating the first 2 locations in this PR, and then we can tackle the third in an internal PR?

Copy link
Member Author

@mbg mbg Nov 22, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestion! Unfortunately, this fails with:

Exception occurred:
  File "/opt/homebrew/lib/python3.10/site-packages/sphinx/highlighting.py", line 130, in get_lexer
    lexer = lexer_classes[lang](**opts)
TypeError: 'QLLexer' object is not callable

I think the problem may be that QLLexer is callable regardless of the Sphinx version used. It is just add_lexer that has different expectations of how you pass the lexer in, depending on the version.

Copy link
Collaborator

@adityasharad adityasharad Nov 22, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmph yes good point. Thank you for trying. I wonder if we can detect from within Python what the Sphinx version is? If not I think the principled solution is the one in the internal issue - pin to a specific version of the packages.

mbg and others added 2 commits Nov 22, 2022
Co-authored-by: Aditya Sharad <6874315+adityasharad@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants