> Are there any systems where Python is only installed as "python" and not as 
> "python3" or is this safe?

If "python3" is missing, it should be installable via a package or can
be made available manually via a symbolic link, but I suppose this is
going to be troublesome for some so I've reverted the hashbang binary
back to "python" in the reattached patch.

> I've tested and on Windows (Python 3.12) I get the following syntax warnings:
>
> C:\Devel\subversion_trunk\contrib\client-side\svn_apply_autoprops.py:71: 
> SyntaxWarning: invalid escape sequence '\s'
>   re_start_autoprops = re.compile('^\s*\[auto-props\]\s*')
> C:\Devel\subversion_trunk\contrib\client-side\svn_apply_autoprops.py:72: 
> SyntaxWarning: invalid escape sequence '\s'
>   re_end_autoprops = re.compile('^\s*\[\w+\]\s*')

I was using Python 3.10 on both Windows and Linux and so was not
getting the warnings. I have since upgraded to Python 3.12 on Windows
and have made the necessary changes in the reattached patch. Testing
with Python 2.7 suggests that there are no problems with the raw
strings regarding backwards compatibility.

[[[
Make svn_apply_autoprops.py Python 3-compatible.

* contrib/client-side/svn_apply_autoprops.py:
  (get_autoprop_lines): Use raw strings for regexes, and `for line in
fd` instead of `for line in
fd.xreadlines()`.
  (filter_walk): Pass directory names separately.
  (main): Use `open()` instead of `file()`, and `os.walk()` instead of
`os.path.walk()`.
]]]

Best regards,
Khairul

On Tue, Apr 30, 2024 at 11:31 PM Daniel Sahlberg
<daniel.l.sahlb...@gmail.com> wrote:
>
> Den mån 29 apr. 2024 kl 14:06 skrev Khairul Azhar Kasmiran 
> <kaza...@gmail.com>:
>>
>> Hi everyone!
>>
>> As promised in [1], this patch makes svn_apply_autoprops.py Python
>> 3-compatible while keeping Python 2 compatibility. Afaik, the original
>> semantics are preserved 100% -- I think I did the conversion from
>> `os.path.walk()` to `os.walk()` correctly.
>>
>> [1] https://lists.apache.org/thread/j8cjrgxosz2cmcysymhy8pr4b5x9s96k
>>
>> [[[
>> Make svn_apply_autoprops.py Python 3-compatible.
>>
>> * contrib/client-side/svn_apply_autoprops.py: Set hashbang binary to 
>> `python3`.
>
>
> Are there any systems where Python is only installed as "python" and not as 
> "python3" or is this safe?
>
>>
>>   (get_autoprop_lines): Use `for line in fd` instead of `for line in
>> fd.xreadlines()`.
>>   (filter_walk): Pass directory names separately.
>>   (main): Use `open()` instead of `file()`, and `os.walk()` instead of
>> `os.path.walk()`.
>> ]]]
>
>
> Thanks!
>
> I've tested and on Windows (Python 3.12) I get the following syntax warnings:
>
> C:\Devel\subversion_trunk\contrib\client-side\svn_apply_autoprops.py:71: 
> SyntaxWarning: invalid escape sequence '\s'
>   re_start_autoprops = re.compile('^\s*\[auto-props\]\s*')
> C:\Devel\subversion_trunk\contrib\client-side\svn_apply_autoprops.py:72: 
> SyntaxWarning: invalid escape sequence '\s'
>   re_end_autoprops = re.compile('^\s*\[\w+\]\s*')
>
> (I don't get those on Linux (Python 3.11)).
>
> It seems to help to use a raw string, but I'm not sure if this will kill 
> backwards compatibility. ON the other hand if we set the hashbang to python3, 
> we've explicitly killed any hope of backwards compatibility.
>
> Kind regards,
> Daniel
>
>
>
>>
>>
>> Best regards,
>> Khairul
Index: contrib/client-side/svn_apply_autoprops.py
===================================================================
--- contrib/client-side/svn_apply_autoprops.py  (revision 1917418)
+++ contrib/client-side/svn_apply_autoprops.py  (working copy)
@@ -68,10 +68,10 @@ def get_autoprop_lines(fd):
   lines = []
   reading_autoprops = 0
 
-  re_start_autoprops = re.compile('^\s*\[auto-props\]\s*')
-  re_end_autoprops = re.compile('^\s*\[\w+\]\s*')
+  re_start_autoprops = re.compile(r'^\s*\[auto-props\]\s*')
+  re_end_autoprops = re.compile(r'^\s*\[\w+\]\s*')
 
-  for line in fd.xreadlines():
+  for line in fd:
     if reading_autoprops:
       if re_end_autoprops.match(line):
         reading_autoprops = 0
@@ -124,13 +124,14 @@ def process_autoprop_lines(lines):
 
   return result
 
-def filter_walk(autoprop_lines, dirname, filenames):
+def filter_walk(autoprop_lines, dirname, dirnames, filenames):
   # Do not descend into a .svn directory.
   try:
-    filenames.remove(SVN_WC_ADM_DIR_NAME)
+    dirnames.remove(SVN_WC_ADM_DIR_NAME)
   except ValueError:
     pass
 
+  filenames += dirnames
   filenames.sort()
 
   # Find those filenames that match each fnmatch.
@@ -184,7 +185,7 @@ def main():
     return 1
 
   try:
-    fd = file(config_filename)
+    fd = open(config_filename)
   except IOError:
     print("Cannot open svn configuration file '%s' for reading: %s" \
           % (config_filename, sys.exc_value.strerror))
@@ -196,7 +197,8 @@ def main():
 
   autoprop_lines = process_autoprop_lines(autoprop_lines)
 
-  os.path.walk(wc_path, filter_walk, autoprop_lines)
+  for root, dirs, files in os.walk(wc_path):
+    filter_walk(autoprop_lines, root, dirs, files)
 
 if __name__ == '__main__':
   sys.exit(main())

Reply via email to