Skip to content

textwrap module not usable with MicroPython ure #318

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

Open
egranata opened this issue Nov 3, 2018 · 3 comments
Open

textwrap module not usable with MicroPython ure #318

egranata opened this issue Nov 3, 2018 · 3 comments

Comments

@egranata
Copy link

egranata commented Nov 3, 2018

I have a port of MicroPython which includes the ure module. I tried to bring in the textwrap module from this project, but ran into a couple of issues:

    wordsep_re = re.compile(
        r'(\s+|'                                  # any whitespace
        r'[^\s\w]*\w+[^0-9\W]-(?=\w+[^0-9\W])|'   # hyphenated words
        r'(?<=[\w\!\"\'\&\.\,\?])-{2,}(?=\w))')   # em-dash

This regular expression does not compile cleanly as ure does not support the (?= notation

_whitespace_only_re = re.compile('^[ \t]+$', re.MULTILINE)
_leading_whitespace_re = re.compile('(^[ \t]*)(?:[^ \t\n])', re.MULTILINE)

These two also fail to compile, in this case because the MULTILINE flag is missing

@jimmo
Copy link
Member

jimmo commented Sep 19, 2022

Looks like this module was written with the unix-ffi version of the re module in mind (which uses PCRE behind the scenes).

Now that we've made textwrap part of the python-stdlib section, it needs to be updated to no longer require these regexp features.

@jimmo
Copy link
Member

jimmo commented Sep 20, 2022

@brianlinuxing

What do you actually need this module for? I'm not seeing any obvious reasons why a microcontroller needs to do text wrapping.

More specifically, if we were to make a much simpler subset implementation rather than making all the features of the CPython version work, what exact features would you require?

@jimmo
Copy link
Member

jimmo commented Sep 20, 2022

@brianlinuxing

If you don't use the dedent function or don't require break_on_hyphens to be set to True for the wrap, then all you have to do is remove the lines that use the re features that aren't supported and this will work fine.

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

2 participants