Enable more linters (round 3)

0 views
Skip to first unread message

Rob Browning

unread,
Mar 6, 2026, 6:16:53 PM (8 days ago) Mar 6
to bup-...@googlegroups.com
Another round of assorted linters and the associated fixes.

Pushed to main.

--
Rob Browning
rlb @defaultvalue.org and @debian.org
GPG as of 2011-07-10 E6A9 DA3C C9FD 1FF8 C676 D2C4 C0F0 39E9 ED1B 597A
GPG as of 2002-11-03 14DD 432F AE39 534D B592 F9A0 25C8 D377 8C7E 73A4

Rob Browning

unread,
Mar 6, 2026, 6:16:54 PM (8 days ago) Mar 6
to bup-...@googlegroups.com
Signed-off-by: Rob Browning <r...@defaultvalue.org>
Tested-by: Rob Browning <r...@defaultvalue.org>
---
.pylintrc | 1 +
lib/bup/cmd/drecurse.py | 2 +-
lib/bup/main.py | 2 +-
3 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/.pylintrc b/.pylintrc
index 689e0e02..4eb948ba 100644
--- a/.pylintrc
+++ b/.pylintrc
@@ -32,6 +32,7 @@ enable=
expression-not-assigned,
f-string-without-interpolation,
function-redefined,
+ import-outside-toplevel,
inconsistent-return-statements,
logging-not-lazy,
no-else-continue,
diff --git a/lib/bup/cmd/drecurse.py b/lib/bup/cmd/drecurse.py
index f533f346..4211dba6 100644
--- a/lib/bup/cmd/drecurse.py
+++ b/lib/bup/cmd/drecurse.py
@@ -36,7 +36,7 @@ def main(argv):
excluded_paths=excluded_paths,
exclude_rxs=exclude_rxs)
if opt.profile:
- import cProfile
+ import cProfile # pylint: disable=import-outside-toplevel
def do_it():
for i in it:
pass
diff --git a/lib/bup/main.py b/lib/bup/main.py
index e32931e5..7ef9e1e3 100755
--- a/lib/bup/main.py
+++ b/lib/bup/main.py
@@ -196,7 +196,7 @@ def run_subcmd(module, args):
try:
if not do_profile:
return module.main(args)
- import cProfile
+ import cProfile # pylint: disable=import-outside-toplevel
f = compile('module.main(args)', __file__, 'exec')
return cProfile.runctx(f, globals(), locals())
finally:
--
2.47.3

Rob Browning

unread,
Mar 6, 2026, 6:16:54 PM (8 days ago) Mar 6
to bup-...@googlegroups.com
Signed-off-by: Rob Browning <r...@defaultvalue.org>
Tested-by: Rob Browning <r...@defaultvalue.org>
---
.pylintrc | 1 +
lib/bup/main.py | 6 ++++--
test/int/test_client.py | 3 ++-
test/int/test_metadata.py | 2 +-
test/int/test_resolve.py | 5 +++--
test/int/test_treesplit.py | 2 +-
test/int/test_vfs.py | 7 ++++---
7 files changed, 16 insertions(+), 10 deletions(-)

diff --git a/.pylintrc b/.pylintrc
index 41fae24b..3aa4c095 100644
--- a/.pylintrc
+++ b/.pylintrc
@@ -67,4 +67,5 @@ enable=
use-maxsplit-arg,
use-yield-from,
useless-return,
+ wrong-import-order,
wrong-import-position
diff --git a/lib/bup/main.py b/lib/bup/main.py
index 7ef9e1e3..91f23835 100755
--- a/lib/bup/main.py
+++ b/lib/bup/main.py
@@ -1,14 +1,16 @@

-import bup_main, os, sys
+import os, sys
+import bup_main
if bup_main.env_pythonpath:
os.environb[b'PYTHONPATH'] = bup_main.env_pythonpath
else:
del os.environ['PYTHONPATH']

-# pylint: disable=wrong-import-position
+# pylint: disable=wrong-import-position disable=wrong-import-order
from importlib import import_module
from os import fsdecode
from pkgutil import iter_modules
+# pylint: enable=wrong-import-order

from bup import compat, io, path
from bup.compat import environ, print_exception
diff --git a/test/int/test_client.py b/test/int/test_client.py
index 717069fb..38499125 100644
--- a/test/int/test_client.py
+++ b/test/int/test_client.py
@@ -2,11 +2,12 @@
import os, time, random, subprocess, glob
import pytest

