Skip to content

Commit

Permalink
Configures 'pre-commit' hooks for Zappa's development tools (#1284)
Browse files Browse the repository at this point in the history
Configures pre-commit hooks for Zappa's development tools
  • Loading branch information
javulticat authored Nov 9, 2023
1 parent 35af3cd commit 10316af
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 8 deletions.
45 changes: 45 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: check-yaml
- id: name-tests-test
args: [--unittest]
exclude: ^tests/utils.py
- repo: https://github.com/pycqa/isort
rev: 5.12.0
hooks:
- id: isort
args: [--profile=black, --gitignore]
- repo: https://github.com/psf/black
rev: 23.10.1
hooks:
- id: black
args: [--line-length=127]
- repo: https://github.com/PyCQA/flake8
rev: 6.1.0
hooks:
- id: flake8
args:
- --count
- --max-complexity=55
- --max-line-length=127
- --statistics
- --extend-ignore=E203,E231,E252,E721,F403,F405,F541,W503
files: zappa
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.6.1
hooks:
- id: mypy
args:
- --show-error-codes
- --pretty
- --ignore-missing-imports
- --no-site-packages
files: zappa
- repo: https://github.com/thlorenz/doctoc
rev: v2.2.0
hooks:
- id: doctoc
args: [--update-only]
files: ./README.md
1 change: 1 addition & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ isort = "*"
mock = "*"
mypy = "*"
packaging = "*"
pre-commit = "*"
pytest = "*"
pytest-cov = "*"

Expand Down
16 changes: 8 additions & 8 deletions zappa/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ class ZappaCLI:
aws_kms_key_arn = ""
context_header_mappings = None
additional_text_mimetypes = None
tags = []
tags = [] # type: ignore[var-annotated]
layers = None

stage_name_env_pattern = re.compile("^[a-zA-Z0-9_]+$")
Expand Down Expand Up @@ -2414,14 +2414,14 @@ def create_package(self, output=None, use_zappa_release: Optional[str] = None):
# Create the Lambda zip package (includes project and virtualenvironment)
# Also define the path the handler file so it can be copied to the zip
# root for Lambda.
current_file = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
current_file = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))) # type: ignore[arg-type]
handler_file = os.sep.join(current_file.split(os.sep)[0:]) + os.sep + "handler.py"

# Create the zip file(s)
if self.stage_config.get("slim_handler", False):
# Create two zips. One with the application and the other with just the handler.
# https://github.com/Miserlou/Zappa/issues/510
self.zip_path = self.zappa.create_lambda_zip(
self.zip_path = self.zappa.create_lambda_zip( # type: ignore[attr-defined]
prefix=self.lambda_name,
use_precompiled_packages=self.stage_config.get("use_precompiled_packages", True),
exclude=self.stage_config.get("exclude", []),
Expand All @@ -2432,11 +2432,11 @@ def create_package(self, output=None, use_zappa_release: Optional[str] = None):

# Make sure the normal venv is not included in the handler's zip
exclude = self.stage_config.get("exclude", [])
cur_venv = self.zappa.get_current_venv()
cur_venv = self.zappa.get_current_venv() # type: ignore[attr-defined]
exclude.append(cur_venv.split("/")[-1])
self.handler_path = self.zappa.create_lambda_zip(
self.handler_path = self.zappa.create_lambda_zip( # type: ignore[attr-defined]
prefix="handler_{0!s}".format(self.lambda_name),
venv=self.zappa.create_handler_venv(use_zappa_release=use_zappa_release),
venv=self.zappa.create_handler_venv(use_zappa_release=use_zappa_release), # type: ignore[attr-defined]
handler_file=handler_file,
slim_handler=True,
exclude=exclude,
Expand All @@ -2448,7 +2448,7 @@ def create_package(self, output=None, use_zappa_release: Optional[str] = None):
exclude = self.stage_config.get("exclude", ["boto3", "dateutil", "botocore", "s3transfer", "concurrent"])

# Create a single zip that has the handler and application
self.zip_path = self.zappa.create_lambda_zip(
self.zip_path = self.zappa.create_lambda_zip( # type: ignore[attr-defined]
prefix=self.lambda_name,
handler_file=handler_file,
use_precompiled_packages=self.stage_config.get("use_precompiled_packages", True),
Expand All @@ -2472,7 +2472,7 @@ def create_package(self, output=None, use_zappa_release: Optional[str] = None):
else:
handler_zip = self.zip_path

with zipfile.ZipFile(handler_zip, "a") as lambda_zip:
with zipfile.ZipFile(handler_zip, "a") as lambda_zip: # type: ignore[call-overload]
settings_s = self.get_zappa_settings_string()

# Copy our Django app into root of our package.
Expand Down

0 comments on commit 10316af

Please sign in to comment.