From fd34fa2d029aec978ae433862d035c9f3af699c4 Mon Sep 17 00:00:00 2001 From: Elmar Hoffmann Date: Sat, 28 May 2022 16:22:58 +0200 Subject: [PATCH] use relative imports Use relative imports where trivially possible for more consistency and to avoid using the borg module name explicitly. --- src/borg/archiver.py | 12 ++++++------ src/borg/helpers/checks.py | 5 ++--- src/borg/platform/base.py | 6 +++--- src/borg/testsuite/helpers.py | 4 ++-- 4 files changed, 13 insertions(+), 14 deletions(-) diff --git a/src/borg/archiver.py b/src/borg/archiver.py index 0dd91bcee..995a87bfe 100644 --- a/src/borg/archiver.py +++ b/src/borg/archiver.py @@ -622,7 +622,7 @@ class Archiver: key_96 = os.urandom(12) import io - from borg.chunker import get_chunker + from .chunker import get_chunker print("Chunkers =======================================================") size = "1GB" @@ -639,7 +639,7 @@ class Archiver: print(f"{spec:<24} {size:<10} {timeit(func, number=100):.3f}s") import zlib - from borg.checksums import crc32, deflate_crc32, xxh64 + from .checksums import crc32, deflate_crc32, xxh64 print("Non-cryptographic checksums / hashes ===========================") size = "1GB" tests = [ @@ -656,7 +656,7 @@ class Archiver: for spec, func in tests: print(f"{spec:<24} {size:<10} {timeit(func, number=100):.3f}s") - from borg.crypto.low_level import hmac_sha256, blake2b_256 + from .crypto.low_level import hmac_sha256, blake2b_256 print("Cryptographic hashes / MACs ====================================") size = "1GB" for spec, func in [ @@ -665,8 +665,8 @@ class Archiver: ]: print(f"{spec:<24} {size:<10} {timeit(func, number=100):.3f}s") - from borg.crypto.low_level import AES256_CTR_BLAKE2b, AES256_CTR_HMAC_SHA256 - from borg.crypto.low_level import AES256_OCB, CHACHA20_POLY1305 + from .crypto.low_level import AES256_CTR_BLAKE2b, AES256_CTR_HMAC_SHA256 + from .crypto.low_level import AES256_OCB, CHACHA20_POLY1305 print("Encryption =====================================================") size = "1GB" @@ -691,7 +691,7 @@ class Archiver: ]: print(f"{spec:<24} {count:<10} {timeit(func, number=count):.3f}s") - from borg.compress import CompressionSpec + from .compress import CompressionSpec print("Compression ====================================================") for spec in [ 'lz4', diff --git a/src/borg/helpers/checks.py b/src/borg/helpers/checks.py index 1d14788b9..316368b0c 100644 --- a/src/borg/helpers/checks.py +++ b/src/borg/helpers/checks.py @@ -23,15 +23,14 @@ class ExtensionModuleError(Error): def check_extension_modules(): - import borg.crypto.low_level - from .. import platform, compress, item, chunker, hashindex + from .. import platform, compress, crypto, item, chunker, hashindex if hashindex.API_VERSION != '1.2_01': raise ExtensionModuleError if chunker.API_VERSION != '1.2_01': raise ExtensionModuleError if compress.API_VERSION != '1.2_02': raise ExtensionModuleError - if borg.crypto.low_level.API_VERSION != '1.3_01': + if crypto.low_level.API_VERSION != '1.3_01': raise ExtensionModuleError if item.API_VERSION != '1.2_01': raise ExtensionModuleError diff --git a/src/borg/platform/base.py b/src/borg/platform/base.py index 2bd712cf6..3cfd82974 100644 --- a/src/borg/platform/base.py +++ b/src/borg/platform/base.py @@ -4,9 +4,9 @@ import socket import tempfile import uuid -from borg.constants import UMASK_DEFAULT -from borg.helpers import safe_unlink -from borg.platformflags import is_win32 +from ..constants import UMASK_DEFAULT +from ..helpers import safe_unlink +from ..platformflags import is_win32 """ platform base module diff --git a/src/borg/testsuite/helpers.py b/src/borg/testsuite/helpers.py index 8014101a5..54343eda8 100644 --- a/src/borg/testsuite/helpers.py +++ b/src/borg/testsuite/helpers.py @@ -245,7 +245,7 @@ class TestLocationWithoutEnv: Location('ssh://user@host:/path') def test_omit_archive(self): - from borg.platform import hostname + from ..platform import hostname loc = Location('ssh://user@host:1234/repos/{hostname}::archive') loc_without_archive = loc.omit_archive() assert loc_without_archive.archive is None @@ -264,7 +264,7 @@ class TestLocationWithEnv: "Location(proto='ssh', user='user', host='host', port=1234, path='/some/path', archive=None)" def test_ssh_placeholder(self, monkeypatch): - from borg.platform import hostname + from ..platform import hostname monkeypatch.setenv('BORG_REPO', 'ssh://user@host:1234/{hostname}') assert repr(Location('::archive')) == \ f"Location(proto='ssh', user='user', host='host', port=1234, path='/{hostname}', archive='archive')"