Skip to content

Commit af6faee

Browse files
authored
Merge pull request #48 from NREL/pp/separate_param_doc
Separate param docs
2 parents a45f225 + bcab668 commit af6faee

File tree

7 files changed

+74
-34
lines changed

7 files changed

+74
-34
lines changed

examples/example_users.rst

+7-7
Original file line numberDiff line numberDiff line change
@@ -846,11 +846,11 @@ combinations into multiple sets in our batch config:
846846
"sets": [
847847
{
848848
"args": {
849-
"wind_turbine_hub_ht": [100],
849+
"wind_turbine_hub_ht": [110],
850850
"wind_turbine_rotor_diameter": [145, 170]
851851
},
852852
"files": ["./turbine.json"],
853-
"set_tag": "100hh"
853+
"set_tag": "110hh"
854854
},
855855
{
856856
"args": {
@@ -869,7 +869,7 @@ Now if we run batch (``--dry``), we will only get three sub-directories, which i
869869
shell
870870
871871
$ ls
872-
100hh_wtrd145 100hh_wtrd170 120hh_wtrd160 batch_jobs.csv config_batch.json config_gen.json config_pipeline.json turbine.json
872+
110hh_wtrd145 110hh_wtrd170 120hh_wtrd160 batch_jobs.csv config_batch.json config_gen.json config_pipeline.json turbine.json
873873
874874
Note how we used the ``"set_tag"`` key to get consistent names across the newly-created runs. Once again,
875875
we can verify that batch correctly updated the parameters in each sub-directory:
@@ -878,21 +878,21 @@ we can verify that batch correctly updated the parameters in each sub-directory:
878878
.. code-block::
879879
shell
880880
881-
$ cat 100hh_wtrd145/turbine.json
881+
$ cat 110hh_wtrd145/turbine.json
882882
{
883883
...
884884
"wind_turbine_rotor_diameter": 145,
885885
...
886-
"wind_turbine_hub_ht": 100,
886+
"wind_turbine_hub_ht": 110,
887887
...
888888
}
889889
890-
$ cat 100hh_wtrd170/turbine.json
890+
$ cat 110hh_wtrd170/turbine.json
891891
{
892892
...
893893
"wind_turbine_rotor_diameter": 170,
894894
...
895-
"wind_turbine_hub_ht": 100,
895+
"wind_turbine_hub_ht": 110,
896896
...
897897
}
898898

gaps/cli/documentation.py

+21-9
Original file line numberDiff line numberDiff line change
@@ -501,22 +501,34 @@ def template_config(self):
501501
)
502502
return config
503503

504+
@property
505+
def _parameter_npd(self):
506+
"""NumpyDocString: Parameter help `NumpyDocString` instance."""
507+
param_doc = NumpyDocString("")
508+
param_doc["Parameters"] = [
509+
p
510+
for doc in self.docs
511+
for p in doc["Parameters"]
512+
if p.name in self.template_config
513+
]
514+
return param_doc
515+
504516
@property
505517
def parameter_help(self):
518+
"""str: Parameter help for the func."""
519+
return str(self._parameter_npd)
520+
521+
@property
522+
def hpc_parameter_help(self):
506523
"""str: Parameter help for the func, including execution control."""
507524
exec_dict_param = [
508525
p
509526
for p in NumpyDocString(self.exec_control_doc)["Parameters"]
510527
if p.name in {"execution_control", "log_directory", "log_level"}
511528
]
512-
param_only_doc = NumpyDocString("")
513-
param_only_doc["Parameters"] = exec_dict_param + [
514-
p
515-
for doc in self.docs
516-
for p in doc["Parameters"]
517-
if p.name in self.template_config
518-
]
519-
return "\n".join(_format_lines(str(param_only_doc).split("\n")))
529+
param_doc = deepcopy(self._parameter_npd)
530+
param_doc["Parameters"] = exec_dict_param + param_doc["Parameters"]
531+
return "\n".join(_format_lines(str(param_doc).split("\n")))
520532

521533
@property
522534
def extended_summary(self):
@@ -557,7 +569,7 @@ def config_help(self, command_name):
557569
doc = CONFIG_DOC.format(
558570
name=command_name,
559571
sample_config=sample_config,
560-
docstring=self.parameter_help,
572+
docstring=self.hpc_parameter_help,
561573
)
562574
return _cli_formatted(doc)
563575

gaps/version.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
"""GAPs Version Number. """
22

3-
__version__ = "0.6.11"
3+
__version__ = "0.6.12"

requirements.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
click>=8.1.3
22
colorama>=0.4.6
33
NREL-rex>=0.2.80
4-
numpy>=1.22.0
4+
numpy>=1.20,<2.0
55
numpydoc>=1.5.0
66
pandas>=2.0.0
77
psutil>=5.9.2

tests/cli/test_cli_config.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1113,13 +1113,13 @@ def test_command_skip_doc_params(test_class):
11131113
skip_doc_params={"input1"},
11141114
)
11151115

1116-
assert "input1" not in command_config.documentation.parameter_help
1116+
assert "input1" not in command_config.documentation.hpc_parameter_help
11171117
assert "input1" not in command_config.documentation.template_config
11181118

1119-
assert "_input2" not in command_config.documentation.parameter_help
1119+
assert "_input2" not in command_config.documentation.hpc_parameter_help
11201120
assert "_input2" not in command_config.documentation.template_config
11211121

1122-
assert "input3" in command_config.documentation.parameter_help
1122+
assert "input3" in command_config.documentation.hpc_parameter_help
11231123
assert "input3" in command_config.documentation.template_config
11241124

11251125

tests/cli/test_cli_documentation.py

+40-12
Original file line numberDiff line numberDiff line change
@@ -250,16 +250,16 @@ def test_command_documentation_default_exec_values_and_doc():
250250
"""Test `CommandDocumentation.default_exec_values` and docs."""
251251

252252
doc = CommandDocumentation(func_no_args)
253-
assert "nodes" not in doc.default_exec_values
254-
assert "max_workers" not in doc.default_exec_values
255-
assert "nodes" not in doc.exec_control_doc
256-
assert "max_workers" not in doc.exec_control_doc
253+
assert ":nodes:" not in doc.default_exec_values
254+
assert ":max_workers:" not in doc.default_exec_values
255+
assert ":nodes:" not in doc.exec_control_doc
256+
assert ":max_workers:" not in doc.exec_control_doc
257257

258258
doc = CommandDocumentation(func_no_args, is_split_spatially=True)
259259
assert doc.default_exec_values == DEFAULT_EXEC_VALUES
260-
assert "max_workers" not in doc.default_exec_values
261-
assert "nodes" in doc.exec_control_doc
262-
assert "max_workers" not in doc.exec_control_doc
260+
assert ":max_workers:" not in doc.default_exec_values
261+
assert ":nodes:" in doc.exec_control_doc
262+
assert ":max_workers:" not in doc.exec_control_doc
263263

264264

265265
def test_command_documentation_required_args():
@@ -347,6 +347,34 @@ def func(project_points):
347347
doc = CommandDocumentation(func, is_split_spatially=True)
348348
param_help = doc.parameter_help
349349

350+
section_dividers = [
351+
any(line) and all(c == "-" for c in line)
352+
for line in param_help.split("\n")
353+
]
354+
assert sum(section_dividers) == 1
355+
assert "Parameters" in param_help
356+
assert "project_points" in param_help
357+
assert "Path to project points file." in param_help
358+
assert "execution_control :" not in param_help
359+
assert "log_directory :" not in param_help
360+
assert "log_level :" not in param_help
361+
362+
363+
def test_command_documentation_hpc_parameter_help():
364+
"""Test `CommandDocumentation.hpc_parameter_help`."""
365+
366+
def func(project_points):
367+
"""Test func.
368+
369+
Parameters
370+
----------
371+
project_points : str
372+
Path to project points file.
373+
"""
374+
375+
doc = CommandDocumentation(func, is_split_spatially=True)
376+
param_help = doc.hpc_parameter_help
377+
350378
section_dividers = [
351379
any(line) and all(c == "-" for c in line)
352380
for line in param_help.split("\n")
@@ -397,7 +425,7 @@ def test_command_documentation_config_help(monkeypatch):
397425

398426
assert "my_command_name" in config_help
399427
assert (
400-
gaps.cli.documentation._cli_formatted(doc.parameter_help)
428+
gaps.cli.documentation._cli_formatted(doc.hpc_parameter_help)
401429
in config_help
402430
)
403431
assert ".. tabs::" in config_help
@@ -458,7 +486,7 @@ def _func2(another_param, d=42, e=None):
458486
}
459487
assert doc.template_config == expected_config
460488

461-
docstring = doc.parameter_help
489+
docstring = doc.hpc_parameter_help
462490
assert "Max num workers" in docstring
463491
assert "Path to project points." in docstring
464492
assert "More input" in docstring
@@ -481,7 +509,7 @@ def _func(another_param, d=42, e=None):
481509
)
482510
assert len(doc.signatures) == 1
483511

