Skip to content

Commit

Permalink
chore: Bump pylint version (aws#3825)
Browse files Browse the repository at this point in the history
* Bump pylint version

* Update pylint version requirment

* Disable pylint rule C0209

* Disable pylint rules W1514, R1734, R1735

* Fix pylint violations

* Fix pylint rule R1732 violations
  • Loading branch information
hawflau authored Apr 22, 2022
1 parent 963f98f commit d1db668
Show file tree
Hide file tree
Showing 15 changed files with 57 additions and 38 deletions.
6 changes: 5 additions & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,11 @@ disable=
C0103, # Class constant name "%s" doesn't conform to UPPER_CASE naming style ('([^\\W\\da-z][^\\Wa-z]*|__.*__)$' pattern) (invalid-name)
# New recommendations, disable for now to avoid introducing behaviour changes.
R1729, # Use a generator instead '%s' (use-a-generator)
R1732, # Consider using 'with' for resource-allocating operations (consider-using-with)
C0209, # Formatting a regular string which could be a f-string (consider-using-f-string)
W1514, # Using open without explicitly specifying an encoding (unspecified-encoding)
R1734, # Consider using [] instead of list() (use-list-literal)
R1735, # Consider using {} instead of dict() (use-dict-literal)

# This applies to CPython only.
I1101, # Module 'math' has no 'pow' member, but source is unavailable. Consider adding this module to extension-pkg-allow-list if you want to perform analysis based on run-time introspection of living objects. (c-extension-no-member)

Expand Down
2 changes: 1 addition & 1 deletion requirements/pre-dev.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
pylint~=2.9.0
pylint>=2.13.0,<3
5 changes: 3 additions & 2 deletions samcli/cli/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,10 @@ def get_cmd_names(cmd_name, ctx) -> List[str]:
Parameters
----------
cmd_name : name of current command
cmd_name : str
name of current command
ctx : click.Context
click context
Returns
-------
Expand Down
2 changes: 1 addition & 1 deletion samcli/cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def print_cmdline_args(func):
Parameters
----------
func: function reference
func: Callable
Actual function (command) which will be executed
Returns
Expand Down
2 changes: 1 addition & 1 deletion samcli/commands/_utils/option_value_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def process_image_options(image_args: Optional[Tuple[str]]) -> Dict:
Function as key and the corresponding image URI as value.
Global default image URI is contained in the None key.
"""
images: Dict[Optional[str], str] = dict()
images: Dict[Optional[str], str] = {}
if image_args:
for image_string in image_args:
function_name, image_uri = _parse_key_value_pair(image_string)
Expand Down
7 changes: 3 additions & 4 deletions samcli/commands/init/interactive_init_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -533,10 +533,9 @@ def _get_schema_template_details(schemas_api_caller):
def _package_schemas_code(runtime, schemas_api_caller, schema_template_details, output_dir, name, location):
try:
click.echo("Trying to get package schema code")
download_location = tempfile.NamedTemporaryFile(delete=False)
do_download_source_code_binding(runtime, schema_template_details, schemas_api_caller, download_location)
do_extract_and_merge_schemas_code(download_location, output_dir, name, location)
download_location.close()
with tempfile.NamedTemporaryFile(delete=False) as download_location:
do_download_source_code_binding(runtime, schema_template_details, schemas_api_caller, download_location)
do_extract_and_merge_schemas_code(download_location, output_dir, name, location)
except (ClientError, WaiterError) as e:
raise SchemasApiException(
"Exception occurs while packaging Schemas code. %s" % e.response["Error"]["Message"]
Expand Down
4 changes: 2 additions & 2 deletions samcli/lib/build/build_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ def _write_source_hash(
"""
document = {}
if not self._filepath.exists():
open(self._filepath, "a+").close()
open(self._filepath, "a+").close() # pylint: disable=consider-using-with

txt = self._filepath.read_text()
# .loads() returns a TOMLDocument,
Expand Down Expand Up @@ -462,7 +462,7 @@ def _write(self) -> None:
document.add(BuildGraph.LAYER_BUILD_DEFINITIONS, cast(tomlkit.items.Item, layer_build_definitions_table))

if not self._filepath.exists():
open(self._filepath, "a+").close()
open(self._filepath, "a+").close() # pylint: disable=consider-using-with

self._filepath.write_text(tomlkit.dumps(document))

Expand Down
14 changes: 10 additions & 4 deletions samcli/lib/cookiecutter/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,16 @@ def generate_project(self, context: Dict, output_dir: str) -> None:
output_dir: str
the directory where project will be generated in
Raise:
Raises
------
InvalidLocationError: if the given location is not from a known repo type
GenerateProjectFailedError: if something else went wrong
PreprocessingError
xxx
InvalidLocationError
if the given location is not from a known repo type
GenerateProjectFailedError
if something else went wrong
PostprocessingError
yyy
"""
try:
LOG.debug("preprocessing the cookiecutter context")
Expand All @@ -161,7 +167,7 @@ def generate_project(self, context: Dict, output_dir: str) -> None:
extra_context=context,
overwrite_if_exists=True,
)
except RepositoryNotFound as e:
except RepositoryNotFound:
# cookiecutter.json is not found in the template. Let's just clone it directly without
# using cookiecutter and call it done.
LOG.debug(
Expand Down
2 changes: 1 addition & 1 deletion samcli/lib/init/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def generate_project(
# https://github.com/cookiecutter/cookiecutter/pull/1407
if platform.system().lower() == "windows":
osutils.convert_files_to_unix_line_endings(output_dir, ["gradlew"])
except RepositoryNotFound as e:
except RepositoryNotFound:
# cookiecutter.json is not found in the template. Let's just clone it directly without using cookiecutter
# and call it done.
LOG.debug(
Expand Down
3 changes: 1 addition & 2 deletions samcli/lib/package/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,7 @@ def make_zip(file_name, source_root):
source_root = os.path.abspath(source_root)
compression_type = zipfile.ZIP_DEFLATED
with open(zipfile_name, "wb") as f:
zip_file = zipfile.ZipFile(f, "w", compression_type)
with contextlib.closing(zip_file) as zf:
with contextlib.closing(zipfile.ZipFile(f, "w", compression_type)) as zf:
for root, _, files in os.walk(source_root, followlinks=True):
for filename in files:
full_path = os.path.join(root, filename)
Expand Down
4 changes: 2 additions & 2 deletions samcli/lib/utils/codeuri.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ def resolve_code_path(cwd, codeuri):
Parameters
----------
cwd str
cwd : str
Current working directory
codeuri
codeuri : str
CodeURI of the function. This should contain the path to the function code
Returns
Expand Down
6 changes: 3 additions & 3 deletions samcli/lib/utils/git_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ def _git_executable() -> str:

for executable in executables:
try:
subprocess.Popen([executable], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
# No exception. Let's pick this
return executable
with subprocess.Popen([executable], stdout=subprocess.PIPE, stderr=subprocess.PIPE):
# No exception. Let's pick this
return executable
except OSError as ex:
LOG.debug("Unable to find executable %s", executable, exc_info=ex)

Expand Down
19 changes: 12 additions & 7 deletions samcli/lib/utils/hash.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ def file_checksum(file_name: str, hash_generator: Any = None) -> str:
Parameters
----------
file_name: file name of the file for which md5 checksum is required.
hash_generator: hashlib _Hash object for generating hashes. Defaults to hashlib.md5.
file_name : str
file name of the file for which md5 checksum is required.
hash_generator : hashlib._Hash
hashlib _Hash object for generating hashes. Defaults to hashlib.md5.
Returns
-------
Expand Down Expand Up @@ -48,10 +49,14 @@ def dir_checksum(
Parameters
----------
directory : A directory with an absolute path
followlinks: Follow symbolic links through the given directory
ignore_list: The list of file/directory names to ignore in checksum
hash_generator: The hashing method (hashlib _Hash object) that generates checksum. Defaults to hashlib.md5.
directory : dict
A directory with an absolute path
followlinks : bool
Follow symbolic links through the given directory
ignore_list : list(str)
The list of file/directory names to ignore in checksum
hash_generator : hashlib._Hash
The hashing method (hashlib _Hash object) that generates checksum. Defaults to hashlib.md5.
Returns
-------
Expand Down
5 changes: 4 additions & 1 deletion samcli/lib/utils/managed_cloudformation_stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ def manage_stack(
parameter_overrides: Optional[Dict[str, Union[str, List[str]]]]
Values of template parameters, if any.
Returns: Stack output section(list of OutputKey, OutputValue pairs)
Returns
-------
StackOutput:
Stack output section(list of OutputKey, OutputValue pairs)
"""
try:
if profile:
Expand Down
14 changes: 8 additions & 6 deletions samcli/local/docker/lambda_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,17 +86,19 @@ def build(self, runtime, packagetype, image, layers, architecture, stream=None,
Parameters
----------
runtime str
runtime : str
Name of the Lambda runtime
packagetype str
packagetype : str
Packagetype for the Lambda
image str
image : str
Pre-defined invocation image.
layers list(samcli.commands.local.lib.provider.Layer)
layers : list(samcli.commands.local.lib.provider.Layer)
List of layers
architecture
architecture : str
Architecture type either x86_64 or arm64 on AWS lambda
function_name str
stream : io.RawIOBase
stream to write
function_name : str
The name of the function that the image is building for
Returns
Expand Down

0 comments on commit d1db668

Please sign in to comment.