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

bug: Force UTF8 when writing? #1

Open
pawamoy opened this issue Jan 7, 2024 · 0 comments
Open

bug: Force UTF8 when writing? #1

pawamoy opened this issue Jan 7, 2024 · 0 comments
Assignees

Comments

@pawamoy
Copy link
Owner

pawamoy commented Jan 7, 2024

Description of the bug

On the annoying operating system, we get this error in CI:

   .venv\lib\site-packages\mkdocs_manpage\plugin.py:116: in on_post_build
      temp_file.write(html)
  C:\hostedtoolcache\windows\Python\3.8.10\x64\lib\tempfile.py:473: in func_wrapper
      return func(*args, **kwargs)
  _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

  self = <encodings.cp1252.IncrementalEncoder object at 0x000001EB8A26A730>
  input = '<html><body><h1 id="mkdocs-manpage">MkDocs Manpage</h1>\r\n<p>\r\n\r\n\r\n\r\n</p>\r\n<p>MkDocs plugin to generate a ...0.0">1.0.0 <small>June 06, 2023</small></h3>\r\n<ul>\r\n<li>Release first Insiders version</li>\r\n</ul></body></html>'
  final = False

      def encode(self, input, final=False):
  >       return codecs.charmap_encode(input,self.errors,encoding_table)[0]
  E       UnicodeEncodeError: 'charmap' codec can't encode character '\U0001f40d' in position 19356: character maps to <undefined>

To Reproduce

Simply try to use the plugin on Windows.

Full traceback

Full traceback
  _________________________________ test_plugin _________________________________
  [gw0] win32 -- Python 3.8.10 D:\a\mkdocs-manpage\mkdocs-manpage\.venv\Scripts\python.exe

      def test_plugin() -> None:
          """Run the plugin."""
          os.environ["MANPAGE"] = "true"
          with pytest.raises(expected_exception=SystemExit) as exc:
  >           mkdocs.build()()

  tests\test_plugin.py:13: 
  _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
  .venv\lib\site-packages\failprint\lazy.py:37: in __call__
      return self.call(*self.args, **self.kwargs)
  .venv\lib\site-packages\duty\callables\mkdocs.py:80: in build
      run("build", *cli_args, quiet=quiet, verbose=verbose)
  .venv\lib\site-packages\duty\callables\mkdocs.py:26: in run
      mkdocs(cli_args)
  .venv\lib\site-packages\click\core.py:1157: in __call__
      return self.main(*args, **kwargs)
  .venv\lib\site-packages\click\core.py:1078: in main
      rv = self.invoke(ctx)
  .venv\lib\site-packages\click\core.py:1688: in invoke
      return _process_result(sub_ctx.command.invoke(sub_ctx))
  .venv\lib\site-packages\click\core.py:1434: in invoke
      return ctx.invoke(self.callback, **ctx.params)
  .venv\lib\site-packages\click\core.py:783: in invoke
      return __callback(*args, **kwargs)
  .venv\lib\site-packages\mkdocs\__main__.py:286: in build_command
      build.build(cfg, dirty=not clean)
  .venv\lib\site-packages\mkdocs\commands\build.py:354: in build
      config.plugins.on_post_build(config=config)
  .venv\lib\site-packages\mkdocs\plugins.py:542: in on_post_build
      return self.run_event('post_build', config=config)
  .venv\lib\site-packages\mkdocs\plugins.py:509: in run_event
      result = method(**kwargs)
  .venv\lib\site-packages\mkdocs_manpage\plugin.py:116: in on_post_build
      temp_file.write(html)
  C:\hostedtoolcache\windows\Python\3.8.10\x64\lib\tempfile.py:473: in func_wrapper
      return func(*args, **kwargs)
  _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

  self = <encodings.cp1252.IncrementalEncoder object at 0x000001EB8A26A730>
  input = '<html><body><h1 id="mkdocs-manpage">MkDocs Manpage</h1>\r\n<p>\r\n\r\n\r\n\r\n</p>\r\n<p>MkDocs plugin to generate a ...0.0">1.0.0 <small>June 06, 2023</small></h3>\r\n<ul>\r\n<li>Release first Insiders version</li>\r\n</ul></body></html>'
  final = False

      def encode(self, input, final=False):
  >       return codecs.charmap_encode(input,self.errors,encoding_table)[0]
  E       UnicodeEncodeError: 'charmap' codec can't encode character '\U0001f40d' in position 19356: character maps to <undefined>

Expected behavior

No encoding/decoding errors.

Environment information

GHA, Windows.

Additional context

Suggested solution is to add encoding="utf8" to the write call in temp_file.write(html).

@pawamoy pawamoy self-assigned this Jan 7, 2024
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

No branches or pull requests

1 participant