Skip to content

Trying to use json palette crashes because of file encoding #47

Description

@badjano

Important notices
Before you add a new report, we ask you kindly to acknowledge the following:

[-] I have read the contributing guide lines at https://github.com/timofurrer/colorful/blob/master/.github/CONTRIBUTING.md
THIS LINK IS BROKEN: https://github.com/timofurrer/colorful/blob/master/.github/CONTRIBUTING.md

[-] I have read and respect the code of conduct at https://github.com/timofurrer/colorful/blob/master/.github/CODE_OF_CONDUCT.md
OK

[-] I have searched the existing issues and I'm convinced that mine is new.
YES, ALTHOUGH SOME MIGHT BE RELATED

Describe the bug
A clear and concise description of what the bug is.

import json

from colorful import Colorful, colors
from colorful.core import COLORNAMES_COLORS_PATH

cf = Colorful(colorpalette=COLORNAMES_COLORS_PATH)  # this is going to crash
colors.parse_json_color_file(COLORNAMES_COLORS_PATH)  # this is the method that is actually crashing

with open(COLORNAMES_COLORS_PATH, encoding="utf8") as f:  # this is how you fix it
    colorpalette = json.load(f)

Environment and Version

  • OS (incl. terminal and shell used): windows, pycharm
  • Python Version: 3.8
  • colorful Version: 0.5.4

To Reproduce
A clear and concise description of steps to reproduce the behavior
you are experiencing.

from colorful import Colorful, colors
from colorful.core import COLORNAMES_COLORS_PATH

cf = Colorful(colorpalette=COLORNAMES_COLORS_PATH)  # this is going to crash
colors.parse_json_color_file(COLORNAMES_COLORS_PATH)  # this is the method that is actually crashing

Expected behavior
A clear and concise description of what you expected to happen.

I think an easier way to extend colors with the json included on this library would be good

Screenshots
If applicable, add screenshots to help explain your problem.

Additional context
Add any other context about the problem here.

if you want to I know exactly what to do to fix it so I can make a PR, but I would want to make some changes, like the color name in the json file has spaces and upper cased letters, I would probably change that to camel case, which seems to be the standard for this library

edit: I just realized there is already a sanitize_color_palette that makes the camelcase, sorry

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions