Skip to content

Commit

Permalink
fix: Read files even without progress bar ...
Browse files Browse the repository at this point in the history
Fixes #50
  • Loading branch information
thvitt committed Feb 22, 2023
1 parent f93e546 commit a228597
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
5 changes: 3 additions & 2 deletions src/macrogen/config.py
Expand Up @@ -328,9 +328,10 @@ def progress(self, iterable, *args, **kwargs):
kwargs['dynamic_ncols'] = True
with tqdm_logging_redirect():
yield from tqdm(iterable, *args, **kwargs)
return
except ImportError:
pass
return iterable
logger.info('Could not import progress bar, working without progress info')
yield from iterable

def relative_path(self, absolute_path):
return Path(absolute_path).relative_to(self.path.data)
Expand Down
5 changes: 4 additions & 1 deletion src/macrogen/uris.py
Expand Up @@ -241,7 +241,8 @@ def uris(self):
@classmethod
def _load_database(cls):
cls.corrections = cls._load_corrections()
sigil_data = [doc.to_record() for doc in all_documents()]
documents = all_documents()
sigil_data = [doc.to_record() for doc in documents]
cls.database = cls.build_database(sigil_data)

@classmethod
Expand All @@ -266,6 +267,8 @@ def _load_paralipomena(cls, url=None):
@classmethod
def build_database(cls, sigil_data):
database = {}
if len(sigil_data) == 0:
raise ValueError('No sigil data!')
for doc in sigil_data:
wit = cls(doc)
for uri in wit.uris():
Expand Down
7 changes: 5 additions & 2 deletions src/macrogen/witnesses.py
Expand Up @@ -312,7 +312,10 @@ def resolve(self, arg: str, inscription: Optional[str]=None):

@lru_cache()
def all_documents(path: Optional[Path] = None):
logger.debug('Reading inscription info from sources ...')
if path is None:
path = config.path.data.joinpath('document')
return [Document(doc) for doc in config.progress(list(path.rglob('**/*.xml')))]
logger.debug('Reading inscription info from sources in %s...', path)
files = list(path.glob('**/*.xml'))
if not files:
raise ValueError(f'No XML files found in {path}!')
return [Document(doc) for doc in (config.progress(files))]

0 comments on commit a228597

Please sign in to comment.