Skip to content

Commit 7cd7958

Browse files
author
Taniya Mathur
committed
Update PyYAML dependency handling across publish scripts and docs
1 parent 35eabfe commit 7cd7958

File tree

3 files changed

+12
-15
lines changed

3 files changed

+12
-15
lines changed

docs/deployment.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ You need to have the following packages installed on your computer:
2626
3. [sam (AWS SAM)](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/install-sam-cli.html)
2727
4. python 3.11 or later
2828
5. A local Docker daemon
29-
6. Python packages for publish.py: `pip install boto3 typer rich botocore setuptools`
29+
6. Python packages for publish.py: `pip install boto3 rich PyYAML botocore setuptools`
3030

3131
For guidance on setting up a development environment, see: [Development Environment Setup Guide on Linux](./setup-development-env-linux.md) or [Development Environment Setup Guide on MacOS](./setup-development-env-macos.md)
3232

publish.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
from urllib.parse import quote
2323

2424
import boto3
25+
import yaml
2526
from botocore.exceptions import ClientError
2627
from rich.console import Console
2728
from rich.progress import (
@@ -933,15 +934,6 @@ def _check_requirements_has_idp_common_pkg(self, func_dir):
933934
def _extract_function_name(self, dir_name, template_path):
934935
"""Extract CloudFormation function name from template by matching CodeUri."""
935936
try:
936-
try:
937-
import yaml
938-
except ImportError:
939-
self.console.print("[yellow]PyYAML not found, installing...[/yellow]")
940-
subprocess.run(
941-
[sys.executable, "-m", "pip", "install", "PyYAML"], check=True
942-
)
943-
import yaml
944-
945937
# Create a custom loader that ignores CloudFormation intrinsic functions
946938
class CFLoader(yaml.SafeLoader):
947939
pass

publish.sh

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,19 @@ check_python_version() {
8888
check_and_install_packages() {
8989
print_info "Checking required Python packages..."
9090

91-
# List of required packages
92-
required_packages=("typer" "rich" "boto3")
91+
# List of required packages (import_name:package_name)
92+
declare -A required_packages=(
93+
["typer"]="typer"
94+
["rich"]="rich"
95+
["boto3"]="boto3"
96+
["yaml"]="PyYAML"
97+
)
9398
missing_packages=()
9499

95100
# Check each package
96-
for package in "${required_packages[@]}"; do
97-
if ! $PYTHON_CMD -c "import $package" >/dev/null 2>&1; then
98-
missing_packages+=("$package")
101+
for import_name in "${!required_packages[@]}"; do
102+
if ! $PYTHON_CMD -c "import $import_name" >/dev/null 2>&1; then
103+
missing_packages+=("${required_packages[$import_name]}")
99104
fi
100105
done
101106

0 commit comments

Comments
 (0)