docs: Fix warnings in re pattern and update py-gfm version#7234
docs: Fix warnings in re pattern and update py-gfm version#7234KevinOConnor merged 1 commit intoKlipper3d:masterfrom
Conversation
|
Hey guys, I found that github actions workflow currently uses Python 3.8, which silently accepts |
nefelim4ag
left a comment
There was a problem hiding this comment.
It seems to fix the local build of the docs for me.
Python 3.14.3
Thanks,
-Timofey
|
Thanks. We can certainly add the In general, I would prefer to avoid conditional dependencies where possible, as they can make it hard to reproduce the same results across different machines. -Kevin |
Hi Kevin, 1) With py-gfm version 1.0.2 and Python 3.12+ it reports an error when build docs: ERROR - Config value: 'markdown_extensions'. Error: global flags not at the start of the expression at position 6
Aborted with 1 Configuration Errors!I found the same error report here in klipper discourse. 2) The root reason: The gfm library 1.0.2 uses a regex pattern that begins with (?i) to enable case-insensitive matching: URL_RE = r"(?i)\b((?:(?:ftp|https?)://|www\d{0,3}[.])..." When this pattern is registered with the Markdown library, inlinepatterns.py wraps it inside another regex: self.compiled_re = re.compile(r"^(.?)%s(.)$" % pattern, re.DOTALL | re.UNICODE) This produces: ^(.*?)(?i)\b((?:... The problem: Python 3.14 enforces that inline flags like (?i) must appear at the very start of the entire regex pattern. Now that ^(.*?) precedes (?i), the flag is no longer at the start, triggering the error. We can see the diff of junan@fedora:~/Desktop/py-gfm$ git diff 1.0.2 2.0.0 -- gfm/autolink.py
diff --git a/gfm/autolink.py b/gfm/autolink.py
index efbdff8..5b150ca 100644
--- a/gfm/autolink.py
+++ b/gfm/autolink.py
@@ -41,20 +41,21 @@ Typical usage
import re
import markdown
+import xml.etree.ElementTree as etree
URL_RE = (
- r"(?i)\b((?:(?:ftp|https?)://|www\d{0,3}[.])(?:[^\s()<>]+|"
+ r"\b((?:(?i:ftp|https?)://|(?i:www)\d{0,3}[.])(?:[^\s()<>]+|"
r"\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()"
r"<>]+\)))*\)|[^\s`!()\[\]{};:" + r"'" + r'".,<>?«»“”‘’]))'
)
-PROTOCOL_RE = re.compile(r"^(ftp|https?)://", re.IGNORECASE)
+PROTOCOL_RE = re.compile(r"^(?i:ftp|https?)://")
# We can't re-use the built-in AutolinkPattern because we need to add protocols
# to links without them.
class AutolinkPattern(markdown.inlinepatterns.Pattern):
def handleMatch(self, m):
- el = markdown.util.etree.Element("a")
+ el = etree.Element("a")
href = m.group(2)
if not PROTOCOL_RE.match(href):The leading Thanks, |
|
Thanks. It's also fine if we need to update to a later version of py-gfm, but I'd prefer to avoid conditional versioning. Is there a version of py-gfm that works on both python 3.8 and python 3.12? -Kevin |
|
https://pypi.org/project/py-gfm/2.0.0/ - seems to support 3.8+ -Timofey |
1. wipe out syntaxwarnings of "invalid escape sequence '\s'" 2. update py-gfm version to fit python3.8+ Signed-off-by: Ju Nan <junan76@163.com>
|
Hi, @KevinOConnor as Timofey said:
Thanks Timofey, I tested py-gfm 2.0.0 with python 3.8, it works. And the commit is updated now 😄 -Ju Nan
|
|
Thanks. -Kevin |

I got the following errors when build the documentations with python3.12 :
what I do to fix these:
rprefix;