diff --git a/newsfragments/768.feature b/newsfragments/768.feature new file mode 100644 index 000000000..9ac92167c --- /dev/null +++ b/newsfragments/768.feature @@ -0,0 +1,2 @@ +``dials.import``: add a progress bar for the import process, particularly +useful when importing thousands of files diff --git a/newsfragments/773.bugfix b/newsfragments/773.bugfix new file mode 100644 index 000000000..a9df61b72 --- /dev/null +++ b/newsfragments/773.bugfix @@ -0,0 +1 @@ +``dials.import``: force tqdm output to stdout not stderr as default \ No newline at end of file diff --git a/newsfragments/774.bugfix b/newsfragments/774.bugfix new file mode 100644 index 000000000..6f355b5f5 --- /dev/null +++ b/newsfragments/774.bugfix @@ -0,0 +1 @@ +``dials.show``: hide tqdm if DIALS_NOBANNER diff --git a/newsfragments/775.bugfix b/newsfragments/775.bugfix new file mode 100644 index 000000000..450b4bd4a --- /dev/null +++ b/newsfragments/775.bugfix @@ -0,0 +1 @@ +``dials.import``: set tqdm output to stdout (again) diff --git a/src/dxtbx/model/experiment_list.py b/src/dxtbx/model/experiment_list.py index 1386fd231..4ab93b966 100644 --- a/src/dxtbx/model/experiment_list.py +++ b/src/dxtbx/model/experiment_list.py @@ -14,6 +14,7 @@ from typing import Any, Callable, Generator, Iterable import natsort +from tqdm import tqdm import dxtbx from dxtbx.format.Format import Format @@ -664,6 +665,9 @@ def from_filenames( """Create a list of data blocks from a list of directory or file names.""" experiments = ExperimentList() + # Cast filenames to a list from whatever iterator they are + filenames = list(filenames) + # Process each file given by this path list to_process = _openingpathiterator(filenames) find_format = FormatChecker() @@ -671,7 +675,13 @@ def from_filenames( format_groups = collections.defaultdict(list) if format_kwargs is None: format_kwargs = {} - for filename in to_process: + + if os.isatty and len(filenames) > 1 and "DIALS_NOBANNER" not in os.environ: + filename_iter = tqdm(to_process, total=len(filenames), file=sys.stdout) + else: + filename_iter = to_process + + for filename in filename_iter: # We now have a file, pre-opened by Format.open_file (therefore # cached). Determine its type, and prepare to put into a group format_class = find_format.find_format(filename)