textwrap module not usable with MicroPython ure
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
PicoW, MicroPython and textwrap, does it work fully? Or is it the re module?
Hello,
Is the textwrap module in the library usable on MicroPython 1.19.1 nightly?
This error comes up when loading up textwrap.py of Micropython-3.4.2.post1
Line 83:
Traceback (most recent call last):
File "<stdin>", line 22, in <module>
File "<stdin>", line 83, in TextWrapper
ValueError: error in regex
I wonder if there is a problem with the re package? Shown as “ r'(\s+|' # any whitespace” on line 83 as can be seen from the screenshots.
My question, is there an obvious debug strategy to this or short-term fix?
I found a previous open issue from 2018:
https://github.com/micropython/micropython-lib/issues/318
I would welcome helpful suggestions as to how to resolve this (a module I am using needs textwrap to work).
Thanks, Brian
[Running in Thonny 4.0.1 and MicroPython v1.19.1 on 2022-09-14; Raspberry Pi Pico W with RP2040]

Looks like this module was written with the unix-ffi version of the
remodule in mind (which uses PCRE behind the scenes).Now that we've made
textwrappart of the python-stdlib section, it needs to be updated to no longer require these regexp features.@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?
@brianlinuxing
If you don't use the
dedentfunction or don't requirebreak_on_hyphensto be set to True for thewrap, then all you have to do is remove the lines that use therefeatures that aren't supported and this will work fine.