484-
docstring = doc.parameter_help
512+
docstring = doc.hpc_parameter_help
485513
assert "Max num workers" not in docstring
486514
assert "another_param :" not in docstring
487515
assert "d :" not in docstring
@@ -491,7 +519,7 @@ def _func(another_param, d=42, e=None):
491519

492520

493521
def test_command_documentation_for_class():
494-
"""Test `CommandDocumentation` with func missing docstring."""
522+
"""Test `CommandDocumentation` for a mix of classes and functions."""
495523

496524
class TestCommand:
497525
"""A test command as a class."""
@@ -556,7 +584,7 @@ def preprocessor(another_input, _a_private_input, another_input2=None):
556584
)
557585
assert len(doc.signatures) == 3
558586

559-
docstring = doc.parameter_help
587+
docstring = doc.hpc_parameter_help
560588
assert ":max_workers:" in docstring
561589
assert "\narg1 :" in docstring
562590
assert "\narg2 :" in docstring

tests/test_collection.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ def make_fake_h5_chunks(temp_dir, features, shuffle=False):
103103
"""
104104
data = np.random.uniform(0, 20, (50, 50, 48))
105105
lon, lat = np.meshgrid(np.linspace(-180, 0, 50), np.linspace(90, 0, 50))
106-
gids = np.arange(np.product(lat.shape))
106+
gids = np.arange(np.prod(lat.shape))
107107
if shuffle:
108108
np.random.shuffle(gids)
109109

0 commit comments

Comments
 (0)