+from buptest import ex
+
from bup import client, git, path
from bup.compat import environ
from bup.config import ConfigError
from bup.repo import LocalRepo
-from buptest import ex


def randbytes(sz):
diff --git a/test/int/test_metadata.py b/test/int/test_metadata.py
index d9f626d1..c3b77213 100644
--- a/test/int/test_metadata.py
+++ b/test/int/test_metadata.py
@@ -4,6 +4,7 @@ import os, sys
import pytest

from wvpytest import *
+import buptest

from bup import git, helpers, metadata
from bup import vfs
@@ -12,7 +13,6 @@ from bup.helpers import clear_errors, detect_fakeroot, is_superuser, resolve_par
from bup.metadata import xattr
from bup.repo import LocalRepo
from bup.xstat import utime, lutime
-import buptest

lib_t_dir = os.path.dirname(fsencode(__file__))

diff --git a/test/int/test_resolve.py b/test/int/test_resolve.py
index e65500fc..08e3d648 100644
--- a/test/int/test_resolve.py
+++ b/test/int/test_resolve.py
@@ -6,13 +6,14 @@ from stat import S_IFDIR
import os
from time import localtime, strftime

+from buptest import ex, exo
+from buptest.vfs import tree_dict
from wvpytest import *

from bup import git, path, vfs
from bup.compat import environ
from bup.repo import LocalRepo, make_repo
-from buptest import ex, exo
-from buptest.vfs import tree_dict
+

bup_path = path.exe()

diff --git a/test/int/test_treesplit.py b/test/int/test_treesplit.py
index 5a461840..5a90f045 100644
--- a/test/int/test_treesplit.py
+++ b/test/int/test_treesplit.py
@@ -4,11 +4,11 @@ from pathlib import Path
from sys import stderr
import re

+from buptest import ex, exo
from wvpytest import *

from bup import git, tree
from bup.helpers import mkdirp
-from buptest import ex, exo


def test_abbreviate():
diff --git a/test/int/test_vfs.py b/test/int/test_vfs.py
index f66c7cd6..673b3473 100644
--- a/test/int/test_vfs.py
+++ b/test/int/test_vfs.py
@@ -8,17 +8,18 @@ import os
import sys
from time import localtime, strftime, tzset

-from wvpytest import *
import pytest

+from buptest import exo
+from buptest.vfs import tree_dict
+from wvpytest import *
+
from bup._helpers import write_random
from bup import git, metadata, vfs
from bup.compat import environ, fsencode
from bup.helpers import exc, shstr
from bup.metadata import Metadata
from bup.repo import LocalRepo
-from buptest import exo
-from buptest.vfs import tree_dict

lib_t_dir = os.path.dirname(fsencode(__file__))
top_dir = os.path.join(lib_t_dir, b'../..')
--
2.47.3

Rob Browning

unread,
Mar 6, 2026, 6:16:54 PM (8 days ago) Mar 6
to bup-...@googlegroups.com
Signed-off-by: Rob Browning <r...@defaultvalue.org>
Tested-by: Rob Browning <r...@defaultvalue.org>
---
.pylintrc | 5 ++++
lib/bup/cmd/midx.py | 18 +++++++-------
lib/bup/cmd/tag.py | 4 ++--
lib/bup/git.py | 4 ++--
test/int/test_hashsplit.py | 6 ++---
test/lib/wvpytest.py | 49 ++++++++++++++++++++------------------
6 files changed, 47 insertions(+), 39 deletions(-)

diff --git a/.pylintrc b/.pylintrc
index 3aa4c095..788e53de 100644
--- a/.pylintrc
+++ b/.pylintrc
@@ -1,6 +1,10 @@
# -*-conf-*-
[GENERAL OPTIONS]

+[BASIC]
+class-rgx=([_a-z]+)|(_?([A-Z]+[a-z]*)+) # LocalRepo mmap finalized...
+const-rgx=([_a-z]+)|([_A-Z]+) # snake-case uppper or lower
+
[VARIABLES]
ignored-argument-names=.*_$

