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

Use BytesIO wrapped font instead of passing path to avoid "Cannot open resource" error in Windows #837

Merged
merged 2 commits into from
Aug 9, 2024

Conversation

jaimergp
Copy link
Contributor

@jaimergp jaimergp commented Aug 9, 2024

Description

CI erroring out in Azure at conda-forge/constructor-feedstock#78. Not sure why we didn't see this on GHA, but I can reproduce locally and this is the recommended fix in the Pillow docstring.

This is the error:

Traceback (most recent call last):
  File "C:\Users\username\Documents\GitHub\conda\devenv\Windows\envs\devenv-3.11\envs\const>
    sys.exit(main())
             ^^^^^^
  File "C:\Users\username\Documents\GitHub\conda\devenv\Windows\envs\devenv-3.11\envs\constn
    main_build(dir_path, output_dir=out_dir, platform=args.platform,
  File "C:\Users\username\Documents\GitHub\conda\devenv\Windows\envs\devenv-3.11\envs\constd
    create(info, verbose=verbose)
  File "C:\Users\username\Documents\GitHub\conda\devenv\Windows\envs\devenv-3.11\envs\conste
    write_images(info, tmp_dir)
  File "C:\Users\username\Documents\GitHub\conda\devenv\Windows\envs\devenv-3.11\envs\consts
    im = function(info)
         ^^^^^^^^^^^^^^
  File "C:\Users\username\Documents\GitHub\conda\devenv\Windows\envs\devenv-3.11\envs\conste
    font = ImageFont.truetype(ttf_path, 20)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\username\Documents\GitHub\conda\devenv\Windows\envs\devenv-3.11\envs\conste
    return freetype(font)
           ^^^^^^^^^^^^^^
  File "C:\Users\username\Documents\GitHub\conda\devenv\Windows\envs\devenv-3.11\envs\conste
    return FreeTypeFont(font, size, index, encoding, layout_engine)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\username\Documents\GitHub\conda\devenv\Windows\envs\devenv-3.11\envs\const_
    self.font = core.getfont(
                ^^^^^^^^^^^^^
OSError: cannot open resource

Checklist - did you ...

  • Add a file to the news directory (using the template) for the next release's release notes?
  • Add / update necessary tests?
  • Add / update outdated documentation?

@jaimergp jaimergp requested a review from a team as a code owner August 9, 2024 08:33
@conda-bot conda-bot added the cla-signed [bot] added once the contributor has signed the CLA label Aug 9, 2024
Comment on lines +15 to +16
with open(ttf_path, "rb") as f:
ttf_bytes = f.read()
Copy link
Member

Choose a reason for hiding this comment

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

Would be worthwhile to use https://docs.python.org/3/library/importlib.resources.html for this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

One day, yes. That path has worked for a long time so I just want to unblock this issue to release 3.9.1.

Copy link
Contributor

@marcoesters marcoesters left a comment

Choose a reason for hiding this comment

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

I think this is an acceptable workaround for now.

@jaimergp jaimergp merged commit abf208d into conda:main Aug 9, 2024
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla-signed [bot] added once the contributor has signed the CLA
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

4 participants