Skip to content

Commit 8852b92

Browse files
authored
[ci] [python-package] enforce 'numpydoc-validation' and 'pydoclint' checks (#7478)
1 parent 9474d04 commit 8852b92

12 files changed

Lines changed: 347 additions & 170 deletions

File tree

‎.ci/parameter-generator.py‎

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ def get_parameter_infos(config_hpp: Path) -> Tuple[List[Tuple[str, int]], List[L
2323
2424
Returns
2525
-------
26-
infos : tuple
26+
tuple
2727
Tuple with names and content of sections.
28-
"""
28+
""" # noqa: DOC105
2929
is_inparameter = False
3030
cur_key = None
3131
key_lvl = 0
@@ -96,9 +96,9 @@ def get_names(infos: List[List[Dict[str, List]]]) -> List[str]:
9696
9797
Returns
9898
-------
99-
names : list
99+
list
100100
Names of all parameters.
101-
"""
101+
""" # noqa: DOC105
102102
names = []
103103
for x in infos:
104104
for y in x:
@@ -116,9 +116,9 @@ def get_alias(infos: List[List[Dict[str, List]]]) -> List[Tuple[str, str]]:
116116
117117
Returns
118118
-------
119-
pairs : list
119+
list
120120
List of tuples (param alias, param name).
121-
"""
121+
""" # noqa: DOC105
122122
pairs = []
123123
for x in infos:
124124
for y in x:
@@ -142,9 +142,9 @@ def parse_check(check: str, reverse: bool = False) -> Tuple[str, str]:
142142
143143
Returns
144144
-------
145-
pair : tuple
145+
tuple
146146
Parsed constraint in the form of tuple (value, sign).
147-
"""
147+
""" # noqa: DOC105
148148
try:
149149
idx = 1
150150
float(check[idx:])
@@ -172,9 +172,9 @@ def set_one_var_from_string(name: str, param_type: str, checks: List[str]) -> st
172172
173173
Returns
174174
-------
175-
ret : str
175+
str
176176
Lines of auto config file with getting and checks of one parameter value.
177-
"""
177+
""" # noqa: DOC105
178178
ret = ""
179179
univar_mapper = {"int": "GetInt", "double": "GetDouble", "bool": "GetBool", "std::string": "GetString"}
180180
if "vector" not in param_type:
@@ -209,7 +209,7 @@ def gen_parameter_description(
209209
Structured descriptions of parameters.
210210
params_rst : pathlib.Path
211211
Path to the file with parameters documentation.
212-
"""
212+
""" # noqa: DOC105
213213
params_to_write = []
214214
lvl_mapper = {1: "-", 2: "~"}
215215
for (section_name, section_lvl), section_params in zip(sections, descriptions, strict=True):
@@ -274,9 +274,9 @@ def gen_parameter_code(
274274
275275
Returns
276276
-------
277-
infos : tuple
277+
tuple
278278
Tuple with names and content of sections.
279-
"""
279+
""" # noqa: DOC105
280280
keys, infos = get_parameter_infos(config_hpp)
281281
names = get_names(infos)
282282
alias = get_alias(infos)

‎.pre-commit-config.yaml‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22
exclude: |
33
(?x)^(
44
build|
5+
dist|
56
external_libs|
67
lightgbm-python|
78
lightgbm_r|
89
\.pixi|
10+
\.venv|
911
)$
1012
|R-package/configure$
1113
|R-package/inst/Makevars$
@@ -77,6 +79,16 @@ repos:
7779
- ./.ci/parameter-generator.py
7880
language: python
7981
pass_filenames: false
82+
- repo: https://github.com/numpy/numpydoc
83+
rev: v1.11.0
84+
hooks:
85+
- id: numpydoc-validation
86+
args: [--config=python-package]
87+
- repo: https://github.com/jsh9/pydoclint
88+
rev: 0.10.1
89+
hooks:
90+
- id: pydoclint
91+
args: [--config=python-package/pyproject.toml]
8092
- repo: https://github.com/rstcheck/rstcheck
8193
rev: v6.2.5
8294
hooks:

‎docs/conf.py‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ def generate_doxygen_xml(app: Sphinx) -> None:
239239
----------
240240
app : sphinx.application.Sphinx
241241
The application object representing the Sphinx process.
242-
"""
242+
""" # noqa: DOC105
243243
doxygen_args = [
244244
f"INPUT={CURR_PATH.parent / 'include' / 'LightGBM' / 'c_api.h'}",
245245
f"OUTPUT_DIRECTORY={CURR_PATH / 'doxyoutput'}",
@@ -283,7 +283,7 @@ def generate_r_docs(app: Sphinx) -> None:
283283
----------
284284
app : sphinx.application.Sphinx
285285
The application object representing the Sphinx process.
286-
"""
286+
""" # noqa: DOC105
287287
commands = f"""
288288
export TAR=/bin/tar
289289
cd {CURR_PATH.parent}
@@ -316,7 +316,7 @@ def replace_reference_to_r_docs(app: Sphinx) -> None:
316316
----------
317317
app : sphinx.application.Sphinx
318318
The application object representing the Sphinx process.
319-
"""
319+
""" # noqa: DOC105
320320
index_doc_path = CURR_PATH / "index.rst"
321321
with open(index_doc_path, "r+t", encoding="utf-8") as index_doc:
322322
content = index_doc.read()
@@ -332,7 +332,7 @@ def setup(app: Sphinx) -> None:
332332
----------
333333
app : sphinx.application.Sphinx
334334
The application object representing the Sphinx process.
335-
"""
335+
""" # noqa: DOC105
336336
first_run = not (CURR_PATH / "_FIRST_RUN.flag").exists()
337337
if first_run and RTD:
338338
(CURR_PATH / "_FIRST_RUN.flag").touch()

0 commit comments

Comments
 (0)