Skip to content

Commit 94dcae7

Browse files
authored
Format docs directory with black (NVIDIA#5214)
This PR applies Black to the docs/ directory and enables linter on this path. The `examples/use_cases` subdirectory is excluded - it contains a lot of 3rd party code that was forked by DALI and has numerous linter issues. Linting and formatting that part should be done as a separate step (if at all). NVIDIA#5226 enabled black to be used within jupyter files on our CI. Notable changes: 1. The index file generation for operator references gets a header with imports and a license. This solves a lot of `F821 undefined name XXXX`. 2. Some too-long strings and too-long comments are broken into additional lines 3. Several one-letter variables are replaced with more meaningful ones 4. noqa is added around mxnet imports that appear to be no-op, but it looks like the importing has side effects (for example path adjustment to look up the library). 5. Some fixes in the conf.py Signed-off-by: Krzysztof Lecki <[email protected]>
1 parent 39b9be1 commit 94dcae7

File tree

109 files changed

+6491
-4332
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

109 files changed

+6491
-4332
lines changed

.flake8

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ extend-ignore = E203,W503
1010
# W504 - Line break occurred after a binary operator
1111
extend-select = W504
1212
# Filter out the AutoGraph from regular linter - it has a separate .flake8.ag config.
13-
exclude = *nvidia/dali/_autograph/*,*test/python/autograph/*
13+
# Filter out use_cases directory, with forked 3rd party examples that include DALI modifications
14+
exclude = *nvidia/dali/_autograph/*,*test/python/autograph/*,*docs/examples/use_cases/*

cmake/lint.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ add_custom_target(lint-cpp
2121

2222
set(PYTHON_LINT_PATHS
2323
${PROJECT_SOURCE_DIR}/dali
24+
${PROJECT_SOURCE_DIR}/docs
2425
${PROJECT_SOURCE_DIR}/tools
2526
${PROJECT_SOURCE_DIR}/dali_tf_plugin
2627
${PROJECT_SOURCE_DIR}/qa

docs/autodoc_submodules.py

Lines changed: 40 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,50 @@
1-
from nvidia.dali import backend as b
2-
import nvidia.dali.ops as ops
1+
# Copyright (c) 2020-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
315
import nvidia.dali.plugin.pytorch
416
import nvidia.dali.plugin.numba
517
import inspect
618
import sys
7-
from pathlib import Path
819

920
import operations_table
1021

1122
# Dictionary with modules that can have registered Ops
1223
ops_modules = {
13-
'nvidia.dali.ops': nvidia.dali.ops,
14-
'nvidia.dali.plugin.numba.experimental': nvidia.dali.plugin.numba.experimental,
24+
"nvidia.dali.ops": nvidia.dali.ops,
25+
"nvidia.dali.plugin.numba.experimental": nvidia.dali.plugin.numba.experimental,
1526
}
1627

1728

18-
exclude_ops_members = {
19-
'nvidia.dali.ops': ["PythonFunctionBase"]
20-
}
29+
exclude_ops_members = {"nvidia.dali.ops": ["PythonFunctionBase"]}
2130

2231

2332
fn_modules = {
24-
'nvidia.dali.fn': nvidia.dali.fn,
25-
'nvidia.dali.plugin.pytorch.fn': nvidia.dali.plugin.pytorch.fn,
26-
'nvidia.dali.plugin.numba.fn.experimental': nvidia.dali.plugin.numba.fn.experimental,
33+
"nvidia.dali.fn": nvidia.dali.fn,
34+
"nvidia.dali.plugin.pytorch.fn": nvidia.dali.plugin.pytorch.fn,
35+
"nvidia.dali.plugin.numba.fn.experimental": nvidia.dali.plugin.numba.fn.experimental,
2736
}
2837

2938

30-
exclude_fn_members = {
31-
}
39+
exclude_fn_members = {}
3240

3341

3442
mod_aditional_doc = {
35-
'nvidia.dali.fn.transforms' : "All operators in this module support only CPU device as they are meant " +
36-
"to be provided as an input to named keyword operator arguments. Check for more details the relevant " +
37-
":ref:`pipeline documentation section<Processing Graph Structure>`."
43+
"nvidia.dali.fn.transforms": (
44+
"All operators in this module support only CPU device as they are meant to be provided"
45+
" as an input to named keyword operator arguments. Check for more details the relevant"
46+
" :ref:`pipeline documentation section<Processing Graph Structure>`."
47+
)
3848
}
3949

4050

@@ -47,8 +57,11 @@ def get_modules(top_modules):
4757
modules = []
4858
for module in sys.modules.keys():
4959
for doc_module in top_modules:
50-
if (module.startswith(doc_module) and not module.endswith('hidden')
51-
and not _is_private(module)):
60+
if (
61+
module.startswith(doc_module)
62+
and not module.endswith("hidden")
63+
and not _is_private(module)
64+
):
5265
modules += [module]
5366
return sorted(modules)
5467

@@ -66,6 +79,7 @@ def get_functions(module):
6679
result.append(member_name)
6780
return result
6881

82+
6983
def get_schema_names(module, functions):
7084
return [getattr(sys.modules[module], fun)._schema_name for fun in functions]
7185

@@ -85,7 +99,7 @@ def op_autodoc(out_filename):
8599
excluded = exclude_ops_members[module]
86100
s += " :exclude-members: {}\n".format(", ".join(excluded))
87101
s += "\n\n"
88-
with open(out_filename, 'w') as f:
102+
with open(out_filename, "w") as f:
89103
f.write(s)
90104

91105

@@ -99,18 +113,18 @@ def get_references(name, references):
99113
result += f" * `{desc} <../{url}>`_\n"
100114
return result
101115

116+
102117
def single_fun_file(full_name, references):
103-
"""Generate stub page for documentation of given function from fn api.
104-
"""
118+
"""Generate stub page for documentation of given function from fn api."""
105119
result = f"{full_name}\n"
106120
result += "-" * len(full_name) + "\n\n"
107121
result += f".. autofunction:: {full_name}\n\n"
108122
result += get_references(full_name, references)
109123
return result
110124

125+
111126
def single_module_file(module, funs_in_module, references):
112-
"""Generate stub page for documentation of given module
113-
"""
127+
"""Generate stub page for documentation of given module"""
114128
result = f"{module}\n"
115129
result += "~" * len(module) + "\n\n"
116130

@@ -123,7 +137,6 @@ def single_module_file(module, funs_in_module, references):
123137
result += operations_table.operations_table_str(get_schema_names(module, funs_in_module))
124138
result += "\n\n"
125139

126-
127140
result += ".. toctree::\n :hidden:\n\n"
128141

129142
for fun in funs_in_module:
@@ -133,6 +146,7 @@ def single_module_file(module, funs_in_module, references):
133146
result += f" {full_name}\n"
134147
return result
135148

149+
136150
def fn_autodoc(out_filename, generated_path, references):
137151
all_modules_str = ".. toctree::\n :hidden:\n\n"
138152
all_modules = get_modules(fn_modules)
@@ -149,7 +163,7 @@ def fn_autodoc(out_filename, generated_path, references):
149163
all_modules_str += f" {generated_path / module}\n"
150164

151165
single_module_str = single_module_file(module, funs_in_module, references)
152-
with open(generated_path / (module + ".rst"), 'w') as module_file:
166+
with open(generated_path / (module + ".rst"), "w") as module_file:
153167
module_file.write(single_module_str)
154168

155169
for fun in funs_in_module:
@@ -160,5 +174,5 @@ def fn_autodoc(out_filename, generated_path, references):
160174
single_file_str = single_fun_file(full_name, references)
161175
function_file.write(single_file_str)
162176

163-
with open(out_filename, 'w') as f:
177+
with open(out_filename, "w") as f:
164178
f.write(all_modules_str)

0 commit comments

Comments
 (0)