sizmailov / pybind11-stubgen

Generate stubs for python modules
Other
228 stars 45 forks source link

Versions 1.x no longer supporting characters such as Ω, ≡, etc. in docstrings [Windows] #131

Closed allanleal closed 11 months ago

allanleal commented 11 months ago

Hello. Thanks for proving us this excellent tool. Since version 1.x+, I've noticed that pybind11-stubgen no longer works in Windows when using Greek and mathematical characters:

.def("saturationIndex", &AqueousProps::saturationIndex, "Return the saturation index SI ≡ log(Ω) = log(IAP/K) of a non-aqueous species.")

This causes the following error using MS Visual Studio:

    File "C:\Users\Allan\miniforge3\envs\reaktoro\Scripts\pybind11-stubgen-script.py", line 9, in <module>
      sys.exit(main())
               ^^^^^^
    File "C:\Users\Allan\miniforge3\envs\reaktoro\Lib\site-packages\pybind11_stubgen\__init__.py", line 239, in main
      run(
    File "C:\Users\Allan\miniforge3\envs\reaktoro\Lib\site-packages\pybind11_stubgen\__init__.py", line 271, in run
      writer.write_module(module, printer, to=out_dir, sub_dir=sub_dir)
    File "C:\Users\Allan\miniforge3\envs\reaktoro\Lib\site-packages\pybind11_stubgen\writer.py", line 28, in write_module
      self.write_module(sub_module, printer, to=module_dir)
    File "C:\Users\Allan\miniforge3\envs\reaktoro\Lib\site-packages\pybind11_stubgen\writer.py", line 25, in write_module
      f.writelines(line + "\n" for line in printer.print_module(module))
    File "C:\Users\Allan\miniforge3\envs\reaktoro\Lib\encodings\cp1252.py", line 19, in encode
      return codecs.charmap_encode(input,self.errors,encoding_table)[0]
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  UnicodeEncodeError: 'charmap' codec can't encode character '\u03a9' in position 45: character maps to <undefined>
C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\MSBuild\Microsoft\VC\v160\Microsoft.CppCommon.targets(241,5): error MSB8066: Custom build for 'C:\Users\Allan\codes\reaktoro\build\CMakeFiles\2b4c3edb4f49283adc03d67aef6b258a\reaktoro-setuptools.rule' exited with code 1. [C:\Users\Allan\codes\reaktoro\build\python\package\reaktoro-setuptools.vcxproj]       

I tried to find a solution, but it seems codecs.charmap_encode does not accept an encoding option.

Thanks for looking into this.

sizmailov commented 11 months ago

Thanks for the report.

I reintroduced bug #73 in the new release and failed to setup windows tests so it went unnoticed.

allanleal commented 11 months ago

Awesome. I maintain the conda-forge package for pybind11-stubgen. Once you make a new release with these fixes, we'll have an updated conda-forge package.

sizmailov commented 11 months ago

I just released the 2.0.