Skip to content

Commit d197b74

Browse files
authored
infra: add tools/ dir to pylint check (aws#1499)
1 parent 81ad62b commit d197b74

File tree

6 files changed

+25
-15
lines changed

6 files changed

+25
-15
lines changed

tools/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@
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+
"""Tools to assist with using the SageMake Python SDK."""
1314
from __future__ import absolute_import

tools/compatibility/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@
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+
"""Tools to assist with compatibility between SageMaker Python SDK versions."""
1314
from __future__ import absolute_import

tools/compatibility/v2/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@
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+
"""Tools to assist with upgrading to v2 of the SageMaker Python SDK."""
1314
from __future__ import absolute_import

tools/compatibility/v2/files.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def _write_output_file(self, output):
8080
os.makedirs(output_dir)
8181

8282
if os.path.exists(self.output_path):
83-
LOGGER.warning("Overwriting file {}".format(self.output_path))
83+
LOGGER.warning("Overwriting file %s", self.output_path)
8484

8585
with open(self.output_path, "w") as output_file:
8686
output_file.write(pasta.dump(output))

tools/compatibility/v2/modifiers/framework_version.py

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,13 @@
3232

3333

3434
class FrameworkVersionEnforcer(Modifier):
35+
"""A class to ensure that ``framework_version`` is defined when
36+
instantiating a framework estimator or model.
37+
"""
38+
3539
def node_should_be_modified(self, node):
36-
"""Check if the ast.Call node instantiates a framework estimator or model,
37-
but doesn't specify the framework_version parameter.
40+
"""Checks if the ast.Call node instantiates a framework estimator or model,
41+
but doesn't specify the ``framework_version`` parameter.
3842
3943
This looks for the following formats:
4044
@@ -57,34 +61,37 @@ def node_should_be_modified(self, node):
5761
return False
5862

5963
def _is_framework_constructor(self, node):
60-
"""Check if the ``ast.Call`` node represents a call of the form
64+
"""Checks if the ``ast.Call`` node represents a call of the form
6165
<Framework> or sagemaker.<framework>.<Framework>.
6266
"""
67+
# Check for <Framework> call
6368
if isinstance(node.func, ast.Name):
6469
if node.func.id in FRAMEWORK_CLASSES:
6570
return True
6671

67-
if (
68-
isinstance(node.func, ast.Attribute)
69-
and node.func.attr in FRAMEWORK_CLASSES
70-
and isinstance(node.func.value, ast.Attribute)
72+
# Check for sagemaker.<framework>.<Framework> call
73+
ends_with_framework_constructor = (
74+
isinstance(node.func, ast.Attribute) and node.func.attr in FRAMEWORK_CLASSES
75+
)
76+
77+
is_in_framework_module = (
78+
isinstance(node.func.value, ast.Attribute)
7179
and node.func.value.attr in FRAMEWORK_MODULES
7280
and isinstance(node.func.value.value, ast.Name)
7381
and node.func.value.value.id == "sagemaker"
74-
):
75-
return True
82+
)
7683

77-
return False
84+
return ends_with_framework_constructor and is_in_framework_module
7885

7986
def _fw_version_in_keywords(self, node):
80-
"""Check if the ``ast.Call`` node's keywords contain ``framework_version``."""
87+
"""Checks if the ``ast.Call`` node's keywords contain ``framework_version``."""
8188
for kw in node.keywords:
8289
if kw.arg == "framework_version" and kw.value:
8390
return True
8491
return False
8592

8693
def modify_node(self, node):
87-
"""Modify the ``ast.Call`` node's keywords to include ``framework_version``.
94+
"""Modifies the ``ast.Call`` node's keywords to include ``framework_version``.
8895
8996
The ``framework_version`` value is determined by the framework:
9097
@@ -103,7 +110,7 @@ def modify_node(self, node):
103110
)
104111

105112
def _framework_name_from_node(self, node):
106-
"""Retrieve the framework name based on the function call.
113+
"""Retrieves the framework name based on the function call.
107114
108115
Args:
109116
node (ast.Call): a node that represents the constructor of a framework class.

tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ skip_install = true
8282
deps =
8383
pylint==2.3.1
8484
commands =
85-
python -m pylint --rcfile=.pylintrc -j 0 src/sagemaker
85+
python -m pylint --rcfile=.pylintrc -j 0 src/sagemaker tools
8686

8787
[testenv:twine]
8888
basepython = python3

0 commit comments

Comments
 (0)