-
Notifications
You must be signed in to change notification settings - Fork 43
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
Describe the bug:
On a very simple type annotated function, I get:
Writing api.md.
Failed to generate docs for module api: UnicodeEncodeError('charmap', '<!-- markdownlint-disable -->\r\n\r\n# <kbd>module</kbd> `api`\r\n\r\n\r\n\r\n\r\n\r\n---\r\n\r\n## <kbd>function</kbd> `to_string`\r\n\r\n```python\r\nto_string(value: int) → str\r\n```\r\n\r\nSimple function. \r\n\r\n\r\n\r\n**Args:**\r\n \r\n - <b>`value`</b>: integer value \r\n\r\n\r\n\r\n**Returns:**\r\n same value as string \r\n\r\n\r\n', 148, 149, 'character maps to <undefined>')
Expected behaviour:
Should generate markdown file.
Steps to reproduce the issue:
- On windows make sure your local default encoding is not
utf8
(windows console defaults tocp1252
) - Run lazydocs generation on any code that has type annotations.
Technical details:
- Host Machine OS (Windows/Linux/Mac): Windows 10
- Browser (Chrome/Firefox/Safari): Firefox
Possible Fix:
There's a hacky solution to make sure python is defaulting to 'utf8' when opening files:
if os.name == "nt":
import _locale
_locale._gdl_bak = _locale._getdefaultlocale
_locale._getdefaultlocale = (lambda *args: (_locale._gdl_bak()[0], 'utf8'))
However, I'd advise against it as it may not be exactly future proof. Instead, it is better to be explicit when opening a file:
with open(os.path.join(out_path, md_file), "w", encoding="utf-8") as f:
The line in question is here:
lazydocs/src/lazydocs/generation.py
Line 230 in ebf6ea8
with open(os.path.join(out_path, md_file), "w") as f: |
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working