Skip to content

Commit 8a5dafa

Browse files
addressed comments so far
1 parent 435b127 commit 8a5dafa

File tree

3 files changed

+34
-25
lines changed

3 files changed

+34
-25
lines changed

src/diffpy/labpdfproc/labpdfprocapp.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from pathlib import Path
44

55
from diffpy.labpdfproc.functions import apply_corr, compute_cve
6-
from diffpy.labpdfproc.tools import load_additional_info
6+
from diffpy.labpdfproc.tools import load_user_metadata
77
from diffpy.utils.parsers.loaddata import loadData
88
from diffpy.utils.scattering_objects.diffraction_objects import XQUANTITIES, Diffraction_object
99

@@ -37,7 +37,7 @@ def get_args():
3737
p.add_argument(
3838
"-x",
3939
"--xtype",
40-
help=f"the quantity on the independnt variable axis. allowed "
40+
help=f"the quantity on the independent variable axis. allowed "
4141
f"values: {*XQUANTITIES, }. If not specified then two-theta "
4242
f"is assumed for the independent variable. Only implemented for "
4343
f"tth currently",
@@ -55,23 +55,23 @@ def get_args():
5555
"-f",
5656
"--force-overwrite",
5757
action="store_true",
58-
help="outputs will not overwrite existing file unless --force is spacified",
58+
help="outputs will not overwrite existing file unless --force is specified",
5959
)
6060
p.add_argument(
61-
"-add",
62-
"--additional-info",
61+
"-u",
62+
"--user-metadata",
6363
metavar=("KEY=VALUE"),
6464
action="append",
6565
help="specify key-value pairs to be loaded into metadata by using key=value. "
66-
"You can specify multiple paris by calling -add multiple times.",
66+
"You can specify multiple paris by calling -u multiple times.",
6767
)
6868
args = p.parse_args()
6969
return args
7070

7171

7272
def main():
7373
args = get_args()
74-
args = load_additional_info(args)
74+
args = load_user_metadata(args)
7575
wavelength = WAVELENGTHS[args.anode_type]
7676
filepath = Path(args.input_file)
7777
outfilestem = filepath.stem + "_corrected"

src/diffpy/labpdfproc/tests/test_tools.py

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,26 @@
22

33
import pytest
44

5-
from diffpy.labpdfproc.tools import load_additional_info
5+
from diffpy.labpdfproc.tools import load_user_metadata
66

77
params5 = [
8-
([], []),
9-
([["weather=rainy"]], [["weather", "rainy"]]),
8+
([[]], []),
9+
([["toast=for breakfast"]], [["toast", "for breakfast"]]),
10+
([["mylist=[1,2,3.0]"]], [["mylist", "[1,2,3.0]"]]),
1011
([["weather=rainy", "day=tuesday"]], [["weather", "rainy"], ["day", "tuesday"]]),
1112
]
1213

1314

1415
@pytest.mark.parametrize("inputs, expected", params5)
1516
def test_load_additional_info(inputs, expected):
1617
actual_parser = ArgumentParser()
17-
actual_parser.add_argument("-add", "--additional-info", action="append", metavar=("KEY=VALUE"))
18+
actual_parser.add_argument("-u", "--user-metadata", action="append", metavar=("KEY=VALUE"))
1819
actual_args = actual_parser.parse_args([])
1920
expected_parser = ArgumentParser()
2021
expected_args = expected_parser.parse_args([])
2122

22-
if not inputs:
23-
actual_args = load_additional_info(actual_args)
24-
assert actual_args == expected_args
25-
else:
26-
setattr(actual_args, "additional_info", inputs[0])
27-
actual_args = load_additional_info(actual_args)
28-
for expected_pair in expected:
29-
setattr(expected_args, expected_pair[0], expected_pair[1])
30-
assert actual_args == expected_args
23+
setattr(actual_args, "user_metadata", inputs[0])
24+
actual_args = load_user_metadata(actual_args)
25+
for expected_pair in expected:
26+
setattr(expected_args, expected_pair[0], expected_pair[1])
27+
assert actual_args == expected_args

src/diffpy/labpdfproc/tools.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,19 @@
1-
def load_additional_info(args):
2-
if args.additional_info:
3-
for item in args.additional_info:
4-
key, value = item.split("=")
1+
import sys
2+
3+
4+
def load_user_metadata(args):
5+
if args.user_metadata:
6+
for item in args.user_metadata:
7+
if not item:
8+
sys.exit(
9+
"please provide at least one key-value pair in the format key=value. "
10+
"you can exclude -add if you don't want to provide additional info."
11+
)
12+
if "=" not in item:
13+
sys.exit("please provide key-value pairs in the format key=value.")
14+
key, value = item.split("=", 1)
15+
# if "=" in value:
16+
# sys.exit("please use only one equals sign for key=value.")
517
setattr(args, key, value)
6-
delattr(args, "additional_info")
18+
delattr(args, "user_metadata")
719
return args

0 commit comments

Comments
 (0)