Skip to content

Commit

Permalink
chore: Revert 'Make pylintrc ignore rule more readable' aws#2375 (aws…
Browse files Browse the repository at this point in the history
…#2400)

* Revert "chore: Enable pylint compare to zero/empty string"

This reverts commit 1e3b282.

* Revert "chore: Enable pylint Else If Used checker"

This reverts commit 5819ded.

* Revert "chore: Remove unnecessary pylint disable"

This reverts commit d4a5c46.

* Revert "chore: Enable pylint line too long"

This reverts commit fb54504.

* Revert "chore: Enable pylint multi-processes"

This reverts commit b02c8d9.

* Revert "chore: Enable pylint rule Unused import"

This reverts commit a6eda1d.

* Revert "chore: Remove pylint rules that do not apply for python 3"

This reverts commit 6212005.

* Revert "chore: Make pylintrc ignore rule more readable"

This reverts commit fe50385.
  • Loading branch information
aahung authored Nov 23, 2020
1 parent ecefc76 commit ff150ed
Show file tree
Hide file tree
Showing 34 changed files with 152 additions and 212 deletions.
17 changes: 2 additions & 15 deletions .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,9 @@ persistent=yes
# List of plugins (as comma separated values of python modules names) to load,
# usually to register additional checkers.
load-plugins=
pylint.extensions.check_elif, # Else If Used checker
pylint.extensions.emptystring, # compare to empty string
pylint.extensions.comparetozero, # compare to 0

# Use multiple processes to speed up Pylint.
jobs=4
jobs=1

# Allow loading of arbitrary C extensions. Extensions are imported into the
# active Python interpreter and may run arbitrary code.
Expand Down Expand Up @@ -62,17 +59,7 @@ confidence=
# --enable=similarities". If you want to run only the classes checker, but have
# no Warning level messages displayed, use"--disable=all --enable=classes
# --disable=W"
disable=
R0201, # Method could be a function
W0613, # Unused argument %r
W0640, # Cell variable %s defined in loop A variable used in a closure is defined in a loop
R0902, # Too many instance attributes (%s/%s)
R0903, # Too few public methods (%s/%s)
R0913, # Too many arguments (%s/%s)
W0703, # Catching too general exception %s
R0904, # Too many public methods (%s/%s)
R0914, # Too many local variables (%s/%s)
C0415 # Import outside toplevel (%s) Used when an import statement is used anywhere other than the module toplevel. Move this import to the top of the file.
disable=R0201,W0613,W0640,I0021,I0020,W1618,W1619,R0902,R0903,W0231,W0611,R0913,W0703,C0330,R0204,I0011,R0904,R0914,C0301,C0415


