This repository has been archived by the owner on Nov 30, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix installation of common Python packages (#1424)
* Fix package installation * Update comment * Move python to front of PATH * Add PYTHON parameter * Move ML packages to new script * Remove invalid docs * Check for PYTHON * Install packages from argument * Resolve comments * Add tests for new packages * Copy JupyterLab script * Use generic package install script * Add new script to README * Add missing $ * Try to fix smoke test * Revert changes to jupyterlab-debian.sh * Fix directory of Python * Remove busted sudos * Update test.sh Co-authored-by: Josh Spicer <[email protected]>
- Loading branch information
1 parent
ab35cd6
commit f7b92c8
Showing
6 changed files
with
179 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
containers/codespaces-linux/.devcontainer/library-scripts/python-package-debian.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#!/usr/bin/env bash | ||
#------------------------------------------------------------------------------------------------------------- | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information. | ||
#------------------------------------------------------------------------------------------------------------- | ||
# | ||
# Docs: https://github.com/microsoft/vscode-dev-containers/blob/main/script-library/docs/python-package-debian.md | ||
# Maintainer: The VS Code and Codespaces Teams | ||
# | ||
# Syntax: ./python-package-debian.sh | ||
|
||
set -e | ||
|
||
PACKAGE=${1:-""} | ||
VERSION=${2:-"latest"} | ||
PYTHON=${3:-"python"} | ||
USERNAME=${4-"automatic"} | ||
|
||
# If in automatic mode, determine if a user already exists, if not use vscode | ||
if [ "${USERNAME}" = "auto" ] || [ "${USERNAME}" = "automatic" ]; then | ||
USERNAME="" | ||
POSSIBLE_USERS=("vscode" "node" "codespace" "$(awk -v val=1000 -F ":" '$3==val{print $1}' /etc/passwd)") | ||
for CURRENT_USER in ${POSSIBLE_USERS[@]}; do | ||
if id -u ${CURRENT_USER} > /dev/null 2>&1; then | ||
USERNAME=${CURRENT_USER} | ||
break | ||
fi | ||
done | ||
if [ "${USERNAME}" = "" ]; then | ||
USERNAME=vscode | ||
fi | ||
elif [ "${USERNAME}" = "none" ]; then | ||
USERNAME=root | ||
USER_UID=0 | ||
USER_GID=0 | ||
fi | ||
|
||
# Use sudo to run as non-root user is not already running | ||
sudoUserIf() | ||
{ | ||
if [ "$(id -u)" -eq 0 ] && [ "${USERNAME}" != "root" ]; then | ||
sudo -u ${USERNAME} "$@" | ||
else | ||
"$@" | ||
fi | ||
} | ||
|
||
# Make sure that Python is installed correctly | ||
if ! ${PYTHON} --version > /dev/null ; then | ||
echo "Python command not found: ${PYTHON}" | ||
exit 1 | ||
fi | ||
|
||
# pip skips installation when a requirement is already satisfied | ||
if [ ${VERSION} = "latest" ]; then | ||
sudoUserIf ${PYTHON} -m pip install ${PACKAGE} --no-cache-dir | ||
else | ||
sudoUserIf ${PYTHON} -m pip install ${PACKAGE}==${VERSION} --no-cache-dir | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# Python Package Install Script | ||
|
||
*Installs a Python package.* | ||
|
||
**Script status**: Stable | ||
|
||
**OS support**: Debian 9+, Ubuntu 18.04+, and downstream distros. | ||
|
||
**Maintainer**: GitHub Codespaces team | ||
|
||
## Syntax | ||
|
||
```text | ||
./python-package-debian.sh PACKAGE [VERSION] [PYTHON_BINARY] [USERNAME] | ||
``` | ||
|
||
## Usage | ||
|
||
### Script use | ||
|
||
1. Add [`python-package-debian.sh`](../python-package-debian.sh) to `.devcontainer/library-scripts` | ||
|
||
2. Add the following to your `.devcontainer/Dockerfile`: | ||
|
||
```Dockerfile | ||
COPY library-scripts/python-package-debian.sh /tmp/library-scripts/ | ||
RUN bash /tmp/library-scripts/python-package-debian.sh PACKAGE | ||
``` | ||
|
||
That's it! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#!/usr/bin/env bash | ||
#------------------------------------------------------------------------------------------------------------- | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information. | ||
#------------------------------------------------------------------------------------------------------------- | ||
# | ||
# Docs: https://github.com/microsoft/vscode-dev-containers/blob/main/script-library/docs/python-package-debian.md | ||
# Maintainer: The VS Code and Codespaces Teams | ||
# | ||
# Syntax: ./python-package-debian.sh | ||
|
||
set -e | ||
|
||
PACKAGE=${1:-""} | ||
VERSION=${2:-"latest"} | ||
PYTHON=${3:-"python"} | ||
USERNAME=${4-"automatic"} | ||
|
||
# If in automatic mode, determine if a user already exists, if not use vscode | ||
if [ "${USERNAME}" = "auto" ] || [ "${USERNAME}" = "automatic" ]; then | ||
USERNAME="" | ||
POSSIBLE_USERS=("vscode" "node" "codespace" "$(awk -v val=1000 -F ":" '$3==val{print $1}' /etc/passwd)") | ||
for CURRENT_USER in ${POSSIBLE_USERS[@]}; do | ||
if id -u ${CURRENT_USER} > /dev/null 2>&1; then | ||
USERNAME=${CURRENT_USER} | ||
break | ||
fi | ||
done | ||
if [ "${USERNAME}" = "" ]; then | ||
USERNAME=vscode | ||
fi | ||
elif [ "${USERNAME}" = "none" ]; then | ||
USERNAME=root | ||
USER_UID=0 | ||
USER_GID=0 | ||
fi | ||
|
||
# Use sudo to run as non-root user is not already running | ||
sudoUserIf() | ||
{ | ||
if [ "$(id -u)" -eq 0 ] && [ "${USERNAME}" != "root" ]; then | ||
sudo -u ${USERNAME} "$@" | ||
else | ||
"$@" | ||
fi | ||
} | ||
|
||
# Make sure that Python is installed correctly | ||
if ! ${PYTHON} --version > /dev/null ; then | ||
echo "Python command not found: ${PYTHON}" | ||
exit 1 | ||
fi | ||
|
||
# pip skips installation when a requirement is already satisfied | ||
if [ ${VERSION} = "latest" ]; then | ||
sudoUserIf ${PYTHON} -m pip install ${PACKAGE} --no-cache-dir | ||
else | ||
sudoUserIf ${PYTHON} -m pip install ${PACKAGE}==${VERSION} --no-cache-dir | ||
fi |