Skip to content

Commit

Permalink
Merge branch 'master' into zappa-settings-add-exclude
Browse files Browse the repository at this point in the history
  • Loading branch information
monkut authored Nov 10, 2023
2 parents a3f434a + dd5d1f3 commit 3747f83
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 17 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
11 changes: 5 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1196,14 +1196,13 @@ If you want to use native AWS Lambda environment variables you can use the `aws_
During development, you can add your Zappa defined variables to your locally running app by, for example, using the below (for Django, to manage.py).

```python
if 'SERVERTYPE' in os.environ and os.environ['SERVERTYPE'] == 'AWS Lambda':
import json
import os
import json
import os

if os.environ.get('AWS_LAMBDA_FUNCTION_NAME') is None: # Ensures app is NOT running on Lambda
json_data = open('zappa_settings.json')
env_vars = json.load(json_data)['dev']['environment_variables']
for key, val in env_vars.items():
os.environ[key] = val

os.environ.update(env_vars)
```

#### Remote Environment Variables
Expand Down
18 changes: 9 additions & 9 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 @@ -475,7 +475,7 @@ def positive_int(s):
else:
self.stage_env = self.vargs.get("stage_env")

if args.command == "package":
if args.command in ("package", "save-python-settings-file"):
self.load_credentials = False

self.command = args.command
Expand Down Expand Up @@ -2415,14 +2415,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 @@ -2433,11 +2433,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 @@ -2449,7 +2449,7 @@ def create_package(self, output=None, use_zappa_release: Optional[str] = None):
exclude = self.stage_config.get("exclude", [])

# 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 @@ -2473,7 +2473,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
2 changes: 1 addition & 1 deletion zappa/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

# Set up logging
logging.basicConfig()
logger = logging.getLogger()
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)


Expand Down
2 changes: 1 addition & 1 deletion zappa/wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ def common_log(environ, response, response_time: Optional[int] = None):
response_time: response time in micro-seconds
"""

logger = logging.getLogger()
logger = logging.getLogger(__name__)

if response_time:
formatter = ApacheNCSAFormatter(with_response_time=True)
Expand Down

0 comments on commit 3747f83

Please sign in to comment.