Skip to content

Commit a55a4c6

Browse files
authored
New python dev container (#2)
New version for app-python & azure-function-python
1 parent b3a97a9 commit a55a4c6

File tree

95 files changed

+2953
-452
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

95 files changed

+2953
-452
lines changed

.devcontainer/check-post-install.sh

-26
This file was deleted.

.devcontainer/devcontainer.json

-36
This file was deleted.

.devcontainer/install-deps.sh

+1-10
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,4 @@
11
#!/bin/bash
22

33
sudo apt-get update
4-
sudo DEBIAN_FRONTEND=noninteractive apt-get -yq install vim
5-
6-
# Install the Microsoft ODBC driver for SQL Server (Linux)
7-
# https://learn.microsoft.com/en-us/sql/connect/odbc/linux-mac/installing-the-microsoft-odbc-driver-for-sql-server
8-
9-
# curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -
10-
# curl https://packages.microsoft.com/config/debian/11/prod.list > /etc/apt/sources.list.d/mssql-release.list
11-
# sudo apt-get update
12-
# sudo ACCEPT_EULA=Y apt-get install -y msodbcsql18
13-
# Notice: Add pyodbc in requirements.txt or pyproject.toml file.
4+
sudo DEBIAN_FRONTEND=noninteractive apt-get -yq install vim dos2unix

.devcontainer/install.sh

+31-101
Original file line numberDiff line numberDiff line change
@@ -1,121 +1,51 @@
11
#!/bin/bash
22

3-
RED="\e[31m"
4-
GREEN="\e[32m"
5-
BLUE="\e[34m"
6-
YELLOW="\e[33m"
7-
ENDCOLOR="\e[0m"
3+
. "$WORKSPACE_PATH/tools/color.sh"
84

9-
echo -e "\n${BLUE}################################"
10-
echo -e "${BLUE}#### INSTALL.SH ####${ENDCOLOR}"
11-
echo -e "${BLUE}################################"
5+
cd "$WORKSPACE_PATH/.devcontainer/install"
126

13-
echo -e "\n${GREEN}> Configure virtual environment.${ENDCOLOR}\n"
7+
CONTAINER_TYPE=$(jq -r '.customizations.vscode.settings."container.type"' $WORKSPACE_PATH/.devcontainer/devcontainer.json);
8+
echo -e "\n${BLUE}You are about to initiate a project '${YELLOW}$CONTAINER_TYPE${BLUE}'.${ENDCOLOR}"
149

15-
sudo chgrp vscode /workspaces/app/.venv
16-
sudo chown vscode /workspaces/app/.venv
17-
18-
git config --global --add safe.directory /workspaces/app
19-
git config --global core.eol lf
20-
git config --global core.autocrlf false
21-
22-
python3 -m venv /workspaces/app/.venv
23-
PATH="/workspaces/app/.venv/bin:$PATH"
24-
25-
echo -e "Done.\n"
26-
27-
echo -e "${GREEN}> Update PIP tool.${ENDCOLOR}\n"
28-
pip install --upgrade pip
29-
30-
echo -e "\n${GREEN}> Identify the packaging and dependency manager to install.${ENDCOLOR}\n"
31-
32-
PIP_MANAGER=false
33-
POETRY_MANAGER=false
34-
35-
NEW_POETRY_INSTALL=false
36-
37-
FILE=/workspaces/app/requirements.txt
38-
39-
if [ -f "$FILE" ];
40-
then
41-
echo -e "PIP configuration file was found (requirements.txt).\n"
42-
PIP_MANAGER=true
43-
fi
44-
45-
FILE=/workspaces/app/pyproject.toml
46-
47-
if [ -f "$FILE" ];
48-
then
49-
echo -e "POETRY configuration file was found (pyproject.toml).${ENDCOLOR}"
50-
POETRY_MANAGER=true
51-
fi
52-
53-
if [ "$POETRY_MANAGER" = true ] && [ "$PIP_MANAGER" = true ];
54-
then
55-
echo -e "${RED}> ERROR: You cannot define two packaging and dependency manager in the same time.${ENDCOLOR}\n"
10+
if [ ]; then
11+
echo -e "\n💥 ${RED}Installation was aborted. Specified container type '$CONTAINER_TYPE' is not supported.${ENDCOLOR}💥\n"
5612
exit 1
5713
fi
5814

59-
if [ "$POETRY_MANAGER" = false ] && [ "$PIP_MANAGER" = false ];
60-
then
61-
62-
echo -e "${YELLOW}No packaging and dependency manager was found.${ENDCOLOR}"
63-
echo -e "${YELLOW}Type 'PIP' or 'POETRY' if you want to install a packaging and dependency manager !${ENDCOLOR}"
64-
echo -e "${YELLOW}Another option will install no packaging and dependency manager.${ENDCOLOR}"
65-
echo -e "${YELLOW}Your selection :${ENDCOLOR}"
15+
install_files=()
6616

67-
read MANAGER
68-
echo -e "The following packaging and dependency manager will be installed : $MANAGER\n"
69-
70-
if [ "${MANAGER^^}" = "POETRY" ]
71-
then
72-
POETRY_MANAGER=true
73-
NEW_POETRY_INSTALL=true
17+
while IFS= read -r -d $'\0' current_file ; do
18+
if ! grep -q "# ignored: $CONTAINER_TYPE" "$current_file"; then
19+
install_files+=("$current_file")
7420
fi
21+
done < <(find ./ -type f -name "*.sh" -print0)
7522

76-
if [ "${MANAGER^^}" = "PIP" ]
77-
then
78-
PIP_MANAGER=true
79-
touch /workspaces/app/requirements.txt
80-
touch /workspaces/app/requirements-dev.txt
81-
fi
23+
install_files=($(printf "%s\n" "${install_files[@]}" | sort))
8224

83-
fi
84-
85-
source /workspaces/app/.venv/bin/activate
25+
echo -e "${BLUE}We have found ${YELLOW}${#install_files[@]}${BLUE} installation files.${ENDCOLOR}"
8626

87-
if [ "$PIP_MANAGER" = true ];
88-
then
27+
for install_file in "${install_files[@]}"; do
28+
if [ -f "$install_file" ]; then
8929

90-
echo -e "${GREEN}> Install dependencies with PIP.${ENDCOLOR}\n"
30+
echo -e "\n\e[104m Execute: $install_file \e[49m"
9131

92-
# pip install keyring artifacts-keyring
32+
if [ ! -x "$install_file" ]; then
33+
chmod +x "$install_file"
34+
fi
9335

94-
# cat <<EOF >> /workspaces/app/.venv/pip.conf
95-
# [global]
96-
# extra-index-url=https://pkgs.dev.azure.com/...
97-
# EOF
36+
./"$install_file"
9837

99-
pip install -r /workspaces/app/requirements-dev.txt
100-
pip install -r /workspaces/app/requirements.txt
38+
if [ "$?" -ge 1 ]; then
39+
echo -e "\n💥 ${RED}Installation was aborted. Check the errors displayed above.${ENDCOLOR}💥\n"
40+
exit 1
41+
else
42+
echo -e "${YELLOW}... Press any key to continue ..."
43+
read -s -p " " -n 1 -r
44+
echo -e "${ENDCOLOR}"
45+
fi
10146

102-
fi
103-
104-
if [ "$POETRY_MANAGER" = true ];
105-
then
106-
107-
echo -e "${GREEN}> Install POETRY tool and install dependencies.${ENDCOLOR}\n"
108-
curl -sSL https://install.python-poetry.org | python3 -
109-
poetry completions bash >> ~/.bash_completion
110-
111-
if [ "$POETRY_MANAGER" = true ];
112-
then
113-
poetry init
11447
fi
48+
done
11549

116-
poetry install
117-
118-
fi
119-
120-
chmod +x /workspaces/app/.devcontainer/check-post-install.sh
121-
/workspaces/app/.devcontainer/check-post-install.sh
50+
echo -e "🎉 ${YELLOW}Installation is finished!${ENDCOLOR}"
51+
echo -e "🎉 ${YELLOW}You can close all terminal windows and reload the project!${ENDCOLOR}\n"
+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#!/bin/bash
2+
3+
. "$WORKSPACE_PATH/tools/color.sh"
4+
5+
echo -e "\n${BLUE}#############################################################${ENDCOLOR}"
6+
echo -e "${BLUE}##### #####${ENDCOLOR}"
7+
echo -e "${BLUE}##### Project review #####${ENDCOLOR}"
8+
echo -e "${BLUE}##### #####${ENDCOLOR}"
9+
echo -e "${BLUE}#############################################################${ENDCOLOR}"
10+
11+
echo -e "\n${GREEN}> Project review.${ENDCOLOR}\n"
12+
13+
DEPENDENCY_MANAGER=$(jq -r '.customizations.vscode.settings."python.dependencyManager"' $WORKSPACE_PATH/.devcontainer/devcontainer.json);
14+
PRE_COMMIT_ENABLED=$(jq -r '.customizations.vscode.settings."git.preCommitEnabled"' $WORKSPACE_PATH/.devcontainer/devcontainer.json);
15+
PYTEST_ENABLED=$(jq -r '.customizations.vscode.settings."python.testing.pytestEnabled"' $WORKSPACE_PATH/.devcontainer/devcontainer.json);
16+
UNITTEST_ENABLED=$(jq -r '.customizations.vscode.settings."python.testing.unittestEnabled"' $WORKSPACE_PATH/.devcontainer/devcontainer.json);
17+
COVERAGE_ENABLED=$(jq -r '.customizations.vscode.settings."python.testing.coverageEnabled"' $WORKSPACE_PATH/.devcontainer/devcontainer.json);
18+
FORMATTER=$(jq -r '.customizations.vscode.settings."editor.defaultFormatter"' $WORKSPACE_PATH/.devcontainer/devcontainer.json);
19+
20+
PIP_EXTRA_INDEX_URL=$(jq -r '.customizations.vscode.settings."python.pip.extraIndexUrl"' $WORKSPACE_PATH/.devcontainer/devcontainer.json);
21+
22+
echo -e "The dependency manager used for the project is ${YELLOW}$DEPENDENCY_MANAGER${ENDCOLOR}."
23+
echo -e "The formatter used for the project is ${YELLOW}$FORMATTER${ENDCOLOR}.\n"
24+
25+
if [ "$PIP_EXTRA_INDEX_URL" = "" ] || [ "$PIP_EXTRA_INDEX_URL" = "null" ]; then
26+
echo -e "No additional package indexes is configured.\n"
27+
else
28+
echo -e "An additional package indexes is specified (value: ${YELLOW}$PIP_EXTRA_INDEX_URL${ENDCOLOR}).\n"
29+
fi
30+
31+
if [ $PRE_COMMIT_ENABLED = "true" ]; then
32+
echo -e "✔️ㅤPre-commit"
33+
else
34+
echo -e "✖️ㅤPre-commit"
35+
fi
36+
37+
if [ $PYTEST_ENABLED = "true" ]; then
38+
echo -e "✔️ㅤPytest"
39+
else
40+
echo -e "✖️ㅤPytest"
41+
fi
42+
43+
if [ $UNITTEST_ENABLED = "true" ]; then
44+
echo -e "✔️ㅤUnittest"
45+
else
46+
echo -e "✖️ㅤUnittest"
47+
fi
48+
49+
if [ $COVERAGE_ENABLED = "true" ]; then
50+
echo -e "✔️ㅤCode coverage"
51+
else
52+
echo -e "✖️ㅤCode coverage"
53+
fi
54+
55+
if [ "$DEPENDENCY_MANAGER" != "pip" ] && [ "$DEPENDENCY_MANAGER" != "poetry" ]; then
56+
echo -e "\n${RED}No correct packaging and dependency manager is configured.${ENDCOLOR}"
57+
echo -e "${RED}Only 'pip' and 'poetry' managers are supported.${ENDCOLOR}"
58+
STOP=true
59+
fi
60+
61+
if [ "$FORMATTER" != "eeyore.yapf" ] && [ "$FORMATTER" != "ms-python.black-formatter" ]; then
62+
echo -e "\n${RED}No correct formatter is configured.${ENDCOLOR}"
63+
echo -e "${RED}Only 'eeyore.yapf' and 'ms-python.black-formatter' formaters are supported.${ENDCOLOR}"
64+
STOP=true
65+
fi
66+
67+
if [ "$STOP" == "true" ]; then
68+
exit 1
69+
fi
70+
71+
echo -e ""
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/bin/bash
2+
3+
. "$WORKSPACE_PATH/tools/color.sh"
4+
5+
echo -e "\n${BLUE}#############################################################${ENDCOLOR}"
6+
echo -e "${BLUE}##### #####${ENDCOLOR}"
7+
echo -e "${BLUE}##### Fix VSCode Settings File #####${ENDCOLOR}"
8+
echo -e "${BLUE}##### #####${ENDCOLOR}"
9+
echo -e "${BLUE}#############################################################${ENDCOLOR}"
10+
11+
echo -e "\n${GREEN}> Fix VSCode Settings File.${ENDCOLOR}\n"
12+
13+
jq 'del(.["python.formatting.autopep8Path",
14+
"python.formatting.blackPath",
15+
"python.linting.flake8Path",
16+
"python.linting.flake8Enabled",
17+
"python.linting.mypyPath",
18+
"python.linting.mypyEnabled",
19+
"python.linting.pylintPath",
20+
"python.linting.pylintEnabled"
21+
])' $HOME/.vscode-server/data/Machine/settings.json > /tmp/.vscode-server-settings.json
22+
23+
mv /tmp/.vscode-server-settings.json $HOME/.vscode-server/data/Machine/settings.json
24+
25+
echo -e "File '$HOME/.vscode-server/data/Machine/settings.json' has been modified to fix slow issue with linters.\n"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#!/bin/bash
2+
3+
# can-be-removed-after-installation
4+
5+
. "$WORKSPACE_PATH/tools/color.sh"
6+
7+
echo -e "\n${BLUE}#############################################################${ENDCOLOR}"
8+
echo -e "${BLUE}##### #####${ENDCOLOR}"
9+
echo -e "${BLUE}##### Generate .vscode/extensions.json file #####${ENDCOLOR}"
10+
echo -e "${BLUE}##### #####${ENDCOLOR}"
11+
echo -e "${BLUE}#############################################################${ENDCOLOR}"
12+
13+
mkdir -p $SOURCE_PATH
14+
mkdir "$WORKSPACE_PATH/.vscode"
15+
16+
if [ -f "$WORKSPACE_PATH/.vscode/extensions.json" ]; then
17+
echo -e "\n${YELLOW}Nothing to do because file is already existing.\n${ENDCOLOR}"
18+
else
19+
20+
echo -e "\n${GREEN}> Generate file '.vscode/extensions.json'.${ENDCOLOR}\n"
21+
22+
# Create initial file.
23+
merged_content=$(echo '{"recommendations": []}' | jq '.')
24+
25+
# Add extensions specifically for the container type.
26+
CONTAINER_TYPE=$(jq -r '.customizations.vscode.settings."container.type"' $WORKSPACE_PATH/.devcontainer/devcontainer.json);
27+
28+
if [ -f "$WORKSPACE_PATH/.devcontainer/templates/${CONTAINER_TYPE}/config/extensions.json" ]; then
29+
content=$(cat $WORKSPACE_PATH/.devcontainer/templates/${CONTAINER_TYPE}/config/extensions.json)
30+
merged_content=$(echo "$merged_content" | jq ".recommendations += $content")
31+
fi
32+
33+
# Add extensions specifically for the default formatter.
34+
defaultFormatter=$(jq -r '.customizations.vscode.settings."editor.defaultFormatter"' $WORKSPACE_PATH/.devcontainer/devcontainer.json);
35+
36+
if [ "$defaultFormatter" == "ms-python.autopep8" ] || [ "$defaultFormatter" == "ms-python.black-formatter" ] || [ "$defaultFormatter" == "eeyore.yapf" ]; then
37+
content="[\"$defaultFormatter\"]"
38+
merged_content=$(echo "$merged_content" | jq ".recommendations += $content")
39+
fi
40+
41+
# Add other extensions.
42+
if [ -f "$WORKSPACE_PATH/.devcontainer/templates/default/config/extensions.json" ]; then
43+
content=$(cat $WORKSPACE_PATH/.devcontainer/templates/default/config/extensions.json)
44+
merged_content=$(echo "$merged_content" | jq ".recommendations += $content")
45+
fi
46+
47+
# Pretty-print the content and create the file.
48+
formatted_content=$(echo $merged_content | jq -c '.')
49+
echo $formatted_content | python -m json.tool --indent=2 > "$WORKSPACE_PATH/.vscode/extensions.json"
50+
51+
echo -e "Done.\n"
52+
53+
fi

0 commit comments

Comments
 (0)