2
0
Эх сурвалжийг харах

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...
Antoine Beaupré 9 жил өмнө
parent
commit
9cbc868764
6 өөрчлөгдсөн 21 нэмэгдсэн , 14 устгасан
  1. 4 3
      borg/archive.py
  2. 6 5
      borg/archiver.py
  3. 4 3
      borg/helpers.py
  4. 3 2
      borg/key.py
  5. 2 1
      borg/repository.py
  6. 2 0
      setup.py

+ 4 - 3
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
 

+ 6 - 5
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, \

+ 4 - 3
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):

+ 3 - 2
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

+ 2 - 1
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

+ 2 - 0
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 = {}