Skip to content

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

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

Closed
lucafaggianelli opened this issue Jul 13, 2022 · 3 comments · Fixed by #2131
Closed

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

lucafaggianelli opened this issue Jul 13, 2022 · 3 comments · Fixed by #2131

Comments

@lucafaggianelli
Copy link

lucafaggianelli commented Jul 13, 2022

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

@lucafaggianelli lucafaggianelli changed the title [BUG] Custom components error during build [BUG] Custom components error during build - char encoding Jul 13, 2022
@alexcjohnson
Copy link
Collaborator

@T4rk1n perhaps we can enable unspecified-encoding in pylint? pylint-dev/pylint#4753

@T4rk1n
Copy link
Contributor

T4rk1n commented Jul 13, 2022

@T4rk1n perhaps we can enable unspecified-encoding in pylint?

I guess it was disabled because it was a new rule and the build failed. There is a couple of those to fix when enabled.

@akx
Copy link

akx commented Jul 14, 2022

This would probably also have been fixed by setting the PYTHONUTF8 environment variable, as described in PEP 540.

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

Successfully merging a pull request may close this issue.

4 participants