From 9cbc868764a83fe6e1d39e07c5dfdef3e8baa72a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20Beaupr=C3=A9?= Date: Wed, 7 Oct 2015 22:24:30 -0400 Subject: [PATCH] make tests and build work again in usage using environment this is such a crude hack it is totally embarrassing.... the proper solution would probably be to move the `build_parser()` function out of `Archiver` completely, but this is such an undertaking that i doubt it is worth doing since we're looking at switching to click anyways. the main problem in moving build_parser() out is that it references `self` all the time, so it *needs* an archiver context that it can reuse. we could make the function static and pass self in there by hand, but it seems like almost a worse hack... and besides, we would need to load the archiver in order to do that, which would break usage all over again... --- borg/archive.py | 7 ++++--- borg/archiver.py | 11 ++++++----- borg/helpers.py | 7 ++++--- borg/key.py | 5 +++-- borg/repository.py | 3 ++- setup.py | 2 ++ 6 files changed, 21 insertions(+), 14 deletions(-) diff --git a/borg/archive.py b/borg/archive.py index d6eff1ba9..8350bbebc 100644 --- a/borg/archive.py +++ b/borg/archive.py @@ -12,9 +12,10 @@ import sys import time from io import BytesIO from . import xattr -from .platform import acl_get, acl_set -from .chunker import Chunker -from .hashindex import ChunkIndex +if not os.environ.get('BORG_GEN_USAGE', False): + from .platform import acl_get, acl_set + from .chunker import Chunker + from .hashindex import ChunkIndex from .helpers import parse_timestamp, Error, uid2user, user2uid, gid2group, group2gid, \ Manifest, Statistics, decode_dict, st_mtime_ns, make_path_safe, StableDict, int_to_bigint, bigint_to_int diff --git a/borg/archiver.py b/borg/archiver.py index 9b18486c8..bd49da7c9 100644 --- a/borg/archiver.py +++ b/borg/archiver.py @@ -15,12 +15,13 @@ import textwrap import traceback from . import __version__ +if not os.environ.get('BORG_GEN_USAGE', False): + 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 .compress import Compressor, COMPR_BUFFER -from .upgrader import AtticRepositoryUpgrader -from .repository import Repository -from .cache import Cache -from .key import key_creator 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, format_timedelta, prune_within, prune_split, \ diff --git a/borg/helpers.py b/borg/helpers.py index 47d454bec..175ebf15c 100644 --- a/borg/helpers.py +++ b/borg/helpers.py @@ -18,9 +18,10 @@ from operator import attrgetter import msgpack -from . import hashindex -from . import chunker -from . import crypto +if not os.environ.get('BORG_GEN_USAGE', False): + from . import hashindex + from . import chunker + from . import crypto class Error(Exception): diff --git a/borg/key.py b/borg/key.py index 7067a4454..877b37711 100644 --- a/borg/key.py +++ b/borg/key.py @@ -7,8 +7,9 @@ import textwrap import hmac from hashlib import sha256 -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 +if not os.environ.get('BORG_GEN_USAGE', False): + 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 from .helpers import IntegrityError, get_keys_dir, Error PREFIX = b'\0' * 8 diff --git a/borg/repository.py b/borg/repository.py index 932e4fef3..30163b02c 100644 --- a/borg/repository.py +++ b/borg/repository.py @@ -8,7 +8,8 @@ import struct import sys from zlib import crc32 -from .hashindex import NSIndex +if not os.environ.get('BORG_GEN_USAGE', False): + from .hashindex import NSIndex from .helpers import Error, IntegrityError, read_msgpack, write_msgpack, unhexlify from .locking import UpgradableLock from .lrucache import LRUCache diff --git a/setup.py b/setup.py index 2f29b4a20..3a5286b70 100644 --- a/setup.py +++ b/setup.py @@ -136,6 +136,8 @@ class build_usage(Command): def run(self): import pdb print('generating usage docs') + # XXX: gross hack: allows us to skip loading C modules during help generation + os.environ['BORG_GEN_USAGE'] = "True" from borg.archiver import Archiver parser = Archiver().build_parser(prog='borg') choices = {}