Skip to content
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

issue with docopt #1986

Closed
amine2233 opened this issue Jan 19, 2024 · 8 comments
Closed

issue with docopt #1986

amine2233 opened this issue Jan 19, 2024 · 8 comments

Comments

@amine2233
Copy link

Hello, thank you for your awesome work.

i had an issue with mackup restore --force on Mac 0S

i installed mackup using brew my setup is

macOS = 14.2.1
python = 3.11.7
mackup = 0.8.40

the result of the command is

mackup restore --force
/opt/homebrew/opt/python-docopt/lib/python3.12/site-packages/docopt.py:165: SyntaxWarning: invalid escape sequence '\S'
  name = re.findall('(<\S*?>)', source)[0]
/opt/homebrew/opt/python-docopt/lib/python3.12/site-packages/docopt.py:166: SyntaxWarning: invalid escape sequence '\['
  value = re.findall('\[default: (.*)\]', source, flags=re.I)
/opt/homebrew/opt/python-docopt/lib/python3.12/site-packages/docopt.py:207: SyntaxWarning: invalid escape sequence '\['
  matched = re.findall('\[default: (.*)\]', description, flags=re.I)
/opt/homebrew/opt/python-docopt/lib/python3.12/site-packages/docopt.py:456: SyntaxWarning: invalid escape sequence '\S'
  split = re.split('\n *(<\S+?>|-\S+?)', doc)[1:]

other test

mackup --version
/opt/homebrew/opt/python-docopt/lib/python3.12/site-packages/docopt.py:165: SyntaxWarning: invalid escape sequence '\S'
  name = re.findall('(<\S*?>)', source)[0]
/opt/homebrew/opt/python-docopt/lib/python3.12/site-packages/docopt.py:166: SyntaxWarning: invalid escape sequence '\['
  value = re.findall('\[default: (.*)\]', source, flags=re.I)
/opt/homebrew/opt/python-docopt/lib/python3.12/site-packages/docopt.py:207: SyntaxWarning: invalid escape sequence '\['
  matched = re.findall('\[default: (.*)\]', description, flags=re.I)
/opt/homebrew/opt/python-docopt/lib/python3.12/site-packages/docopt.py:456: SyntaxWarning: invalid escape sequence '\S'
  split = re.split('\n *(<\S+?>|-\S+?)', doc)[1:]
Mackup 0.8.40
@amine2233
Copy link
Author

I found a solution:

  • i removed mackup using homebrew
  • I update python3 using homebrew
  • i cleanup homebrew
  • i installed mackup
  • restart the terminal
  • all works now

@amine2233
Copy link
Author

fixed

@eiiot
Copy link

eiiot commented Jan 30, 2024

Running into this issue on first install:

 ▲ ~ mackup backup
Traceback (most recent call last):
  File "/opt/homebrew/bin/mackup", line 5, in <module>
    from mackup.main import main
  File "/opt/homebrew/lib/python3.12/site-packages/mackup/main.py", line 38, in <module>
    from docopt import docopt
ModuleNotFoundError: No module named 'docopt'

Is this related? Tried the troubleshooting steps above to no avail.

@lougreenwood
Copy link

I'm still getting the error. I've tried uninstall mackup & python@3 then reinstalling mackup and letting it pull in python@3... but it's not working

@muzimuzhi
Copy link

In Python 3.6, invalid escape sequence were deprecated in string literals. In Python 3.12, they generate SyntaxWarning which will become SyntaxError in the future. See doc of re built-in library, What's new in Python 3.12 - Other Language Changes, and python/cpython#98401.

mackup 0.8.41 depends on docopt 0.6.2, a package that creates beautiful command-line interfaces. At the time 0.6.2 was released (in 2013), the latest Python version was 3.3 so it's not surprising that some uses of now invalid escape sequences were found in docopt 0.6.2.

Unfortunately, docopt is out of maintenance. 0.6.2 is still its latest release.

To resolve the SyntaxWarnings, mackup can do one of the following:

  • patch docopt 0.6.2;
  • use a drop-in replacement, for example docopt-ng last released in May 2023;
  • rework the CLI argument parser, for example using the argparse built-in library.

@muzimuzhi
Copy link

muzimuzhi commented Aug 15, 2024

@amine2233 I sugguest reopening this issue.

@westurner
Copy link

Is it as simple as patching docopt to use rawstrings for regexes?

'str'
r'rawstr'

@muzimuzhi
Copy link

@westurner Yes.

diff --git a/lib/python3.12/site-packages/docopt.py b/lib/python3.12/site-packages/docoptnew.py
index 7b927e2..2a9590d 100644
--- a/lib/python3.12/site-packages/docopt.py
+++ b/lib/python3.12/site-packages/docoptnew.py
@@ -162,8 +162,8 @@ class Argument(ChildPattern):
 
     @classmethod
     def parse(class_, source):
-        name = re.findall('(<\S*?>)', source)[0]
-        value = re.findall('\[default: (.*)\]', source, flags=re.I)
+        name = re.findall(r'(<\S*?>)', source)[0]
+        value = re.findall(r'\[default: (.*)\]', source, flags=re.I)
         return class_(name, value[0] if value else None)
 
 
@@ -204,7 +204,7 @@ class Option(ChildPattern):
             else:
                 argcount = 1
         if argcount:
-            matched = re.findall('\[default: (.*)\]', description, flags=re.I)
+            matched = re.findall(r'\[default: (.*)\]', description, flags=re.I)
             value = matched[0] if matched else None
         return class_(short, long, argcount, value)
 
@@ -453,7 +453,7 @@ def parse_argv(tokens, options, options_first=False):
 
 def parse_defaults(doc):
     # in python < 2.7 you can't pass flags=re.MULTILINE
-    split = re.split('\n *(<\S+?>|-\S+?)', doc)[1:]
+    split = re.split(r'\n *(<\S+?>|-\S+?)', doc)[1:]
     split = [s1 + s2 for s1, s2 in zip(split[::2], split[1::2])]
     options = [Option.parse(s) for s in split if s.startswith('-')]
     #arguments = [Argument.parse(s) for s in split if s.startswith('<')]

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

5 participants