Skip to content

pin setuptools<82 in pip packaging command to prevent pkg_resources removal #278

Merged
rory-xu merged 3 commits intoaws-cloudformation:masterfrom
tagtestorg:fix/pin-setuptools-lt-82
Apr 16, 2026
Merged

pin setuptools<82 in pip packaging command to prevent pkg_resources removal #278
rory-xu merged 3 commits intoaws-cloudformation:masterfrom
tagtestorg:fix/pin-setuptools-lt-82

Conversation

@tagaws
Copy link
Copy Markdown
Contributor

@tagaws tagaws commented Apr 15, 2026

Issue

Companion to aws-cloudformation/cloudformation-cli#[https://github.com/aws-cloudformation/cloudformation-cli/pull/1118]

Problem

cfn submit runs:
pip install --upgrade --requirement requirements.txt --target build/

With no setuptools version constraint, --upgrade pulls setuptools 82+ into the build zip. setuptools 82 removed pkg_resources, breaking cloudformation-cli-python-lib at runtime.

Downgrading setuptools in the dev venv does NOT fix this — cfn submit re-installs fresh into build/ regardless of the venv state.

Changes

  • codegen.py _make_pip_command: append setuptools<82 to the pip install command so the build zip never contains a broken setuptools
  • setup.py: pin setuptools<82 in install_requires
  • templates/requirements.txt: add setuptools<82 so new projects from cfn init have the pin from day one

Testing

  • rpdk.log confirms setuptools-81.0.0 installed during packaging (not 82+)
  • Unit test test__make_pip_command_pins_setuptools_lt_82 added to codegen_test.py
  • End-to-end: cfn submit --dry-run + zip inspection confirms constraint works (Also tested cfn test with sam local deploy working as expected)

Comment thread setup.py
"cloudformation-cli>=0.2.26",
"types-dataclasses>=0.1.5",
"setuptools",
"setuptools<82",
Copy link
Copy Markdown
Contributor Author

@tagaws tagaws Apr 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Protects the dev env (venv) from pinning incorrect setuptools version still safe to add a <82 here, although codegen.py is what compiles it into the build: - If someone uses a different build tool or manually runs pip against requirements.txt

@@ -1 +1,2 @@
{{ support_lib_name }}>=2.1.9
setuptools<82
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without this change, a brand new project created with cfn init would get a requirements.txt containing only:

cloudformation-cli-python-lib>=2.1.9

You would still need to pin <82 locally to get cfn init working based on my testing on a fresh instalation without pinning <82 when you run cfn init you will get the following error "ModuleNotFoundError: No module named 'pkg_resources' "

@tagaws tagaws marked this pull request as ready for review April 16, 2026 07:25
@tagaws
Copy link
Copy Markdown
Contributor Author

tagaws commented Apr 16, 2026

Issue mentioned here aws-cloudformation/cloudformation-cli#1117

@rory-xu rory-xu assigned rory-xu and unassigned rory-xu Apr 16, 2026
@rory-xu rory-xu requested review from AkifRafique and rory-xu April 16, 2026 21:17
@rory-xu rory-xu merged commit 9159d8b into aws-cloudformation:master Apr 16, 2026
15 checks passed
@tagaws tagaws deleted the fix/pin-setuptools-lt-82 branch April 17, 2026 21:28
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.

3 participants