From f13dd6e579299c3a7997c3722fe8e2450ccea448 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20Beaupr=C3=A9?= Date: Fri, 13 Nov 2015 10:38:50 -0500 Subject: [PATCH] completely remove have_cython() hack this was making us require mock, which is really a test component and shouldn't be part of the runtime dependencies. furthermore, it was making the imports and the code more brittle: it may have been possible that, through an environment variable, backups could be corrupted because mock libraries would be configured instead of real once, which is a risk we shouldn't be taking. finally, this was used only to build docs, which we will build and commit to git by hand with a fully working borg when relevant. see #384. --- borg/archive.py | 14 +++++--------- borg/archiver.py | 13 ++++++------- borg/cache.py | 5 ++--- borg/fuse.py | 5 ++--- borg/helpers.py | 26 +++++--------------------- borg/key.py | 9 ++++----- borg/remote.py | 5 ++--- borg/repository.py | 5 ++--- docs/usage.rst | 6 ------ setup.py | 5 ----- 10 files changed, 28 insertions(+), 65 deletions(-) diff --git a/borg/archive.py b/borg/archive.py index 008909a2f..d5b46792c 100644 --- a/borg/archive.py +++ b/borg/archive.py @@ -18,16 +18,12 @@ import time from io import BytesIO from . import xattr from .helpers import parse_timestamp, Error, uid2user, user2uid, gid2group, group2gid, format_timedelta, \ - Manifest, Statistics, decode_dict, make_path_safe, StableDict, int_to_bigint, bigint_to_int, have_cython, \ + Manifest, Statistics, decode_dict, make_path_safe, StableDict, int_to_bigint, bigint_to_int, \ st_atime_ns, st_ctime_ns, st_mtime_ns -if have_cython(): - from .platform import acl_get, acl_set - from .chunker import Chunker - from .hashindex import ChunkIndex - import msgpack -else: - import mock - msgpack = mock.Mock() +from .platform import acl_get, acl_set +from .chunker import Chunker +from .hashindex import ChunkIndex +import msgpack ITEMS_BUFFER = 1024 * 1024 diff --git a/borg/archiver.py b/borg/archiver.py index 5512bb258..ff6c4b3b5 100644 --- a/borg/archiver.py +++ b/borg/archiver.py @@ -20,16 +20,15 @@ from .helpers import Error, location_validator, format_time, format_file_size, \ format_file_mode, ExcludePattern, IncludePattern, exclude_path, adjust_patterns, to_localtime, timestamp, \ get_cache_dir, get_keys_dir, prune_within, prune_split, unhexlify, \ Manifest, remove_surrogates, update_excludes, format_archive, check_extension_modules, Statistics, \ - dir_is_tagged, bigint_to_int, ChunkerParams, CompressionSpec, have_cython, is_slow_msgpack, yes, \ + dir_is_tagged, bigint_to_int, ChunkerParams, CompressionSpec, is_slow_msgpack, yes, \ EXIT_SUCCESS, EXIT_WARNING, EXIT_ERROR from .logger import create_logger, setup_logging logger = create_logger() -if have_cython(): - from .compress import Compressor, COMPR_BUFFER - from .upgrader import AtticRepositoryUpgrader - from .repository import Repository - from .cache import Cache - from .key import key_creator +from .compress import Compressor, COMPR_BUFFER +from .upgrader import AtticRepositoryUpgrader +from .repository import Repository +from .cache import Cache +from .key import key_creator from .archive import Archive, ArchiveChecker, CHUNKER_PARAMS from .remote import RepositoryServer, RemoteRepository diff --git a/borg/cache.py b/borg/cache.py index 38ef42081..89aedd4f9 100644 --- a/borg/cache.py +++ b/borg/cache.py @@ -10,12 +10,11 @@ from .key import PlaintextKey from .logger import create_logger logger = create_logger() from .helpers import Error, get_cache_dir, decode_dict, st_mtime_ns, unhexlify, int_to_bigint, \ - bigint_to_int, format_file_size, have_cython, yes + bigint_to_int, format_file_size, yes from .locking import UpgradableLock from .hashindex import ChunkIndex -if have_cython(): - import msgpack +import msgpack class Cache: diff --git a/borg/fuse.py b/borg/fuse.py index 417811feb..19dc09cc9 100644 --- a/borg/fuse.py +++ b/borg/fuse.py @@ -7,11 +7,10 @@ import stat import tempfile import time from .archive import Archive -from .helpers import daemonize, have_cython +from .helpers import daemonize from .remote import cache_if_remote -if have_cython(): - import msgpack +import msgpack # Does this version of llfuse support ns precision? have_fuse_xtime_ns = hasattr(llfuse.EntryAttributes, 'st_mtime_ns') diff --git a/borg/helpers.py b/borg/helpers.py index 84379e75a..1937c9bf0 100644 --- a/borg/helpers.py +++ b/borg/helpers.py @@ -22,27 +22,11 @@ from fnmatch import translate from operator import attrgetter -def have_cython(): - """allow for a way to disable Cython includes - - this is used during usage docs build, in setup.py. It is to avoid - loading the Cython libraries which are built, but sometimes not in - the search path (namely, during Tox runs). - - we simply check an environment variable (``BORG_CYTHON_DISABLE``) - which, when set (to anything) will disable includes of Cython - libraries in key places to enable usage docs to be built. - - :returns: True if Cython is available, False otherwise. - """ - return not os.environ.get('BORG_CYTHON_DISABLE') - -if have_cython(): - from . import hashindex - from . import chunker - from . import crypto - import msgpack - import msgpack.fallback +from . import hashindex +from . import chunker +from . import crypto +import msgpack +import msgpack.fallback # return codes returned by borg command diff --git a/borg/key.py b/borg/key.py index 78bfa8b70..a712cd133 100644 --- a/borg/key.py +++ b/borg/key.py @@ -7,14 +7,13 @@ import textwrap import hmac from hashlib import sha256 -from .helpers import IntegrityError, get_keys_dir, Error, have_cython +from .helpers import IntegrityError, get_keys_dir, Error from .logger import create_logger logger = create_logger() -if have_cython(): - from .crypto import pbkdf2_sha256, get_random_bytes, AES, bytes_to_long, long_to_bytes, bytes_to_int, num_aes_blocks - from .compress import Compressor, COMPR_BUFFER - import msgpack +from .crypto import pbkdf2_sha256, get_random_bytes, AES, bytes_to_long, long_to_bytes, bytes_to_int, num_aes_blocks +from .compress import Compressor, COMPR_BUFFER +import msgpack PREFIX = b'\0' * 8 diff --git a/borg/remote.py b/borg/remote.py index 82353fef0..df435ebce 100644 --- a/borg/remote.py +++ b/borg/remote.py @@ -10,11 +10,10 @@ import traceback from . import __version__ -from .helpers import Error, IntegrityError, have_cython +from .helpers import Error, IntegrityError from .repository import Repository -if have_cython(): - import msgpack +import msgpack BUFSIZE = 10 * 1024 * 1024 diff --git a/borg/repository.py b/borg/repository.py index 048fa032d..0127bca3b 100644 --- a/borg/repository.py +++ b/borg/repository.py @@ -10,9 +10,8 @@ import shutil import struct from zlib import crc32 -from .helpers import Error, ErrorWithTraceback, IntegrityError, read_msgpack, write_msgpack, unhexlify, have_cython -if have_cython(): - from .hashindex import NSIndex +from .helpers import Error, ErrorWithTraceback, IntegrityError, read_msgpack, write_msgpack, unhexlify +from .hashindex import NSIndex from .locking import UpgradableLock from .lrucache import LRUCache diff --git a/docs/usage.rst b/docs/usage.rst index 46ecd4bf2..abeb074a8 100644 --- a/docs/usage.rst +++ b/docs/usage.rst @@ -59,12 +59,6 @@ Some "yes" sayers (if set, they automatically confirm that you really want to do For "Warning: The repository at location ... was previously located at ..." BORG_CHECK_I_KNOW_WHAT_I_AM_DOING For "Warning: 'check --repair' is an experimental feature that might result in data loss." - BORG_CYTHON_DISABLE - Disables the loading of Cython modules. This is currently - experimental and is used only to generate usage docs at build - time. It is unlikely to produce good results on a regular - run. The variable should be set to the name of the calling class, and - should be unique across all of borg. It is currently only used by ``build_usage``. Directories: BORG_KEYS_DIR diff --git a/setup.py b/setup.py index 5c6e98a2f..cf699447e 100644 --- a/setup.py +++ b/setup.py @@ -135,8 +135,6 @@ class build_usage(Command): def run(self): print('generating usage docs') # allows us to build docs without the C modules fully loaded during help generation - if 'BORG_CYTHON_DISABLE' not in os.environ: - os.environ['BORG_CYTHON_DISABLE'] = self.__class__.__name__ from borg.archiver import Archiver parser = Archiver().build_parser(prog='borg') choices = {} @@ -166,9 +164,6 @@ class build_usage(Command): doc.write(re.sub("^", " ", parser.format_help(), flags=re.M)) doc.write("\nDescription\n~~~~~~~~~~~\n") doc.write(epilog) - # return to regular Cython configuration, if we changed it - if os.environ.get('BORG_CYTHON_DISABLE') == self.__class__.__name__: - del os.environ['BORG_CYTHON_DISABLE'] class build_api(Command):