features icon indicating copy to clipboard operation
features copied to clipboard

WIP: [python] Introduce `packages` option

Open alexander-smolyakov opened this issue 2 years ago • 0 comments

General info

Feature name:

  • ghcr.io/devcontainers/features/python

Attached related issue:

  • https://github.com/devcontainers/images/issues/856

Description:

This PR introduces a new option - packages. The new option receives a comma-spread string as input. The input contains packages that should be installed during the feature installation process.

User experience

The user can specify a package version that would be installed. Usage examples:

Example 1:

{
        "ghcr.io/devcontainers/features/python:1": {
            "version": "3.10.12",
            "packages": "torch,request,aiohttp"
        },
}

Note: In this example, the feature installs the latest versions available in PIP.

Example 2:

{
        "ghcr.io/devcontainers/features/python:1": {
            "version": "3.10.12",
            "packages": "cryptography==41.0.4,urllib3==1.26.18"
        },
}

Note: In this case, the feature install versions were explicitly pointed out in the devcontainer.json.

Installation process

The feature already contains the install_user_package function. Considering new functionality, the function should be updated, and the installation process should be split into two steps:

  1. Uninstall the older package version if it was installed or shipped with Python;
  2. Install the new package version;

The installation folder will be resolved based on the user under which the feature is installed:

  • root: packages will be installed in Python's site-packages folder;
  • non-root users: packages will be installed in the user's site-packages folder;

Changelog

  • Added info about packages and additionalVersions inputs;

  • Introduced the packages option:

    • Added logic to handle packages input;
    • Implemented the install_python_package function to replace the install_user_package function;
    • The sudo_if function moved to the utils.sh file;
  • Added tests to cover new functionality;

Checklist:

  • [ ] Checked that applied changes work as expected

alexander-smolyakov avatar Nov 29 '23 10:11 alexander-smolyakov