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

generate citation_reference nodes for rinoh builder #291

Merged
merged 16 commits into from Apr 11, 2022

Conversation

mcmtroffaes
Copy link
Owner

@brechtm Take 3 as discussed.

I do have one issue that I cannot run the rinoh builder to test this, getting this error:

...\test\roots\test-citation_rinoh> python -m sphinx -b rinoh . _build/
    return _compile(pattern, flags).sub(repl, string, count)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: expected string or bytes-like object, got 'NoneType'
The full traceback has been saved in ***\sphinx-err-9ca3m_zd.log, if you want to report the issue to the developers.
Please also report this if it was a user error, so that a better error message can be provided next time.
A bug report can be filed in the tracker at <https://github.com/sphinx-doc/sphinx/issues>. Thanks!

Here's the full log. Any clue?

# Sphinx version: 4.4.0
# Python version: 3.11.0a5 (CPython)
# Docutils version: 0.17.1 release
# Jinja2 version: 3.0.3
# Last messages:

# Loaded extensions:
Traceback (most recent call last):
  File "***\Python311\Lib\contextlib.py", line 155, in __exit__
    self.gen.throw(typ, value, traceback)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "***\Python311\Lib\contextlib.py", line 155, in __exit__
    self.gen.throw(typ, value, traceback)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "***\sphinxcontrib-bibtex\venv311\Lib\site-packages\sphinx\util\docutils.py", line 140, in patched_get_language
    yield
    ^^^^^
  File "***\Python311\Lib\contextlib.py", line 155, in __exit__
    self.gen.throw(typ, value, traceback)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "***\sphinxcontrib-bibtex\venv311\Lib\site-packages\sphinx\util\docutils.py", line 154, in using_user_docutils_conf
    yield
    ^^^^^
  File "***\sphinxcontrib-bibtex\venv311\Lib\site-packages\sphinx\util\docutils.py", line 166, in patch_docutils
    yield
    ^^^^^
  File "***\Python311\Lib\contextlib.py", line 155, in __exit__
    self.gen.throw(typ, value, traceback)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "***\sphinxcontrib-bibtex\venv311\Lib\site-packages\sphinx\util\docutils.py", line 55, in docutils_namespace
    yield
    ^^^^^
  File "***\sphinxcontrib-bibtex\venv311\Lib\site-packages\sphinx\cmd\build.py", line 280, in build_main
    app = Sphinx(args.sourcedir, args.confdir, args.outputdir,
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "***\sphinxcontrib-bibtex\venv311\Lib\site-packages\sphinx\application.py", line 230, in __init__
    self.setup_extension(extension)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "***\sphinxcontrib-bibtex\venv311\Lib\site-packages\sphinx\application.py", line 387, in setup_extension
    self.registry.load_extension(self, extname)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "***\Python311\Lib\contextlib.py", line 155, in __exit__
    self.gen.throw(typ, value, traceback)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "***\sphinxcontrib-bibtex\venv311\Lib\site-packages\sphinx\util\logging.py", line 338, in prefixed_warnings
    yield
    ^^^^^
  File "***\sphinxcontrib-bibtex\venv311\Lib\site-packages\sphinx\registry.py", line 433, in load_extension
    mod = import_module(extname)
          ^^^^^^^^^^^^^^^^^^^^^^
  File "***\Python311\Lib\importlib\__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 1206, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1178, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1128, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 1206, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1178, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1128, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 1206, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1178, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1149, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 924, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "***\sphinxcontrib-bibtex\venv311\Lib\site-packages\rinoh\__init__.py", line 41, in <module>
    from . import resource
    ^^^^^^^^^^^^^^^^^^^^^^
  File "***\sphinxcontrib-bibtex\venv311\Lib\site-packages\rinoh\resource.py", line 205, in <module>
    from .template import DocumentTemplate
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "***\sphinxcontrib-bibtex\venv311\Lib\site-packages\rinoh\template.py", line 42, in <module>
    from .stylesheets import sphinx
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "***\sphinxcontrib-bibtex\venv311\Lib\site-packages\rinoh\stylesheets\__init__.py", line 42, in <module>
    .format(stylesheet.description, stylesheet))
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "***\sphinxcontrib-bibtex\venv311\Lib\site-packages\rinoh\style.py", line 670, in __str__
    for name, entry_point in self.installed_resources:
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "***\sphinxcontrib-bibtex\venv311\Lib\site-packages\rinoh\resource.py", line 54, in installed_resources
    for entry_point in ilm.entry_points()[cls.entry_point_group]:
                       ^^^^^^^^^^^^^^^^^^
  File "***\Python311\Lib\importlib\metadata\__init__.py", line 993, in entry_points
    return SelectableGroups.load(eps).select(**params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "***\Python311\Lib\importlib\metadata\__init__.py", line 448, in load
    ordered = sorted(eps, key=by_group)
              ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "***\Python311\Lib\importlib\metadata\__init__.py", line 990, in <genexpr>
    eps = itertools.chain.from_iterable(
                                       ^
  File "***\Python311\Lib\importlib\metadata\_itertools.py", line 16, in unique_everseen
    k = key(element)
        ^^^^^^^^^^^^
  File "***\Python311\Lib\importlib\metadata\__init__.py", line 599, in _normalized_name
    return Prepared.normalize(self.name)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "***\Python311\Lib\importlib\metadata\__init__.py", line 855, in normalize
    return re.sub(r"[-_.]+", "-", name).lower().replace('-', '_')
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "***\Python311\Lib\re.py", line 189, in sub
    return _compile(pattern, flags).sub(repl, string, count)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: expected string or bytes-like object, got 'NoneType'

@brechtm
Copy link

brechtm commented Mar 28, 2022

I think this is fixed in master. I'm planning on making a new release soon, but you can try with

pip install https://github.com/brechtm/rinohtype/archive/refs/heads/master.zip

@mcmtroffaes
Copy link
Owner Author

The refid appeared to be wrong. I got this working in the final patch by using just info.citation_id instead of f'%{info.todocname}#{info.citation_id}' but I suspect this will break references across documents. What attributes is rinohtype expecting for citation references across documents? Also, is there a simple way to verify the output e.g. can it output html instead of pdf?

@codecov
Copy link

codecov bot commented Mar 28, 2022

Codecov Report

Merging #291 (565f67c) into develop (eece8c4) will not change coverage.
The diff coverage is 100.00%.

@@            Coverage Diff            @@
##           develop      #291   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           51        52    +1     
  Lines         2399      2428   +29     
  Branches       418       425    +7     
=========================================
+ Hits          2399      2428   +29     
Impacted Files Coverage Δ
src/sphinxcontrib/bibtex/style/template.py 100.00% <100.00%> (ø)
test/test_citation_rinoh.py 100.00% <100.00%> (ø)
test/common.py 100.00% <0.00%> (ø)
test/test_autodoc.py 100.00% <0.00%> (ø)
test/test_numpydoc.py 100.00% <0.00%> (ø)
src/sphinxcontrib/bibtex/domain.py 100.00% <0.00%> (ø)
src/sphinxcontrib/bibtex/foot_roles.py 100.00% <0.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update eece8c4...565f67c. Read the comment docs.

@mcmtroffaes
Copy link
Owner Author

I wrapped up the last test now to check behaviour of citations across documents, and using the proper refid for that case. Looks like there's a bug in rinohtype in that it refuses to resolve citation refid's across documents @brechtm - this appears to be a bug on rinohtype's end unless I somehow missed something. You can test it here (with the code from this PR):

https://github.com/mcmtroffaes/sphinxcontrib-bibtex/tree/feature/generate-citation-reference-3/test/roots/test-citation_rinoh_multidoc

The same problem might have tripped in #291 (comment)

@brechtm
Copy link

brechtm commented Apr 11, 2022

this appears to be a bug on rinohtype's end unless I somehow missed something.

You are correct, this was broken for citations defined in the Sphinx master document (typically index.rst). Also for the Sphinx/docutuls built-in citations. I fixed this in the master branch (brechtm/rinohtype@05447c8). refid for the rinoh builder sphinxcontrib-bibtex's template.py needs to be set to the following though:

refid = f'%{info.todocname}#{info.citation_id}'

Also, is there a simple way to verify the output e.g. can it output html instead of pdf?

No, there is only PDF output. I saw you were using the stylelog; I hope that's sufficient? For rinohtype development, I have a PDF diff script, but the dependencies make this often a pain to keep running on GitHub actions, so I cannot recommend this. A simpler alternative would be to extract the text with pdftotext (poppler), but that also introduces an extra dependency...

@mcmtroffaes
Copy link
Owner Author

You are correct, this was broken for citations defined in the Sphinx master document (typically index.rst). Also for the Sphinx/docutuls built-in citations. I fixed this in the master branch (brechtm/rinohtype@05447c8).

Thank you for fixing - it's working now.

Also, is there a simple way to verify the output e.g. can it output html instead of pdf?

No, there is only PDF output. I saw you were using the stylelog; I hope that's sufficient?

Aye, when I asked, I did not know about the stylelog. It's enough to have this cursory check that the references are present.

@mcmtroffaes mcmtroffaes merged commit 0c496c1 into develop Apr 11, 2022
@mcmtroffaes mcmtroffaes deleted the feature/generate-citation-reference-3 branch April 11, 2022 14:39
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 this pull request may close these issues.

None yet

2 participants