Skip to content

fix(autogen-ext): collect required packages from every pip install line - #8445

Open
电大老baby (HhH666-ux) wants to merge 1 commit into
microsoft:mainfrom
HhH666-ux:fix/required-packages-accumulate
Open

电大老baby (HhH666-ux) wants to merge 1 commit into
microsoft:mainfrom
HhH666-ux:fix/required-packages-accumulate

Conversation

@HhH666-ux

Copy link
Copy Markdown

Description

Fixes #8444.

get_required_packages() walked every !pip install line of a code block but assigned to the result set inside the loop (ret = {...}), so only the packages from the last matching line survived. AzureContainerCodeExecutor uses this function to gate execution on package availability (_azure_container_code_executor.py:451-457), so a block like

!pip install numpy
!pip install pandas

only checked pandas against the environment: a missing numpy passed the gate and the code failed inside the container with ModuleNotFoundError instead of the intended "Python packages unavailable in environment: {numpy}" message.

Changes

  • Accumulate requirements across lines with ret.update(...).
  • Strip all surrounding whitespace from each requirement (tabs as well as spaces) and skip empty entries from trailing commas.
  • The duplicated comment about the -qqq flag (copied from silence_pip) now describes what the function actually does.
  • Two regression tests: multi-line accumulation and the non-python early return.

Testing

$ pytest tests/code_executors/test_commandline_code_executor.py -k get_required_packages
2 passed, 14 deselected in 0.71s

Also verified end to end with the repro from #8444: the function now returns {'numpy', 'pandas', 'requests'} for a three-line install block.

get_required_packages assigned to the result set inside the loop, so only
the packages of the last '!pip install' line survived. The Azure container
code executor relies on this function to gate execution on package
availability, which let blocks with multiple install lines run with
missing packages and fail at import time.

Accumulate with set.update, strip all surrounding whitespace from each
requirement, and skip empty entries.

Fixes microsoft#8444

This branch has not been deployed

No deployments
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.

AzureContainerCodeExecutor: get_required_packages keeps only the last !pip install line's packages

1 participant