[REPORTS]
Expand Down
7 changes: 3 additions & 4 deletions samcli/cli/cli_config_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
CLI configuration decorator to use TOML configuration files for click commands.
"""

# This section contains code copied and modified from
# [click_config_file][https://github.com/phha/click_config_file/blob/master/click_config_file.py]
# SPDX-License-Identifier: MIT
## This section contains code copied and modified from [click_config_file][https://github.com/phha/click_config_file/blob/master/click_config_file.py]
## SPDX-License-Identifier: MIT

import os
import functools
Expand Down Expand Up @@ -264,4 +263,4 @@ def decorator_customize_config_env(f):
return click.option(*config_env_param_decls, **config_env_attrs)(f)


# End section copied from [click_config_file][https://github.com/phha/click_config_file/blob/master/click_config_file.py
# End section copied from [[click_config_file][https://github.com/phha/click_config_file/blob/master/click_config_file.py]
3 changes: 1 addition & 2 deletions samcli/cli/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,7 @@ def convert(self, value, param, ctx):
value = (value,) if not isinstance(value, tuple) else value

for val in value:
# Using standard parser first.
# We should implement other type parser like JSON and Key=key,Value=val type format.
# Using standard parser first. We should implement other type parser like JSON and Key=key,Value=val type format.
parsed, tags = self._standard_key_value_parser(val)
if not parsed:
parsed, tags = self._space_separated_key_value_parser(val)
Expand Down
4 changes: 2 additions & 2 deletions samcli/commands/_utils/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ def get_or_default_template_file_name(ctx, param, provided_value, include_build)
if ctx and ctx.default_map.get("template", None):
provided_value = ctx.default_map.get("template")
else:
# Default value was used. Value can either be template.yaml or template.yml.
# Decide based on which file exists .yml is the default, even if it does not exist.
# Default value was used. Value can either be template.yaml or template.yml. Decide based on which file exists
# .yml is the default, even if it does not exist.
provided_value = "template.yml"

for option in search_paths:
Expand Down
40 changes: 17 additions & 23 deletions samcli/commands/build/build_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,20 @@ class BuildContext:
_BUILD_DIR_PERMISSIONS = 0o755

def __init__(
self,
resource_identifier,
template_file,
base_dir,
build_dir,
cache_dir,
cached,
mode,
manifest_path=None,
clean=False,
use_container=False,
parameter_overrides=None,
docker_network=None,
skip_pull_image=False,
self,
resource_identifier,
template_file,
base_dir,
build_dir,
cache_dir,
cached,
mode,
manifest_path=None,
clean=False,
use_container=False,
parameter_overrides=None,
docker_network=None,
skip_pull_image=False,
):

self._resource_identifier = resource_identifier
Expand Down Expand Up @@ -92,12 +92,7 @@ def _setup_build_dir(build_dir, clean):
build_path = pathlib.Path(build_dir)

if os.path.abspath(str(build_path)) == os.path.abspath(str(pathlib.Path.cwd())):
exception_message = (
"Failing build: Running a build with build-dir as current working directory "
"is extremely dangerous since the build-dir contents is first removed. "
"This is no longer supported, please remove the '--build-dir' option from the command "
"to allow the build artifacts to be placed in the directory your template is in."
)
exception_message = "Failing build: Running a build with build-dir as current working directory is extremely dangerous since the build-dir contents is first removed. This is no longer supported, please remove the '--build-dir' option from the command to allow the build artifacts to be placed in the directory your template is in."
raise InvalidBuildDirException(exception_message)

if build_path.exists() and os.listdir(build_dir) and clean:
Expand Down Expand Up @@ -182,9 +177,8 @@ def resources_to_build(self):
all_resources = [f.name for f in self._function_provider.get_all()]
all_resources.extend([l.name for l in self._layer_provider.get_all()])

available_resource_message = (
f"{self._resource_identifier} not found. Possible options in your " f"template: {all_resources}"
)
available_resource_message = f"{self._resource_identifier} not found. Possible options in your " \
f"template: {all_resources}"
LOG.info(available_resource_message)
raise ResourceNotFound(f"Unable to find a function or layer with name '{self._resource_identifier}'")
return result
Expand Down
21 changes: 10 additions & 11 deletions samcli/commands/build/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,15 @@
"-b",
default=DEFAULT_BUILD_DIR,
type=click.Path(file_okay=False, dir_okay=True, writable=True), # Must be a directory
help="Path to a folder where the built artifacts will be stored. "
"This directory will be first removed before starting a build.",
help="Path to a folder where the built artifacts will be stored. This directory will be first removed before starting a build.",
)
@click.option(
"--cache-dir",
"-cd",
default=DEFAULT_CACHE_DIR,
type=click.Path(file_okay=False, dir_okay=True, writable=True), # Must be a directory
help="The folder where the cache artifacts will be stored when --cached is specified. "
"The default cache directory is .aws-sam/cache",
"The default cache directory is .aws-sam/cache",
)
@click.option(
"--base-dir",
Expand All @@ -103,7 +102,7 @@
"-p",
is_flag=True,
help="Enabled parallel builds. Use this flag to build your AWS SAM template's functions and layers in parallel. "
"By default the functions and layers are built in sequence",
"By default the functions and layers are built in sequence",
)
@click.option(
"--manifest",
Expand All @@ -117,12 +116,12 @@
"-c",
is_flag=True,
help="Enable cached builds. Use this flag to reuse build artifacts that have not changed from previous builds. "
"AWS SAM evaluates whether you have made any changes to files in your project directory. \n\n"
"Note: AWS SAM does not evaluate whether changes have been made to third party modules "
"that your project depends on, where you have not provided a specific version. "
"For example, if your Python function includes a requirements.txt file with the following entry "
"requests=1.x and the latest request module version changes from 1.1 to 1.2, "
"SAM will not pull the latest version until you run a non-cached build.",
"AWS SAM evaluates whether you have made any changes to files in your project directory. \n\n"
"Note: AWS SAM does not evaluate whether changes have been made to third party modules "
"that your project depends on, where you have not provided a specific version. "
"For example, if your Python function includes a requirements.txt file with the following entry "
"requests=1.x and the latest request module version changes from 1.1 to 1.2, "
"SAM will not pull the latest version until you run a non-cached build.",
)
@template_option_without_build
@parameter_override_option
Expand Down Expand Up @@ -237,7 +236,7 @@ def do_cli( # pylint: disable=too-many-locals, too-many-statements
manifest_path_override=ctx.manifest_path_override,
container_manager=ctx.container_manager,
mode=ctx.mode,
parallel=parallel,
parallel=parallel
)
except FunctionNotFound as ex:
raise UserException(str(ex), wrapped_from=ex.__class__.__name__) from ex
Expand Down
7 changes: 3 additions & 4 deletions samcli/commands/init/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,7 @@
@click.option("-n", "--name", help="Name of your project to be generated as a folder")
@click.option(
"--app-template",
help="Identifier of the managed application template you want to use. "
"If not sure, call 'sam init' without options for an interactive workflow.",
help="Identifier of the managed application template you want to use. If not sure, call 'sam init' without options for an interactive workflow.",
)
@click.option(
"--no-input",
Expand Down Expand Up @@ -195,8 +194,8 @@ def _deprecate_notification(runtime):
deprecated_runtimes = {"dotnetcore1.0", "dotnetcore2.0"}
if runtime in deprecated_runtimes:
message = (
f"WARNING: {runtime} is no longer supported by AWS Lambda, please update to a newer supported runtime. "
f"SAM CLI will drop support for all deprecated runtimes {deprecated_runtimes} on May 1st. "
f"WARNING: {runtime} is no longer supported by AWS Lambda, please update to a newer supported runtime. SAM CLI "
f"will drop support for all deprecated runtimes {deprecated_runtimes} on May 1st. "
f"See issue: https://github.com/awslabs/aws-sam-cli/issues/1934 for more details."
)
LOG.warning(Colored().yellow(message))
Expand Down
11 changes: 4 additions & 7 deletions samcli/commands/init/init_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def _check_app_template(self, entry, app_template):
return entry["appTemplate"] == app_template

def init_options(self, runtime, dependency_manager):
if self.clone_attempted is False: # pylint: disable=compare-to-zero
if self.clone_attempted is False:
self._clone_repo()
if self.repo_path is None:
return self._init_options_from_bundle(runtime, dependency_manager)
Expand Down Expand Up @@ -169,12 +169,9 @@ def _replace_app_templates(self, temp_path, dest_path):
LOG.debug("Copying templates from %s to %s", str(temp_path), str(dest_path))
shutil.copytree(temp_path, dest_path, ignore=shutil.ignore_patterns("*.git"))
except (OSError, shutil.Error) as ex:
# UNSTABLE STATE
# it's difficult to see how this scenario could happen except weird permissions, user will need to debug
# UNSTABLE STATE - it's difficult to see how this scenario could happen except weird permissions, user will need to debug
raise AppTemplateUpdateException(
"Unstable state when updating app templates. "
"Check that you have permissions to create/delete files in the AWS SAM shared directory "
"or file an issue at https://github.com/awslabs/aws-sam-cli/issues"
"Unstable state when updating app templates. Check that you have permissions to create/delete files in the AWS SAM shared directory or file an issue at https://github.com/awslabs/aws-sam-cli/issues"
) from ex

def _clone_new_app_templates(self, shared_dir, expected_path):
Expand Down Expand Up @@ -216,7 +213,7 @@ def _git_executable(self):
def is_dynamic_schemas_template(self, app_template, runtime, dependency_manager):
"""
Check if provided template is dynamic template e.g: AWS Schemas template.
Currently dynamic templates require different handling e.g: for schema download and merge schema code in sam-app
Currently dynamic templates require different handling e.g: for schema download and merge schema code in sam-app.
:param app_template:
:param runtime:
:param dependency_manager:
Expand Down
3 changes: 1 addition & 2 deletions samcli/commands/init/interactive_event_bridge_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,7 @@ def _fetch_available_registries(schemas_api_caller, registry_pages, next_token):