@@ -34,6 +38,7 @@ enable=
function-redefined,
import-outside-toplevel,
inconsistent-return-statements,
+ invalid-name,
logging-not-lazy,
no-else-continue,
no-else-raise,
diff --git a/lib/bup/cmd/midx.py b/lib/bup/cmd/midx.py
index fb93e490..a97c4605 100644
--- a/lib/bup/cmd/midx.py
+++ b/lib/bup/cmd/midx.py
@@ -244,23 +244,23 @@ def do_midx_dir(path, outfilename, prout, auto=False, force=False,
all = [(sizes[n],n) for n in (midxs + idxs)]

# FIXME: what are the optimal values? Does this make sense?
- DESIRED_HWM = 1 if force else 5
- DESIRED_LWM = 1 if force else 2
+ desired_hwm = 1 if force else 5
+ desired_lwm = 1 if force else 2
existed = dict((name,1) for sz,name in all)
debug1('midx: %d indexes; want no more than %d.\n'
- % (len(all), DESIRED_HWM))
- if len(all) <= DESIRED_HWM:
+ % (len(all), desired_hwm))
+ if len(all) <= desired_hwm:
debug1('midx: nothing to do.\n')
- while len(all) > DESIRED_HWM:
+ while len(all) > desired_hwm:
all.sort()
- part1 = [name for sz,name in all[:len(all)-DESIRED_LWM+1]]
- part2 = all[len(all)-DESIRED_LWM+1:]
+ part1 = [name for sz,name in all[:len(all)-desired_lwm+1]]
+ part2 = all[len(all)-desired_lwm+1:]
all = list(do_midx_group(path, outfilename, part1,
auto=auto, force=force, max_files=max_files)) \
+ part2
- if len(all) > DESIRED_HWM:
+ if len(all) > desired_hwm:
debug1('\nStill too many indexes (%d > %d). Merging again.\n'
- % (len(all), DESIRED_HWM))
+ % (len(all), desired_hwm))

if print_names:
for sz,name in all:
diff --git a/lib/bup/cmd/tag.py b/lib/bup/cmd/tag.py
index 60160ccc..3870ada5 100644
--- a/lib/bup/cmd/tag.py
+++ b/lib/bup/cmd/tag.py
@@ -72,8 +72,8 @@ def main(argv):
log("bup: error: commit %s not found.\n" % commit.decode('ascii'))
return EXIT_FAILURE

- with git.PackIdxList(git.repo(b'objects/pack')) as pL:
- if not pL.exists(hash):
+ with git.PackIdxList(git.repo(b'objects/pack')) as pl:
+ if not pl.exists(hash):
log("bup: error: commit %s not found.\n" % commit.decode('ascii'))
return EXIT_FAILURE

diff --git a/lib/bup/git.py b/lib/bup/git.py
index 44b7447d..ee50822a 100644
--- a/lib/bup/git.py
+++ b/lib/bup/git.py
@@ -1158,8 +1158,8 @@ def rev_parse(committish, repo_dir=None):
except TypeError:
return None

- with PackIdxList(repo(b'objects/pack', repo_dir=repo_dir)) as pL:
- if pL.exists(hash):
+ with PackIdxList(repo(b'objects/pack', repo_dir=repo_dir)) as pl:
+ if pl.exists(hash):
return hash

return None
diff --git a/test/int/test_hashsplit.py b/test/int/test_hashsplit.py
index ba54b08d..12d0a1a3 100644
--- a/test/int/test_hashsplit.py
+++ b/test/int/test_hashsplit.py
@@ -208,7 +208,7 @@ def test_hashsplitter_object():
hs = HashSplitter([BytesIO(data)], bits=BUP_BLOBBITS, fanbits=1)
for blob, lvl in hs:
yield len(blob), 13 + lvl
- def _splitbufRHS(data):
+ def _splitbuf_rhs(data):
offs = None
fed = 0
data = data[:]
@@ -229,10 +229,10 @@ def test_hashsplitter_object():
yield fed, 13
data = b''.join([b'%d\n' % x for x in range(10000)])
WVPASSEQ(list(_splitbuf(data)),
- list(x for x in _splitbufRHS(data)))
+ list(x for x in _splitbuf_rhs(data)))
data = b''.join([b'%.10x\n' % x for x in range(10000)])
WVPASSEQ(list(_splitbuf(data)),
- list(_splitbufRHS(data)))
+ list(_splitbuf_rhs(data)))

def test_hashsplitter_short_read():
class DataObj:
diff --git a/test/lib/wvpytest.py b/test/lib/wvpytest.py
index 3e5f7755..b383eac1 100644
--- a/test/lib/wvpytest.py
+++ b/test/lib/wvpytest.py
@@ -2,55 +2,58 @@
import pytest


-def WVPASS(cond = True, fail_value=None):
+def wvpass(cond = True, fail_value=None):
if fail_value:
assert cond, fail_value
else:
assert cond

