use relative imports

Use relative imports where trivially possible for more consistency and to
avoid using the borg module name explicitly.
This commit is contained in:
Elmar Hoffmann 2022-05-28 16:22:58 +02:00
parent c34df51e3e
commit fd34fa2d02
4 changed files with 13 additions and 14 deletions

View File

@ -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',

View File

@ -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

View File

@ -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

View File

@ -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')"