Skip to content

Commit 356283e

Browse files
authored
change: format and add missing docstring placeholders (#945)
This commit will format all existing docstring to follow Google style: https://sphinxcontrib-napoleon.readthedocs.io/en/latest/example_google.html This commit will also add docstring placeholders to any class or method previously missing it. An ideal approach would be to take the time to include meaningful docstrings in every file. However, since that is not a task that will be prioritized, I've declared docstring bankruptcy on this package, in order to enforce docstring on all future code changes to this package.
1 parent 40f1f98 commit 356283e

Some content is hidden

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

76 files changed

+5262
-2626
lines changed

.pylintrc

-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ disable=
9292
cyclic-import, # TODO: Resolve cyclic imports
9393
no-self-use, # TODO: Convert methods to functions where appropriate
9494
too-many-branches, # TODO: Simplify or ignore as appropriate
95-
missing-docstring, # TODO: Fix missing docstring
9695

9796
[REPORTS]
9897
# Set the output format. Available formats are text, parseable, colorized, msvs

doc/conf.py

+5
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
1111
# ANY KIND, either express or implied. See the License for the specific
1212
# language governing permissions and limitations under the License.
13+
"""Placeholder docstring"""
1314
from __future__ import absolute_import
1415

1516
import os
@@ -22,6 +23,10 @@
2223
class Mock(MagicMock):
2324
@classmethod
2425
def __getattr__(cls, name):
26+
"""
27+
Args:
28+
name:
29+
"""
2530
if name == "__version__":
2631
return "1.4.0"
2732
else:

examples/cli/host/script.py

+15-11
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@
66

77

88
def model_fn(model_dir):
9-
"""
10-
Load the gluon model. Called once when hosting service starts.
9+
"""Load the gluon model. Called once when hosting service starts.
10+
11+
Args:
12+
model_dir: The directory where model files are stored.
1113
12-
:param: model_dir The directory where model files are stored.
13-
:return: a model (in this case a Gluon network)
14+
Returns:
15+
a model (in this case a Gluon network)
1416
"""
1517
symbol = mx.sym.load("%s/model.json" % model_dir)
1618
outputs = mx.symbol.softmax(data=symbol, name="softmax_label")
@@ -22,14 +24,16 @@ def model_fn(model_dir):
2224

2325

2426
def transform_fn(net, data, input_content_type, output_content_type):
25-
"""
26-
Transform a request using the Gluon model. Called once per request.
27+
"""Transform a request using the Gluon model. Called once per request.
28+
29+
Args:
30+
net: The Gluon model.
31+
data: The request payload.
32+
input_content_type: The request content type.
33+
output_content_type: The (desired) response content type.
2734
28-
:param net: The Gluon model.
29-
:param data: The request payload.
30-
:param input_content_type: The request content type.
31-
:param output_content_type: The (desired) response content type.
32-
:return: response payload and content type.
35+
Returns:
36+
response payload and content type.
3337
"""
3438
# we can use content types to vary input/output handling, but
3539
# here we just assume json for both

examples/cli/train/script.py

+32
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@
1212
def train(channel_input_dirs, hyperparameters, **kwargs):
1313
# SageMaker passes num_cpus, num_gpus and other args we can use to tailor training to
1414
# the current container environment, but here we just use simple cpu context.
15+
"""
16+
Args:
17+
channel_input_dirs:
18+
hyperparameters:
19+
**kwargs:
20+
"""
1521
ctx = mx.cpu()
1622

1723
# retrieve the hyperparameters we set in notebook (with some defaults)
@@ -80,6 +86,11 @@ def train(channel_input_dirs, hyperparameters, **kwargs):
8086

8187
def save(net, model_dir):
8288
# save the model
89+
"""
90+
Args:
91+
net:
92+
model_dir:
93+
"""
8394
y = net(mx.sym.var("data"))
8495
y.save("%s/model.json" % model_dir)
8596
net.collect_params().save("%s/model.params" % model_dir)
@@ -95,11 +106,21 @@ def define_network():
95106

96107

97108
def input_transformer(data, label):
109+
"""
110+
Args:
111+
data:
112+
label:
113+
"""
98114
data = data.reshape((-1,)).astype(np.float32) / 255
99115
return data, label
100116

101117

102118
def get_train_data(data_dir, batch_size):
119+
"""
120+
Args:
121+
data_dir:
122+
batch_size:
123+
"""
103124
return gluon.data.DataLoader(
104125
gluon.data.vision.MNIST(data_dir, train=True, transform=input_transformer),
105126
batch_size=batch_size,
@@ -109,6 +130,11 @@ def get_train_data(data_dir, batch_size):
109130

110131

111132
def get_val_data(data_dir, batch_size):
133+
"""
134+
Args:
135+
data_dir:
136+
batch_size:
137+
"""
112138
return gluon.data.DataLoader(
113139
gluon.data.vision.MNIST(data_dir, train=False, transform=input_transformer),
114140
batch_size=batch_size,
@@ -117,6 +143,12 @@ def get_val_data(data_dir, batch_size):
117143

118144

119145
def test(ctx, net, val_data):
146+
"""
147+
Args:
148+
ctx:
149+
net:
150+
val_data:
151+
"""
120152
metric = mx.metric.Accuracy()
121153
for data, label in val_data:
122154
data = data.as_in_context(ctx)

setup.py

+5
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
1111
# ANY KIND, either express or implied. See the License for the specific
1212
# language governing permissions and limitations under the License.
13+
"""Placeholder docstring"""
1314
from __future__ import absolute_import
1415

1516
import os
@@ -20,6 +21,10 @@
2021

2122

2223
def read(fname):
24+
"""
25+
Args:
26+
fname:
27+
"""
2328
return open(os.path.join(os.path.dirname(__file__), fname)).read()
2429

2530

src/sagemaker/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
1111
# ANY KIND, either express or implied. See the License for the specific
1212
# language governing permissions and limitations under the License.
13+
"""Placeholder docstring"""
1314
from __future__ import absolute_import
1415

1516
import pkg_resources

0 commit comments

Comments
 (0)