From 080e8bd91c68b4c65de45c5f0f100bbd2409e117 Mon Sep 17 00:00:00 2001 From: Sparks29032 Date: Sat, 7 Dec 2024 21:55:33 -0500 Subject: [PATCH 1/6] Fix for multiple subdirectories --- src/diffpy/pdfmorph/pdfmorphapp.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/diffpy/pdfmorph/pdfmorphapp.py b/src/diffpy/pdfmorph/pdfmorphapp.py index 2a25a5f..ea4aa69 100755 --- a/src/diffpy/pdfmorph/pdfmorphapp.py +++ b/src/diffpy/pdfmorph/pdfmorphapp.py @@ -487,14 +487,14 @@ def single_morph(parser, opts, pargs, stdout_flag=True): parser.custom_error(save_fail_message) if opts.plot: - pairlist = [chain.xy_morph_out, chain.xy_target_out] - labels = [pargs[0], pargs[1]] # Default is to use file names + pairlist = [chain.xy_target_out, chain.xy_morph_out] + labels = [pargs[1], pargs[0]] # Default is to use file names # If user chooses labels if opts.mlabel is not None: - labels[0] = opts.mlabel + labels[1] = opts.mlabel if opts.tlabel is not None: - labels[1] = opts.tlabel + labels[0] = opts.tlabel # Plot extent defaults to calculation extent pmin = opts.pmin if opts.pmin is not None else opts.rmin @@ -536,6 +536,8 @@ def multiple_targets(parser, opts, pargs, stdout_flag=True): for target in target_list: if target.is_dir(): target_list.remove(target) + for morph in to_remove: + morph_list.remove(morph) # Do not morph morph_file against itself if it is in the same directory if morph_file in target_list: @@ -678,9 +680,12 @@ def multiple_morphs(parser, opts, pargs, stdout_flag=True): # Get list of files from morph directory morph_list = list(morph_directory.iterdir()) + to_remove = [] for morph in morph_list: if morph.is_dir(): - morph_list.remove(morph) + to_remove.append(morph) + for morph in to_remove: + morph_list.remove(morph) # Do not morph target_file against itself if it is in the same directory if target_file in morph_list: From e2b1eb0354881e2aeb87e57867693d1f356d54b2 Mon Sep 17 00:00:00 2001 From: Sparks29032 Date: Sat, 7 Dec 2024 21:57:14 -0500 Subject: [PATCH 2/6] news --- news/hotfix.rst | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 news/hotfix.rst diff --git a/news/hotfix.rst b/news/hotfix.rst new file mode 100644 index 0000000..02b165e --- /dev/null +++ b/news/hotfix.rst @@ -0,0 +1,23 @@ +**Added:** + +* + +**Changed:** + +* + +**Deprecated:** + +* + +**Removed:** + +* + +**Fixed:** + +* Multiple morphs/targets used to break given multiple subdirectories. + +**Security:** + +* From 052a8aa35bdca2be5e2e25ba7881a78d4e83a36f Mon Sep 17 00:00:00 2001 From: Sparks29032 Date: Sat, 7 Dec 2024 21:58:28 -0500 Subject: [PATCH 3/6] Missing line --- src/diffpy/pdfmorph/pdfmorphapp.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/diffpy/pdfmorph/pdfmorphapp.py b/src/diffpy/pdfmorph/pdfmorphapp.py index ea4aa69..8028066 100755 --- a/src/diffpy/pdfmorph/pdfmorphapp.py +++ b/src/diffpy/pdfmorph/pdfmorphapp.py @@ -533,6 +533,7 @@ def multiple_targets(parser, opts, pargs, stdout_flag=True): # Get list of files from target directory target_list = list(target_directory.iterdir()) + to_remove = [] for target in target_list: if target.is_dir(): target_list.remove(target) From 67d12621cd2b6599f801ed83613b15744d363bee Mon Sep 17 00:00:00 2001 From: Sparks29032 Date: Sat, 7 Dec 2024 21:59:13 -0500 Subject: [PATCH 4/6] Update for targets --- src/diffpy/pdfmorph/pdfmorphapp.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/diffpy/pdfmorph/pdfmorphapp.py b/src/diffpy/pdfmorph/pdfmorphapp.py index 8028066..61252de 100755 --- a/src/diffpy/pdfmorph/pdfmorphapp.py +++ b/src/diffpy/pdfmorph/pdfmorphapp.py @@ -536,9 +536,9 @@ def multiple_targets(parser, opts, pargs, stdout_flag=True): to_remove = [] for target in target_list: if target.is_dir(): - target_list.remove(target) - for morph in to_remove: - morph_list.remove(morph) + to_remove.append(target) + for target in to_remove: + target_list.remove(target) # Do not morph morph_file against itself if it is in the same directory if morph_file in target_list: From 290e839279f869301a39a68bc769da226bd434a4 Mon Sep 17 00:00:00 2001 From: Sparks29032 Date: Mon, 9 Dec 2024 12:32:25 -0500 Subject: [PATCH 5/6] Add to tests --- tests/testdata/testsequence/ignore_dir_1/ignore_1.txt | 1 + tests/testdata/testsequence/ignore_dir_2/ignore_2.txt | 1 + 2 files changed, 2 insertions(+) create mode 100644 tests/testdata/testsequence/ignore_dir_1/ignore_1.txt create mode 100644 tests/testdata/testsequence/ignore_dir_2/ignore_2.txt diff --git a/tests/testdata/testsequence/ignore_dir_1/ignore_1.txt b/tests/testdata/testsequence/ignore_dir_1/ignore_1.txt new file mode 100644 index 0000000..ed6385c --- /dev/null +++ b/tests/testdata/testsequence/ignore_dir_1/ignore_1.txt @@ -0,0 +1 @@ +This directory should be ignored by PDFmorph. diff --git a/tests/testdata/testsequence/ignore_dir_2/ignore_2.txt b/tests/testdata/testsequence/ignore_dir_2/ignore_2.txt new file mode 100644 index 0000000..f7f3749 --- /dev/null +++ b/tests/testdata/testsequence/ignore_dir_2/ignore_2.txt @@ -0,0 +1 @@ +All directories should be ignored by the multiple-morph/target command searches. From 29a8fe83d6fe8b0931859240d9329f14d80af132 Mon Sep 17 00:00:00 2001 From: Sparks29032 Date: Mon, 9 Dec 2024 12:50:43 -0500 Subject: [PATCH 6/6] os to pathlib --- tests/test_tools.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/tests/test_tools.py b/tests/test_tools.py index 7bf79e1..cc89196 100644 --- a/tests/test_tools.py +++ b/tests/test_tools.py @@ -60,10 +60,16 @@ def test_nn_value(self, setup): pytest.approx(tools.nn_value(-value, name=None), abs(-value)) def test_field_sort(self, setup): - sequence_files = [*os.listdir(testsequence_dir)] + sequence_files = [file for file in Path(testsequence_dir).iterdir()] + to_remove = [] + for file in sequence_files: + if file.is_dir(): + to_remove.append(file) + for d in to_remove: + sequence_files.remove(d) absolute_sf = [] for file in sequence_files: - absolute_sf.append(os.path.join(testsequence_dir, file)) + absolute_sf.append(Path(testsequence_dir) / file.name) # Fisher-Yates randomization import random @@ -84,8 +90,8 @@ def test_field_sort(self, setup): sorted_sequence.append(path.name) # Temperature sort should produce same result as alphanumerical if leading character is removed - sequence_files.sort(key=lambda entry: entry[2:]) - assert sequence_files == sorted_sequence + sequence_files.sort(key=lambda entry: entry.name[2:]) + assert [file.name for file in sequence_files] == sorted_sequence # Check temperatures are correct assert fvs == [174, 180, 186, 192, 198, 204, 210] @@ -98,7 +104,7 @@ def test_field_sort(self, setup): # Reversed sort should match alphanumerical sort sequence_files.sort() - assert sequence_files == reversed_sequence + assert [file.name for file in sequence_files] == reversed_sequence # Check we get the same sequence when we load header information from a serial file serial_file = os.path.join(testdata_dir, "testsequence_serialfile.json") @@ -106,7 +112,7 @@ def test_field_sort(self, setup): metadata_sequence = [] for path in metadata_path_sequence: metadata_sequence.append(path.name) - assert sequence_files == metadata_sequence + assert [file.name for file in sequence_files] == metadata_sequence # Check error thrown when field does not exist with pytest.raises(KeyError):