NiklasRosenstein / pydoc-markdown

Create Python API documentation in Markdown format.
http://niklasrosenstein.github.io/pydoc-markdown/
Other
460 stars 105 forks source link

Show error when using non-english docstring #116

Closed BbsonLin closed 3 years ago

BbsonLin commented 4 years ago

Hi, I'm writing docstring in Chinese. It shows the error below.

PS E:\Code\dev-projects\NCTUTWTLab\rabboni-python-sdk> pydoc-markdown.exe -w    
Traceback (most recent call last):
  File "c:\users\bobson\appdata\local\programs\python\python36\Lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "c:\users\bobson\appdata\local\programs\python\python36\Lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "D:\Pipenv\.virtualenvs\rabboni-python-sdk-FMtUT5fP\Scripts\pydoc-markdown.exe\__main__.py", line 7, in <module>
  File "d:\pipenv\.virtualenvs\rabboni-python-sdk-fmtut5fp\lib\site-packages\click\core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "d:\pipenv\.virtualenvs\rabboni-python-sdk-fmtut5fp\lib\site-packages\click\core.py", line 782, in main
    rv = self.invoke(ctx)
  File "d:\pipenv\.virtualenvs\rabboni-python-sdk-fmtut5fp\lib\site-packages\click\core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "d:\pipenv\.virtualenvs\rabboni-python-sdk-fmtut5fp\lib\site-packages\click\core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "d:\pipenv\.virtualenvs\rabboni-python-sdk-fmtut5fp\lib\site-packages\pydoc_markdown\main.py", line 285, in cli
    session.watch_and_serve(pydocmd, open_browser)
  File "d:\pipenv\.virtualenvs\rabboni-python-sdk-fmtut5fp\lib\site-packages\pydoc_markdown\main.py", line 158, in watch_and_serve
    watch_files = self.render(config)
  File "d:\pipenv\.virtualenvs\rabboni-python-sdk-fmtut5fp\lib\site-packages\pydoc_markdown\main.py", line 130, in render
    config.load_modules()
  File "d:\pipenv\.virtualenvs\rabboni-python-sdk-fmtut5fp\lib\site-packages\pydoc_markdown\__init__.py", line 86, in load_modules
    loader.load(self.graph)
  File "d:\pipenv\.virtualenvs\rabboni-python-sdk-fmtut5fp\lib\site-packages\pydoc_markdown\contrib\loaders\python.py", line 619, in load
    self._load_module(graph, package, True)
  File "d:\pipenv\.virtualenvs\rabboni-python-sdk-fmtut5fp\lib\site-packages\pydoc_markdown\contrib\loaders\python.py", line 636, in _load_module
    module = self.load_file(submodule_name, filename)
  File "d:\pipenv\.virtualenvs\rabboni-python-sdk-fmtut5fp\lib\site-packages\pydoc_markdown\contrib\loaders\python.py", line 674, in load_file
    print_function=self.print_function)
  File "d:\pipenv\.virtualenvs\rabboni-python-sdk-fmtut5fp\lib\site-packages\pydoc_markdown\contrib\loaders\python.py", line 95, in parse_file
    code = fp.read()
UnicodeDecodeError: 'cp950' codec can't decode byte 0xe6 in position 5254: illegal multibyte sequence
NiklasRosenstein commented 4 years ago

Hi @BbsonLin ,

When you open your file in a text editor, what is the encoding that the editor is using? Could you upload an example file?

Thanks,

NiklasRosenstein commented 3 years ago

Pydoc-Markdown 3.10.0 allows you to explicityl specify the encoding in the PythonLoader configuration.

loaders:
- type: python
  modules: [my_module]
  encoding: 'utf-8'