Отладка нескольких Python Azure -функций локально в VS Code - PullRequest
1 голос
/ 16 апреля 2020

Я следовал этому руководству по Microsoft , используя CLI для создания Azure -функции в python.

Затем я создал вторую функцию, обе HttpTriggered.

C:\Users\rnwol\workspace\anotherazfunc
├── host.json
└── LocalFunctionProj
   ├── host.json
   ├── HttpCONTACT
   |  ├── function.json
   |  ├── host.json
   |  ├── __init__.py
   |  └── __pycache__
   ├── HttpRNWOLF
   |  ├── function.json
   |  ├── __init__.py
   |  └── __pycache__
   ├── local.settings.json
   └── requirements.txt

В терминале Powershell я могу запускать обе функции следующим образом ...

(.venv) C:\Users\rnwol\workspace\anotherazfunc\LocalFunctionProj> func host start
Found Python version 3.8.2 (python).

                  %%%%%%
                 %%%%%%
            @   %%%%%%    @
          @@   %%%%%%      @@
       @@@    %%%%%%%%%%%    @@@
     @@      %%%%%%%%%%        @@
       @@         %%%%       @@
         @@      %%%       @@
           @@    %%      @@
                %%
                %

Azure Functions Core Tools (3.0.2245 Commit hash: 1d094e2f3ef79b9a478a1621ea7ec3f93ac1910d)
Function Runtime Version: 3.0.13139.0
[15/04/2020 20:43:27] FUNCTIONS_WORKER_RUNTIME set to python. Skipping WorkerConfig for language:java
[15/04/2020 20:43:27] FUNCTIONS_WORKER_RUNTIME set to python. Skipping WorkerConfig for language:node
[15/04/2020 20:43:27] FUNCTIONS_WORKER_RUNTIME set to python. Skipping WorkerConfig for language:powershell
[15/04/2020 20:43:28] Building host: startup suppressed: 'False', configuration suppressed: 'False', startup operation id: '21466b21-c6d0-4a25-9df4-61b42b364bef'
[15/04/2020 20:43:28] Reading host configuration file 'C:\Users\rnwol\workspace\anotherazfunc\LocalFunctionProj\host.json'
[15/04/2020 20:43:28] Host configuration file read:
[15/04/2020 20:43:28] {
[15/04/2020 20:43:28]   "version": "2.0",
[15/04/2020 20:43:28]   "extensionBundle": {
[15/04/2020 20:43:28]     "id": "Microsoft.Azure.Functions.ExtensionBundle",
[15/04/2020 20:43:28]     "version": "[1.*, 2.0.0)"
[15/04/2020 20:43:28]   }
[15/04/2020 20:43:28] }
[15/04/2020 20:43:28] Reading functions metadata
[15/04/2020 20:43:28] 2 functions found
...

Я могу использовать http ie для запуска обеих функций по мере необходимости.

THE ПРОБЛЕМА - Как интерактивно отлаживать в VS-коде?

Когда я сейчас открываю файлы в VS Code для одной функции, я могу затем нажать F5, чтобы запустить команду для отладки и пройти через событие Trigger и выясните, в чем проблема.

Какую конфигурацию мне следует использовать для запуска обеих функций, чтобы я мог устанавливать точки останова и интерактивно отлаживать в VS-коде? Я использую Windows 10.

Направление для решения

Я настроил образец шаблона github repo https://github.com/rnwolf/azure-func-python-layout с результатами моего исследования, которые вы могли бы использовать в качестве стартера для ваших Azure функций.

Схема, которая работает для меня, приведена ниже. Обязательно откройте VSCode в каталоге root, multi3, в приведенном ниже примере. Я обнаружил, что вы можете удалить .vscode и .vstest, а затем VSCode выясняет, как установить некоторые допустимые значения по умолчанию.

