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 non ascii object members #153

Merged
merged 8 commits into from Aug 8, 2022
Merged

Fix non ascii object members #153

merged 8 commits into from Aug 8, 2022

Conversation

m-rossi
Copy link
Contributor

@m-rossi m-rossi commented Jul 31, 2022

I just had an issue with non-ascii-characters in class members (in my case its a column name of a database I access with SQLAlchemy). This PR sets a default encoding for open() as the default seems to be os-dependent, howevers sphinx expects utf8. This fixes my issues on Windows.

I also tried to modify the non-ascii-testcase, however this seems to pass without my fix. If I execute normal sphinx-build during command-line it fails:

sphinx-build . _build
Sphinx v5.1.1 in Verwendung
making output directory... erledigt
loading intersphinx inventory from https://docs.python.org/3/objects.inv...
[autosummary] generating autosummary for: index.rst
[automodsumm] index.rst: found 4 automodsumm entries to generate
building [mo]: targets for 0 po files that are out of date
building [html]: targets for 1 source files that are out of date
updating environment: [new config] 5 added, 0 changed, 0 removed
reading sources... [100%] index                                                onAsciit
C:\Users\USER\path\to\test\api\sphinx_automodapi.tests.example_module.nonascii.NonAscii.rst:13: WARNING: undecodable source characters, replacing with "?": b'      ~NonAscii.get_>>>\xdf<<<\r'
C:\Users\USER\path\to\test\api\sphinx_automodapi.tests.example_module.nonascii.NonAscii.rst:14: WARNING: undecodable source characters, replacing with "?": b'      ~NonAscii.get_>>>\xe4<<<\xf6\xfc\r'
C:\Users\USER\path\to\test\api\sphinx_automodapi.tests.example_module.nonascii.NonAscii.rst:14: WARNING: undecodable source characters, replacing with "?": b'      ~NonAscii.get_\xe4>>>\xf6<<<\xfc\r'
C:\Users\USER\path\to\test\api\sphinx_automodapi.tests.example_module.nonascii.NonAscii.rst:14: WARNING: undecodable source characters, replacing with "?": b'      ~NonAscii.get_\xe4\xf6>>>\xfc<<<\r'
C:\Users\USER\path\to\test\api\sphinx_automodapi.tests.example_module.nonascii.NonAscii.rst:18: WARNING: undecodable source characters, replacing with "?": b'   .. automethod:: get_>>>\xdf<<<\r'
C:\Users\USER\path\to\test\api\sphinx_automodapi.tests.example_module.nonascii.NonAscii.rst:19: WARNING: undecodable source characters, replacing with "?": b'   .. automethod:: get_>>>\xe4<<<\xf6\xfc\r'
C:\Users\USER\path\to\test\api\sphinx_automodapi.tests.example_module.nonascii.NonAscii.rst:19: WARNING: undecodable source characters, replacing with "?": b'   .. automethod:: get_\xe4>>>\xf6<<<\xfc\r'
C:\Users\USER\path\to\test\api\sphinx_automodapi.tests.example_module.nonascii.NonAscii.rst:19: WARNING: undecodable source characters, replacing with "?": b'   .. automethod:: get_\xe4\xf6>>>\xfc<<<\r'
C:\Users\USER\path\to\test\api\sphinx_automodapi.tests.example_module.nonascii.NonAscii.rst:11: WARNING: autosummary: failed to import NonAscii.get_?.
Possible hints:
* AttributeError: type object 'NonAscii' has no attribute 'NonAscii'
* AttributeError: type object 'NonAscii' has no attribute 'get_?'
* ModuleNotFoundError: No module named 'sphinx_automodapi.tests.example_module.nonascii.NonAscii'; 'sphinx_automodapi.tests.example_module.nonascii' is not a package
* ModuleNotFoundError: No module named 'NonAscii'
* ImportError:
C:\Users\USER\path\to\test\api\sphinx_automodapi.tests.example_module.nonascii.NonAscii.rst:11: WARNING: autosummary: failed to import NonAscii.get_???.
Possible hints:
* AttributeError: type object 'NonAscii' has no attribute 'NonAscii'
* AttributeError: type object 'NonAscii' has no attribute 'get_???'
* ModuleNotFoundError: No module named 'sphinx_automodapi.tests.example_module.nonascii.NonAscii'; 'sphinx_automodapi.tests.example_module.nonascii' is not a package
* ModuleNotFoundError: No module named 'NonAscii'
* ImportError:
* KeyError: 'NonAscii'
WARNING: invalid signature for automethod ('get_?')
WARNING: don't know which module to import for autodocumenting 'get_?' (try placing a "module" or "currentmodule" directive in the document, or giving an explicit module name)  
WARNING: don't know which module to import for autodocumenting 'get_???' (try placing a "module" or "currentmodule" directive in the document, or giving an explicit module name)looking for now-outdated files... none found
pickling environment... erledigt
checking consistency... erledigt
preparing documents... erledigt
writing output... [100%] index                                                 nAsciit
generating indices... genindex py-modindex erledigt
writing additional pages... search erledigt
copying static files... erledigt
copying extra files... erledigt
dumping search index in English (code: en)... erledigt
dumping object inventory... erledigt
build abgeschlossen, 14 warnings.

The HTML pages are in _build.

Sphinx expects utf8 and this may set to something different by default on Windows.
Copy link
Member

@bsipocz bsipocz left a comment

Choose a reason for hiding this comment

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

Overall looks good, thank you for the fix.

Could you please add an entry to the changelog (CHANGES.rst) to mention the bugfix? Thanks!

@m-rossi
Copy link
Contributor Author

m-rossi commented Aug 2, 2022

@bsipocz I had to remove your suggestion with the empty line as the test fail now.

@codecov
Copy link

codecov bot commented Aug 2, 2022

Codecov Report

Merging #153 (e5a52cf) into main (b602fdc) will decrease coverage by 0.12%.
The diff coverage is 71.42%.

@@            Coverage Diff             @@
##             main     #153      +/-   ##
==========================================
- Coverage   89.43%   89.31%   -0.13%     
==========================================
  Files          23       24       +1     
  Lines        1098     1104       +6     
==========================================
+ Hits          982      986       +4     
- Misses        116      118       +2     
Impacted Files Coverage Δ
sphinx_automodapi/tests/example_module/nonascii.py 66.66% <66.66%> (ø)
sphinx_automodapi/automodsumm.py 85.62% <100.00%> (ø)

📣 Codecov can now indicate which changes are the most critical in Pull Requests. Learn more

CHANGES.rst Outdated Show resolved Hide resolved
@bsipocz
Copy link
Member

bsipocz commented Aug 8, 2022

Thank you @m-rossi!

@bsipocz bsipocz merged commit c4aa837 into astropy:main Aug 8, 2022
@m-rossi m-rossi deleted the fix-non-ascii-object-members branch August 9, 2022 05:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants