Skip to content

infra: add tools/ dir to pylint check #1499

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions tools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
# ANY KIND, either express or implied. See the License for the specific
# language governing permissions and limitations under the License.
"""Tools to assist with using the SageMake Python SDK."""
from __future__ import absolute_import
1 change: 1 addition & 0 deletions tools/compatibility/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
# ANY KIND, either express or implied. See the License for the specific
# language governing permissions and limitations under the License.
"""Tools to assist with compatibility between SageMaker Python SDK versions."""
from __future__ import absolute_import
1 change: 1 addition & 0 deletions tools/compatibility/v2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
# ANY KIND, either express or implied. See the License for the specific
# language governing permissions and limitations under the License.
"""Tools to assist with upgrading to v2 of the SageMaker Python SDK."""
from __future__ import absolute_import
2 changes: 1 addition & 1 deletion tools/compatibility/v2/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def _write_output_file(self, output):
os.makedirs(output_dir)

if os.path.exists(self.output_path):
LOGGER.warning("Overwriting file {}".format(self.output_path))
LOGGER.warning("Overwriting file %s", self.output_path)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this flagged by pylint?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep 😂

************* Module tools.compatibility.v2.files
tools/compatibility/v2/files.py:83:27: W1202: Use % formatting in logging functions and pass the % parameters as arguments (logging-format-interpolation)


with open(self.output_path, "w") as output_file:
output_file.write(pasta.dump(output))
33 changes: 20 additions & 13 deletions tools/compatibility/v2/modifiers/framework_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,13 @@


class FrameworkVersionEnforcer(Modifier):
"""A class to ensure that ``framework_version`` is defined when
instantiating a framework estimator or model.
"""

def node_should_be_modified(self, node):
"""Check if the ast.Call node instantiates a framework estimator or model,
but doesn't specify the framework_version parameter.
"""Checks if the ast.Call node instantiates a framework estimator or model,
but doesn't specify the ``framework_version`` parameter.

This looks for the following formats:

Expand All @@ -57,34 +61,37 @@ def node_should_be_modified(self, node):
return False

def _is_framework_constructor(self, node):
"""Check if the ``ast.Call`` node represents a call of the form
"""Checks if the ``ast.Call`` node represents a call of the form
<Framework> or sagemaker.<framework>.<Framework>.
"""
# Check for <Framework> call
if isinstance(node.func, ast.Name):
if node.func.id in FRAMEWORK_CLASSES:
return True

if (
isinstance(node.func, ast.Attribute)
and node.func.attr in FRAMEWORK_CLASSES
and isinstance(node.func.value, ast.Attribute)
# Check for sagemaker.<framework>.<Framework> call
ends_with_framework_constructor = (
isinstance(node.func, ast.Attribute) and node.func.attr in FRAMEWORK_CLASSES
)

is_in_framework_module = (
isinstance(node.func.value, ast.Attribute)
and node.func.value.attr in FRAMEWORK_MODULES
and isinstance(node.func.value.value, ast.Name)
and node.func.value.value.id == "sagemaker"
):
return True
)

return False
return ends_with_framework_constructor and is_in_framework_module

def _fw_version_in_keywords(self, node):
"""Check if the ``ast.Call`` node's keywords contain ``framework_version``."""
"""Checks if the ``ast.Call`` node's keywords contain ``framework_version``."""
for kw in node.keywords:
if kw.arg == "framework_version" and kw.value:
return True
return False

def modify_node(self, node):
"""Modify the ``ast.Call`` node's keywords to include ``framework_version``.
"""Modifies the ``ast.Call`` node's keywords to include ``framework_version``.

The ``framework_version`` value is determined by the framework:

Expand All @@ -103,7 +110,7 @@ def modify_node(self, node):
)

def _framework_name_from_node(self, node):
"""Retrieve the framework name based on the function call.
"""Retrieves the framework name based on the function call.

Args:
node (ast.Call): a node that represents the constructor of a framework class.
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ skip_install = true
deps =
pylint==2.3.1
commands =
python -m pylint --rcfile=.pylintrc -j 0 src/sagemaker
python -m pylint --rcfile=.pylintrc -j 0 src/sagemaker tools

[testenv:twine]
basepython = python3
Expand Down