Skip to content

Commit

Permalink
Feature/improve azure function (#4)
Browse files Browse the repository at this point in the history
Installation scripts improved.
Fix issue about the Azure Function Application.
Complete missing documentation.
  • Loading branch information
bastgau authored Apr 19, 2024
1 parent 8f985b6 commit 8346942
Show file tree
Hide file tree
Showing 11 changed files with 44 additions and 209 deletions.
27 changes: 16 additions & 11 deletions .devcontainer/install/03-generate-file-vscode-extensions-json.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ echo -e "${BLUE}#############################################################${E
mkdir -p $SOURCE_PATH
mkdir -p "$WORKSPACE_PATH/.vscode"

echo -e "\n${GREEN}> Generate file '.vscode/extensions.json'.${ENDCOLOR}\n"

if [ -f "$WORKSPACE_PATH/.vscode/extensions.json" ]; then
echo -e "\n${YELLOW}Nothing to do because file is already existing.\n${ENDCOLOR}"
echo -e "${YELLOW}Nothing to do because file is already existing.\n${ENDCOLOR}"
else

echo -e "\n${GREEN}> Generate file '.vscode/extensions.json'.${ENDCOLOR}\n"

# Create initial file.
merged_content=$(echo '{"recommendations": []}' | jq '.')

Expand All @@ -30,14 +30,6 @@ else
merged_content=$(echo "$merged_content" | jq ".recommendations += $content")
fi

# Add extensions specifically for the default formatter.
defaultFormatter=$(jq -r '.customizations.vscode.settings."editor.defaultFormatter"' $WORKSPACE_PATH/.devcontainer/devcontainer.json);

if [ "$defaultFormatter" == "ms-python.autopep8" ] || [ "$defaultFormatter" == "ms-python.black-formatter" ] || [ "$defaultFormatter" == "eeyore.yapf" ]; then
content="[\"$defaultFormatter\"]"
merged_content=$(echo "$merged_content" | jq ".recommendations += $content")
fi

# Add other extensions.
if [ -f "$WORKSPACE_PATH/.devcontainer/templates/default/config/extensions.json" ]; then
content=$(cat $WORKSPACE_PATH/.devcontainer/templates/default/config/extensions.json)
Expand All @@ -51,3 +43,16 @@ else
echo -e "Done.\n"

fi

# Add extensions specifically for the default formatter in 'devcontainer.json' file.
defaultFormatter=$(jq -r '.customizations.vscode.settings."editor.defaultFormatter"' $WORKSPACE_PATH/.devcontainer/devcontainer.json);

if [ "$defaultFormatter" == "ms-python.autopep8" ] || [ "$defaultFormatter" == "ms-python.black-formatter" ] || [ "$defaultFormatter" == "eeyore.yapf" ]; then
exist=`cat $WORKSPACE_PATH/.devcontainer/devcontainer.json | jq ".customizations.vscode.extensions | contains([\"$defaultFormatter\"])"`
if [ $exist == 'false' ]; then
echo -e "${GREEN}> Update file '.devcontainer/devcontainer.json'.${ENDCOLOR}\n"
cat $WORKSPACE_PATH/.devcontainer/devcontainer.json | jq ".customizations.vscode.extensions += [\"$defaultFormatter\"]" > /tmp/devcontainer.json
mv /tmp/devcontainer.json $WORKSPACE_PATH/.devcontainer/devcontainer.json
echo -e "Done.\n"
fi
fi
3 changes: 1 addition & 2 deletions .devcontainer/install/27-install-requirements-app-python.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
#!/bin/bash

# ignored: azure-function-python
# ignored: poetry-dependency-manager

. "$WORKSPACE_PATH/tools/color.sh"

echo -e "\n${BLUE}#############################################################${ENDCOLOR}"
echo -e "${BLUE}##### #####${ENDCOLOR}"
echo -e "${BLUE}##### Install requirements.txt (app-python version) #####${ENDCOLOR}"
echo -e "${BLUE}##### Install requirements.txt #####${ENDCOLOR}"
echo -e "${BLUE}##### #####${ENDCOLOR}"
echo -e "${BLUE}#############################################################${ENDCOLOR}"

Expand Down
159 changes: 0 additions & 159 deletions .devcontainer/install/27-install-requirements-azure-function-python.sh

This file was deleted.

8 changes: 4 additions & 4 deletions .devcontainer/install/85-extension-installation.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ if [ "$defaultFormatter" == "ms-python.autopep8" ] || [ "$defaultFormatter" == "

quantity=(`code --list-extensions --show-versions 2>/dev/null | grep "$defaultFormatter" | wc -l`)

if [ "$quantity" == "0" ]; then
if [ "$quantity" == "-1" ]; then

echo -e "\n${RED}The extension has not been automatically installed.${ENDCOLOR}"
echo -e "\n${BLUE}To install the extension manually, you can in the sidebar on the left, in the 'extension' menu (ctrl+shift+x) search for the extension from its extension id which is:${ENDCOLOR} '$defaultFormatter'\n"
Expand All @@ -67,12 +67,12 @@ if [ "$defaultFormatter" == "ms-python.autopep8" ] || [ "$defaultFormatter" == "

quantity=(`code --list-extensions --show-versions 2>/dev/null | grep "$defaultFormatter_id" | wc -l`)

if [ "$quantity" == "0" ]; then
if [ "$quantity" == "-1" ]; then
echo -e "${RED}The extension seems not to be installed. Please check again!${ENDCOLOR}"
echo -e "${RED}Failure to adhere to a common code formatting tool in a Python project can lead to style inconsistencies, merge conflicts, and reduced team productivity.${ENDCOLOR}\n"
echo -e "${RED}Despite this anomaly, the container installation processus will continue.${ENDCOLOR}"
else
echo -e "Done. Extension is installed."
# else
# echo -e "Done. Extension is installed."
fi

fi
Expand Down
4 changes: 2 additions & 2 deletions .devcontainer/install/86-fix-mypy-extension.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ ORIGINAL_FILE_1="$HOME/.vscode-server/extensions/ms-python.mypy-type-checker-202
ORIGINAL_FILE_2="$HOME/.vscode-server/extensions/ms-python.mypy-type-checker-2023.6.0/bundled/tool/lsp_server.py"

if [ -f "$ORIGINAL_FILE_1" ]; then
$ORIGINAL_FILE=$ORIGINAL_FILE_1
ORIGINAL_FILE=$ORIGINAL_FILE_1
fi

if [ -f "$ORIGINAL_FILE_2" ]; then
$ORIGINAL_FILE=$ORIGINAL_FILE_2
ORIGINAL_FILE=$ORIGINAL_FILE_2
fi

if [ -f "$ORIGINAL_FILE" ]; then
Expand Down
23 changes: 0 additions & 23 deletions .devcontainer/install/__65-generate-file-vscode-launch-json.sh__

This file was deleted.

2 changes: 1 addition & 1 deletion .devcontainer/templates/app-python/config/launch.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[
{
"name": "Execute module '{project_name}'",
"type": "python",
"type": "debugpy",
"request": "launch",
"module": "{project_name}"
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
[
"ms-azuretools.vscode-azurefunctions",
"ms-python.python"
]
[]
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[
{
"name": "Attach to Python Functions: {project_name}",
"type": "python",
"type": "debugpy",
"request": "attach",
"port": 9091,
"preLaunchTask": "Azure Function - Start: {project_name}",
Expand Down
2 changes: 1 addition & 1 deletion .devcontainer/templates/default/config/launch.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[
{
"name": "Python: File",
"type": "python",
"type": "debugpy",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,21 @@

# Duplicate configuration example file

Before you begin, you need to rename the file named *'devcontainer.json-example'* located in the *'.devcontainer/'* directory to *'devcontainer.json'*.
Before you begin, you need to create a *'devcontainer.json'* file and a *'Dockerfile'* file in the directory *'.devcontainer/'*.

If you want to create a python application, you need to copy/paste the following files into the directory: *'.devcontainer/'*.

```
.devcontainer/templates/app-python/devcontainer.json
.devcontainer/templates/app-python/Dockerfile
```

If you want to create an application based on Azure Functions, you must copy/paste the following files into the directory: *'.devcontainer/'*:

```
.devcontainer/templates/azure-function-python/devcontainer.json
.devcontainer/templates/azure-function-python/Dockerfile
```

The new tree should look like :

Expand All @@ -15,6 +29,8 @@ The new tree should look like :
└── install.sh
````
Now we will mainly modify this file.
###### **▶ Next step: [Configure a packaging and dependency manager](./02-configure-packaging-dependency-manager.md)**

0 comments on commit 8346942

Please sign in to comment.