Skip to content

[BUG] Custom components error during build - char encoding #2127

Closed
@lucafaggianelli

Description

Describe your context
Please provide us your environment, so we can easily reproduce the issue.

dash                  2.5.0
dash-core-components  2.0.0
dash-html-components  2.0.0
dash-table            5.0.0

This bug is about a custom component lib, the cookiecutter template I'm using is the TS one but I have the same issue also with the standard template

Describe the bug

I created a custom Dash components library via cookiecutter template and when I run npm run build I receive an error:

Generated ButtonOutline.py
Generated Card.py
Generated CardBody.py
Traceback (most recent call last):
  File "C:\Users\LQ6211\dev\experiments\engie_dash\components\.venv\Scripts\dash-generate-components-script.py", line 33, in <module>
    sys.exit(load_entry_point('dash==2.5.1', 'console_scripts', 'dash-generate-components')())
  File "C:\Users\LQ6211\dev\experiments\engie_dash\components\.venv\lib\site-packages\dash\development\component_generator.py", line 242, in cli
    generate_components(
  File "C:\Users\LQ6211\dev\experiments\engie_dash\components\.venv\lib\site-packages\dash\development\component_generator.py", line 136, in generate_components
    components = generate_classes_files(project_shortname, metadata, *generator_methods)
  File "C:\Users\LQ6211\dev\experiments\engie_dash\components\.venv\lib\site-packages\dash\development\_py_components_generation.py", line 195, in generate_classes_files
    generator(
  File "C:\Users\LQ6211\dev\experiments\engie_dash\components\.venv\lib\site-packages\dash\development\_py_components_generation.py", line 174, in generate_class_file
    f.write(class_string)
  File "C:\Program Files\Python310\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 '\u221e' in position 354214: character maps to <undefined>

The concerned snippet of code is in _py_components_generation.py:

with open(file_path, "w") as f:
        f.write(import_string)
        f.write(class_string)

and if I add an encoding to the open() function, the error disappears, for example open(file_path, "w", encoding="utf-8").

Of course if I remove the strange character (∞) that caused the issue from the components PropTypes, the build goes well, but it would be nice to support it.
Furthermore, I'm using Typescript so the components PropTypes are pulled in from TS types, so it's a bit out of my control and I can't really remove weird chars (I need to Omit<> TS properties from types).

Expected behavior

To just have the .py files generated correctly even if they contain strange chars like

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions