[calm - Cygwin server-side packaging maintenance script] branch master, updated. 20220627-4-g879bfc5

Jon TURNEY via Cygwin-apps-cvs <[email protected]> Sat, 2 Jul 2022 21:07:09 +0000 (GMT)
Newsgroups gmane.os.cygwin.cvs.apps
Message-ID <[email protected]>


https://sourceware.org/git/gitweb.cgi?p=cygwin-apps/calm.git;h=879bfc586924cdaf42fc425fb71e7e145b8752a0

commit 879bfc586924cdaf42fc425fb71e7e145b8752a0
Author: Jon Turney <[email protected]>
Date:   Sat Jul 2 22:03:26 2022 +0100

    Ignore flake8-bugbear B023
    
    I seem to like writing code which I think legitimately use the construct
    this warns about.
    
    Drop ignoring B020, since false positives are fixed.

https://sourceware.org/git/gitweb.cgi?p=cygwin-apps/calm.git;h=130b929a2c7d4fbc28bedcbdbac7214acdacf328

commit 130b929a2c7d4fbc28bedcbdbac7214acdacf328
Author: Jon Turney <[email protected]>
Date:   Sat Jul 2 20:29:08 2022 +0100

    Only remove empty subdirectories below a certain depth
    
    'cygport upload/stage' assumes the existence of the '<arch>/release'
    directories, so don't remove those, even if empty.


Diff:
---
 .flake8       | 2 +-
 calm/utils.py | 8 ++++----
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/.flake8 b/.flake8
index 48e7f81..7c03237 100644
--- a/.flake8
+++ b/.flake8
@@ -1,5 +1,5 @@
 [flake8]
-ignore=E741,E129,W504,A003,B020,B902
+ignore=E741,E129,W504,A003,B023,B902
 max-line-length=240
 per-file-ignores =
   calm/fixes.py:E241,E127
diff --git a/calm/utils.py b/calm/utils.py
index f25e5f4..bafc5ff 100644
--- a/calm/utils.py
+++ b/calm/utils.py
@@ -58,12 +58,12 @@ def makedirs(name):
 
 
 #
-# remove any empty subdirectories
+# remove any empty subdirectories below a given depth
 #
-def rmemptysubdirs(path):
+def rmemptysubdirs(path, depth=3):
     for (dirpath, _subdirs, _files) in os.walk(path, topdown=False, followlinks=True):
-        # don't remove the given directory, only subdirectories
-        if os.path.relpath(dirpath, path) == '.':
+        # don't do anything while above the given depth
+        if len(os.path.relpath(dirpath, path).split(os.sep)) < depth:
             continue
 
         # check whether the directory is now empty after processing any