def _construct_cli_page(items, item_per_page):
"""Responsible for splitting items into CLI pages.
Currently CLI pages are list of dictionary [0:{0:s1, 1:s2: 3:s3}, 1: {4:s4, 5:s5: 6:s6}]
"""Responsible for splitting items into CLI pages. Currently CLI pages are list of dictionary [0:{0:s1, 1:s2: 3:s3}, 1: {4:s4, 5:s5: 6:s6}]
We maintain the page detail and item index details."""
pages = [
items[i * item_per_page : (i + 1) * item_per_page]
Expand Down
3 changes: 2 additions & 1 deletion samcli/commands/local/generate_event/event_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
import click

import samcli.lib.generated_sample_events.events as events
from samcli.cli.cli_config_file import TomlProvider, configuration_option
from samcli.cli.cli_config_file import TomlProvider, get_ctx_defaults, configuration_option
from samcli.cli.options import debug_option
from samcli.lib.telemetry.metrics import track_command
import samcli.lib.config.samconfig as samconfig


class ServiceCommand(click.MultiCommand):
Expand Down
3 changes: 1 addition & 2 deletions samcli/commands/local/lib/local_lambda.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,7 @@ def invoke(self, function_name, event, stdout=None, stderr=None):
# pylint: disable=no-member
if hasattr(os_error, "winerror") and os_error.winerror == 1314:
raise NoPrivilegeException(
"Administrator, Windows Developer Mode, "
"or SeCreateSymbolicLinkPrivilege is required to create symbolic link for files: {}, {}".format(
"Administrator, Windows Developer Mode, or SeCreateSymbolicLinkPrivilege is required to create symbolic link for files: {}, {}".format(
os_error.filename, os_error.filename2
)
) from os_error
Expand Down
9 changes: 3 additions & 6 deletions samcli/commands/local/lib/swagger/integration_uri.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ class LambdaUri:
_FN_SUB = "Fn::Sub"

# From an ARN like below, extract just the Lambda Function ARN
# arn:aws:apigateway:us-west-2:lambda:path/2015-03-31/functions/arn:aws:lambda:us-west-2:123456789012:\
# function:Calculator:ProdAlias/invocations # NOQA
# arn:aws:apigateway:us-west-2:lambda:path/2015-03-31/functions/arn:aws:lambda:us-west-2:123456789012:function:Calculator:ProdAlias/invocations # NOQA
_REGEX_GET_FUNCTION_ARN = r".*/functions/(.*)/invocations"

# From Lamdba Function ARN like below, extract the function name. Note, the [^:] syntax is to capture only function
Expand Down Expand Up @@ -72,8 +71,7 @@ def _get_function_arn(uri_data):
- String:
- Fully resolved ARN
- ARN with Stage Variables:
Ex: arn:aws:apigateway:ap-southeast-2:lambda:path/2015-03-31/functions/arn:aws:lambda:ap-southeast-2:\
123456789012:function:${stageVariables.PostFunctionName}/invocations # NOQA
Ex: arn:aws:apigateway:ap-southeast-2:lambda:path/2015-03-31/functions/arn:aws:lambda:ap-southeast-2:123456789012:function:${stageVariables.PostFunctionName}/invocations # NOQA
- Dictionary: Usually contains intrinsic functions
Expand Down Expand Up @@ -199,8 +197,7 @@ def _resolve_fn_sub(uri_data):
"arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${LambdaFunction.Arn}/invocations"
}
Output: "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/arn:aws:lambda:us-east-1:\
LambdaFunction/invocations" # NOQA
Output: "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/arn:aws:lambda:us-east-1:LambdaFunction/invocations" # NOQA
Note
~~~~
Expand Down
1 change: 1 addition & 0 deletions samcli/commands/package/package_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import boto3
import click
from botocore.config import Config

from samcli.commands.package.exceptions import PackageFailedError
from samcli.lib.package.artifact_exporter import Template
Expand Down
5 changes: 2 additions & 3 deletions samcli/commands/publish/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@

LOG = logging.getLogger(__name__)

SAM_DOC_PREFIX = "https://docs.aws.amazon.com/serverless-application-model/latest/developerguide"
SAM_PUBLISH_DOC = f"{SAM_DOC_PREFIX}/serverless-sam-template-publishing-applications.html" # noqa
SAM_PACKAGE_DOC = f"{SAM_DOC_PREFIX}/sam-cli-command-reference-sam-package.html" # noqa
SAM_PUBLISH_DOC = "https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-template-publishing-applications.html" # noqa
SAM_PACKAGE_DOC = "https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-cli-command-reference-sam-package.html" # noqa
HELP_TEXT = """
Use this command to publish a packaged AWS SAM template to
the AWS Serverless Application Repository to share within your team,
Expand Down
7 changes: 2 additions & 5 deletions samcli/lib/bootstrap/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,11 @@ def manage_stack(profile, region):
cloudformation_client = boto3.client("cloudformation", config=Config(region_name=region if region else None))
except NoCredentialsError as ex:
raise CredentialsError(
"Error Setting Up Managed Stack Client: Unable to resolve credentials for the AWS SDK for Python client. "
"Please see their documentation for options to pass in credentials: "
"https://boto3.amazonaws.com/v1/documentation/api/latest/guide/configuration.html"
"Error Setting Up Managed Stack Client: Unable to resolve credentials for the AWS SDK for Python client. Please see their documentation for options to pass in credentials: https://boto3.amazonaws.com/v1/documentation/api/latest/guide/configuration.html"
) from ex
except NoRegionError as ex:
raise RegionError(
"Error Setting Up Managed Stack Client: Unable to resolve a region. "
"Please provide a region via the --region parameter or by the AWS_REGION environment variable."
"Error Setting Up Managed Stack Client: Unable to resolve a region. Please provide a region via the --region parameter or by the AWS_REGION environment variable."
) from ex
return _create_or_get_stack(cloudformation_client)

Expand Down
Loading

0 comments on commit ff150ed

Please sign in to comment.