Skip to content

Suppress pkg_resources deprecation warning on Alpine Docker builds#10095

Open
fresh3nough wants to merge 1 commit intoaws:v2from
fresh3nough:fix/pkg-resources-deprecation-warning
Open

Suppress pkg_resources deprecation warning on Alpine Docker builds#10095
fresh3nough wants to merge 1 commit intoaws:v2from
fresh3nough:fix/pkg-resources-deprecation-warning

Conversation

@fresh3nough
Copy link

Issue

Fixes #10065

Description

Building AWS CLI v2 from source on Alpine Docker with setuptools >= 81 produces a UserWarning at runtime:

PyInstaller/loader/pyimod02_importers.py:384: UserWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html. The pkg_resources package is slated for removal as early as 2025-11-30. Refrain from using this package or pin to Setuptools<81.

This change addresses two root causes:

  1. Removes the outdated pkg_resources.py2_warn hidden import from exe/pyinstaller/hook-awscli.py. This hidden import was a workaround for pypa/setuptools#1963, which has been resolved upstream in PyInstaller 5.5+ (see pyinstaller/pyinstaller#6952). The py2_warn module was removed from setuptools around version 49.

  2. Adds a PyInstaller runtime hook (pyi_rth_pkg_resources_warning.py) that suppresses the UserWarning emitted by setuptools >= 81 when pkg_resources is imported at runtime. This hook is registered in both aws.spec and aws_completer.spec.

Steps to Reproduce the Issue

Build the CLI on Alpine Docker using the following Dockerfile:

FROM alpine:latest

WORKDIR /aws-cli-sourcecode

RUN apk upgrade --no-cache && \
    apk add --update --no-cache bash ca-certificates musl-dev curl jq htop groff build-base libffi-dev cmake git && \
    apk add python3-dev python3 && \
    git clone --recursive --depth 1 --branch v2 --single-branch https://github.com/aws/aws-cli.git /aws-cli-sourcecode

RUN python -m venv venv && \
    . venv/bin/activate && \
    python3 -m ensurepip && \
    ln -s /usr/bin/pip3 /usr/bin/pip && \
    pip install setuptools && \
    scripts/installers/make-exe && \
    unzip -q dist/awscli-exe.zip && \
    aws/install --bin-dir /aws-cli-bin && \
    /aws-cli-bin/aws --version

Before this fix, the final command outputs:

PyInstaller/loader/pyimod02_importers.py:384: UserWarning: pkg_resources is deprecated as an API...
aws-cli/2.x.x Python/3.x.x Linux/...

Steps to Verify the Fix

Build with the same Dockerfile, replacing the git clone branch with this PR branch. The warning should no longer appear in the output of /aws-cli-bin/aws --version.

Changes

  • exe/pyinstaller/hook-awscli.py: Removed pkg_resources.py2_warn from hidden imports
  • exe/pyinstaller/pyi_rth_pkg_resources_warning.py: New runtime hook to filter the deprecation warning
  • exe/pyinstaller/aws.spec: Added runtime hook reference
  • exe/pyinstaller/aws_completer.spec: Added runtime hook reference

Remove outdated pkg_resources.py2_warn hidden import from the
PyInstaller hook for awscli. This hidden import was a workaround
for pypa/setuptools#1963 which has been resolved in PyInstaller 5.5+.

Add a PyInstaller runtime hook to suppress the UserWarning emitted
by setuptools >= 81 when pkg_resources is imported at runtime. This
prevents the deprecation warning from appearing in CLI output when
building the v2 CLI from source with newer setuptools versions.

Fixes aws#10065
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

Comments