-def WVFAIL(cond = True):
+def wvfail(cond = True):
assert not cond

-def WVPASSEQ(a, b, fail_value=None):
+def wvpasseq(a, b, fail_value=None):
if fail_value:
assert a == b, fail_value
else:
assert a == b

-def WVPASSNE(a, b):
+def wvpassne(a, b):
assert a != b

-def WVPASSLT(a, b):
+def wvpasslt(a, b):
assert a < b

-def WVPASSLE(a, b):
+def wvpassle(a, b):
assert a <= b

-def WVPASSGT(a, b):
+def wvpassgt(a, b):
assert a > b

-def WVPASSGE(a, b):
+def wvpassge(a, b):
assert a >= b

-def WVEXCEPT(etype, func, *args, **kwargs):
+def wvexcept(etype, func, *args, **kwargs):
with pytest.raises(etype):
func(*args, **kwargs)

-def WVCHECK(cond, msg):
+def wvcheck(cond, msg):
assert cond, msg

-def WVMSG(msg):
+def wvmsg(msg):
print(msg)

-wvpass = WVPASS
-wvfail = WVFAIL
-wvpasseq = WVPASSEQ
-wvpassne = WVPASSNE
-wvpaslt = WVPASSLT
-wvpassle = WVPASSLE
-wvpassgt = WVPASSGT
-wvpassge = WVPASSGE
-wvexcept = WVEXCEPT
-wvcheck = WVCHECK
-wvmsg = WVMSG
-wvstart = WVMSG
+wvstart = wvmsg
+
+
+WVPASS = wvpass
+WVFAIL = wvfail
+WVPASSEQ = wvpasseq
+WVPASSNE = wvpassne
+WVPASSLT = wvpasslt
+WVPASSLE = wvpassle
+WVPASSGT = wvpassgt
+WVPASSGE = wvpassge
+WVEXCEPT = wvexcept
+WVCHECK = wvcheck
+WVMSG = wvmsg
+WVSTART = wvmsg
--
2.47.3

Rob Browning

unread,
Mar 6, 2026, 6:16:54 PM (8 days ago) Mar 6
to bup-...@googlegroups.com
Signed-off-by: Rob Browning <r...@defaultvalue.org>
Tested-by: Rob Browning <r...@defaultvalue.org>
---
.pylintrc | 1 +
lib/bup/cmd/fsck.py | 5 ++---
lib/bup/metadata.py | 1 +
test/int/test_helpers.py | 2 +-
4 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/.pylintrc b/.pylintrc
index 4eb948ba..41fae24b 100644
--- a/.pylintrc
+++ b/.pylintrc
@@ -49,6 +49,7 @@ enable=
unbalanced-tuple-unpacking,
undefined-loop-variable,
undefined-variable,
+ ungrouped-imports,
unidiomatic-typecheck,
unnecessary-comprehension,
unnecessary-lambda,
diff --git a/lib/bup/cmd/fsck.py b/lib/bup/cmd/fsck.py
index f4e89a27..9e5918ed 100644
--- a/lib/bup/cmd/fsck.py
+++ b/lib/bup/cmd/fsck.py
@@ -1,10 +1,9 @@

from os import SEEK_END
-from shutil import rmtree
+from os.path import join
+from shutil import copy2, rmtree
from subprocess import DEVNULL, PIPE, run
from tempfile import mkdtemp
-from os.path import join
-from shutil import copy2
import errno, glob, os, sys

from bup import options, git
diff --git a/lib/bup/metadata.py b/lib/bup/metadata.py
index 5252ac0f..1ca204d0 100644
--- a/lib/bup/metadata.py
+++ b/lib/bup/metadata.py
@@ -46,6 +46,7 @@ if sys.platform.startswith('linux'):
'upgrade or install python-pyxattr instead.\n')

try:
+ # pylint: disable-next=ungrouped-imports
from bup._helpers import read_acl, apply_acl
except ImportError:
read_acl = apply_acl = None
diff --git a/test/int/test_helpers.py b/test/int/test_helpers.py
index 2c5e32be..e26c70a8 100644
--- a/test/int/test_helpers.py
+++ b/test/int/test_helpers.py
@@ -1,10 +1,10 @@

from time import tzset
import os, os.path
-from bup import helpers

from wvpytest import *

+from bup import helpers
from bup.compat import environ
from bup.helpers import (atomically_replaced_file, detect_fakeroot,
grafted_path_components, parse_num,
--
2.47.3

Reply all
Reply to author
Forward
0 new messages