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

Invalid escape sequence #2985

Open
Gekiretsu opened this issue Jun 15, 2024 · 1 comment
Open

Invalid escape sequence #2985

Gekiretsu opened this issue Jun 15, 2024 · 1 comment

Comments

@Gekiretsu
Copy link

Hello I've not submitted many issues before so I will try to be as thorough as possible in my explanation. I've used ranger for years as my primary file manager and just recently over the last few months I began to notice that anytime I am constantly receiving an error about a invalid escape sequence. I'm in school now and trying to teach myself python so I'm not sure at all how to fix this so any and all help I would be extremely grateful and appreciative. Below is the error that I receive every time I exit/quit ranger.

/home/chinmoku/.config/ranger/commands.py:78: SyntaxWarning: invalid escape sequence '('
command="find -L . ( -path '/.' -o -fstype 'dev' -o -fstype 'proc' ) -prune
/home/chinmoku/.config/ranger/commands.py:82: SyntaxWarning: invalid escape sequence '('
command="find -L . ( -path '/.' -o -fstype 'dev' -o -fstype 'proc' ) -prune
/home/chinmoku/.config/ranger/commands.py:134: SyntaxWarning: invalid escape sequence '('
command="find -L . ( -path '/.' -o -fstype 'dev' -o -fstype 'proc' ) -prune
/home/chinmoku/.config/ranger/commands.py:138: SyntaxWarning: invalid escape sequence '('
command="find -L . ( -path '/.' -o -fstype 'dev' -o -fstype 'proc' ) -prune \

@OPhamster
Copy link

OPhamster commented Jun 24, 2024

Hey @Gekiretsu it seems that this particular file is populated via the manjaro-ranger-settings package and not in this project. These seem to be compatibility issues w.r.t Python 3. Either way I ended up making the commit locally but the way to contribute to manjaro packages on a quick search seemed tedious - I'll just lay the diff right here in case u need it. Generated it via git diff HEAD~ --no-prefix:

diff --git ranger/commands.py ranger/commands.py
index 60d8676..38905bf 100644
--- ranger/commands.py
+++ ranger/commands.py
@@ -1,11 +1,18 @@
 from ranger.api.commands import Command
 
+
 class paste_as_root(Command):
-       def execute(self):
-               if self.fm.do_cut:
-                       self.fm.execute_console('shell sudo mv %c .')
-               else:
-                       self.fm.execute_console('shell sudo cp -r %c .')
+    """
+    :paste_as_root
+
+    Paste a file using superuser permissions. Use with care
+    """
+    def execute(self):
+        if self.fm.do_cut:
+            self.fm.execute_console('shell sudo mv %c .')
+        else:
+            self.fm.execute_console('shell sudo cp -r %c .')
+
 
 class fzf_select(Command):
     """
@@ -22,17 +29,18 @@ class fzf_select(Command):
         import os.path
         if self.quantifier:
             # match only directories
-            command="find -L . \( -path '*/\.*' -o -fstype 'dev' -o -fstype 'proc' \) -prune \
-            -o -type d -print 2> /dev/null | sed 1d | cut -b3- | fzf +m --reverse --header='Jump to file'"
+            command = r"find -L . \( -path '*/\.*' -o -fstype 'dev' -o -fstype 'proc' \) -prune "\
+                r"-o -type d -print 2> /dev/null | sed 1d | cut -b3- | fzf +m --reverse --header='Jump to file'"  # noqa: E501
         else:
             # match files and directories
-            command="find -L . \( -path '*/\.*' -o -fstype 'dev' -o -fstype 'proc' \) -prune \
-            -o -print 2> /dev/null | sed 1d | cut -b3- | fzf +m --reverse --header='Jump to filemap <C-f> fzf_select'"
-        fzf = self.fm.execute_command(command, universal_newlines=True, stdout=subprocess.PIPE)
-        stdout, stderr = fzf.communicate()
+            command = r"find -L . \( -path '*/\.*' -o -fstype 'dev' -o -fstype 'proc' \) -prune "\
+                r"-o -print 2> /dev/null | sed 1d | cut -b3- | fzf +m --reverse --header='Jump to filemap <C-f> fzf_select'"  # noqa: E501
+        fzf = self.fm.execute_command(command, universal_newlines=True,
+                                      stdout=subprocess.PIPE)
+        stdout, _ = fzf.communicate()
         if fzf.returncode == 0:
             fzf_file = os.path.abspath(stdout.rstrip('\n'))
             if os.path.isdir(fzf_file):
                 self.fm.cd(fzf_file)
             else:
-                self.fm.select_file(fzf_file)
\ No newline at end of file
+                self.fm.select_file(fzf_file)

You should be able to apply this patch locally via patch -p0 < diff.patch where diff.patch is the patch above. The commit message I had for this added references as well

Pre-Patch:

$ ranger
/home/ophamster/.config/ranger/commands.py:25: SyntaxWarning: invalid escape sequence '\('
 command="find -L . \( -path '*/\.*' -o -fstype 'dev' -o -fstype 'proc' \) -prune \
/home/ophamster/.config/ranger/commands.py:29: SyntaxWarning: invalid escape sequence '\('
command="find -L . \( -path '*/\.*' -o -fstype 'dev' -o -fstype 'proc' \) -prune \

Post-Patch:

$ ranger
$
  • Also added a comment to ignore line length

Reference: python/cpython#98401 (comment)

EDIT: I just noticed that that the errors that ur facing different from mine (the lines but the not the errors themselves) - so its more than likely that its coming from a different source - so I apologise for the confusion. But the fix remains the same and u should be able to apply the same method for ur case as well.

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