(.venv) ...orkspace/multi3$ tree -L 3 -a
.
├── .coverage
├── .coveragerc
├── .flake8
├── .git
├── .github
│   └── workflows
│       └── main.yml
├── .gitignore
├── .hypothesis
├── .pre-commit-config.yaml
├── .pylintrc
├── .python-version
├── .venv
│   ├── COPYING
│   ├── COPYING.GPL
│   ├── bin
│   │   ├── Activate.ps1
│   │   ├── activate
│   │   ├── activate.csh
│   │   ├── activate.fish
│   │   ├── autopep8-wrapper
│   │   ├── bandit
│   │   ├── bandit-baseline
│   │   ├── bandit-config-generator
│   │   ├── black
│   │   ├── blackd
│   │   ├── chardetect
│   │   ├── check-added-large-files
│   │   ├── check-ast
│   │   ├── check-builtin-literals
│   │   ├── check-byte-order-marker
│   │   ├── check-case-conflict
│   │   ├── check-docstring-first
│   │   ├── check-executables-have-shebangs
│   │   ├── check-json
│   │   ├── check-merge-conflict
│   │   ├── check-symlinks
│   │   ├── check-toml
│   │   ├── check-vcs-permalinks
│   │   ├── check-xml
│   │   ├── check-yaml
│   │   ├── coverage
│   │   ├── coverage-3.8
│   │   ├── coverage3
│   │   ├── debug-statement-hook
│   │   ├── detect-aws-credentials
│   │   ├── detect-private-key
│   │   ├── dmypy
│   │   ├── double-quote-string-fixer
│   │   ├── easy_install
│   │   ├── easy_install-3.8
│   │   ├── end-of-file-fixer
│   │   ├── epylint
│   │   ├── file-contents-sorter
│   │   ├── fix-encoding-pragma
│   │   ├── flake8
│   │   ├── forbid-new-submodules
│   │   ├── http
│   │   ├── https
│   │   ├── identify-cli
│   │   ├── isort
│   │   ├── mixed-line-ending
│   │   ├── mypy
│   │   ├── mypyc
│   │   ├── name-tests-test
│   │   ├── no-commit-to-branch
│   │   ├── nodeenv
│   │   ├── pbr
│   │   ├── pip
│   │   ├── pip-compile
│   │   ├── pip-sync
│   │   ├── pip3
│   │   ├── pip3.8
│   │   ├── pipenv
│   │   ├── pipenv-resolver
│   │   ├── pre-commit
│   │   ├── pre-commit-validate-config
│   │   ├── pre-commit-validate-manifest
│   │   ├── pretty-format-json
│   │   ├── py.test
│   │   ├── pycodestyle
│   │   ├── pydocstyle
│   │   ├── pyflakes
│   │   ├── pygmentize
│   │   ├── pylint
│   │   ├── pyreverse
│   │   ├── pytest
│   │   ├── python -> /home/rnwolf/.pyenv/versions/3.8.2/bin/python
│   │   ├── python3 -> python
│   │   ├── requirements-txt-fixer
│   │   ├── safety
│   │   ├── sort-simple-yaml
│   │   ├── stubgen
│   │   ├── stubtest
│   │   ├── symilar
│   │   ├── trailing-whitespace-fixer
│   │   ├── virtualenv
│   │   └── virtualenv-clone
│   ├── include
│   ├── lib
│   │   └── python3.8
│   ├── lib64 -> lib
│   └── pyvenv.cfg
├── .vscode
│   ├── .ropeproject
│   │   └── config.py
│   ├── extensions.json
│   ├── launch.json
│   ├── settings.json
│   └── tasks.json
├── .vstest
│   ├── extensions.json
│   ├── launch.json
│   ├── settings.json
│   └── tasks.json
├── Create .venv pythonvirtual env here.txt
├── LICENSE.md
├── README.md
├── __app__
│   ├── .funcignore
│   ├── .python_packages
│   ├── __init__.py
│   ├── conftest.py
│   ├── host.json
│   ├── http_trigger_1
│   │   ├── __init__.py
│   │   ├── __pycache__
│   │   └── function.json
│   ├── http_trigger_2
│   │   ├── __init__.py
│   │   ├── __pycache__
│   │   └── function.json
│   ├── local.settings.SAMPLE.json
│   ├── requirements.txt
│   └── sharedcode
│       ├── __init__.py
│       ├── __pycache__
│       └── my_helper_functions.py
├── dev-requirements.in
├── dev-requirements.txt
├── mypy.ini
├── pytest.ini
└── tests
    ├── .pylintrc
    ├── __init__.py
    ├── testHttpTrigger1.http
    ├── testHttpTrigger2.http
    ├── test_http_trigger_1.py
    └── test_http_trigger_2.py

1 Ответ

0 голосов
/ 16 апреля 2020

В вашем случае запуск f5 запускает две функции. Вам необходимо отправить запрос на соответствующий URL-адрес go в logi c при отладке этих двух функций. Когда вы используете f5 на уровне functionapp, все триггеры запускаются и находятся в состоянии ожидания триггера.

Вы можете создать несколько точек останова в логах триггера c, которые вам нужно отладить, и затем удовлетворить его метод запуска.

enter image description here

Например, если у вас два триггера http, и вы хотите отладить httptrigger1. Вы можете создать в нем некоторую точку останова и затем запустить f5. После этого отправьте запрос на соответствующий URL, а затем используйте f8 (продолжить) для отладки.

Это мой запуск. json:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Attach to Python Functions",
            "type": "python",
            "request": "attach",
            "port": 9091,
            "preLaunchTask": "func: host start"
        }
    ]
}

Это настройки. json:

{
    "azureFunctions.deploySubpath": ".",
    "azureFunctions.scmDoBuildDuringDeployment": true,
    "azureFunctions.pythonVenv": ".venv",
    "azureFunctions.projectLanguage": "Python",
    "azureFunctions.projectRuntime": "~2",
    "debug.internalConsoleOptions": "neverOpen",
    "python.pythonPath": ".venv\\Scripts\\python.exe"
}

И это мои задачи. json:

{
    "version": "2.0.0",
    "tasks": [
        {
            "type": "func",
            "command": "host start",
            "problemMatcher": "$func-watch",
            "isBackground": true,
            "dependsOn": "pipInstall"
        },
        {
            "label": "pipInstall",
            "type": "shell",
            "osx": {
                "command": "${config:azureFunctions.pythonVenv}/bin/python -m pip install -r requirements.txt"
            },
            "windows": {
                "command": "${config:azureFunctions.pythonVenv}\\Scripts\\python -m pip install -r requirements.txt"
            },
            "linux": {
                "command": "${config:azureFunctions.pythonVenv}/bin/python -m pip install -r requirements.txt"
            },
            "problemMatcher": []
        }
    ]
}
...