0

EDIT: My flaw when deploying to Azure was that I was not saving the new Application settings I was introducing facepalm. Saving PIP_EXTRA_INDEX_URL=https://<token>@raw.githubusercontent.com/<gituser> allows pip to finally install my private library.

However, it still doesn't work when locally debugging with F5 on VSCode, regardless of my local.settings.json. Below I'll describe the hack that makes it work locally, but I would prefer to resolve why it doesn't work from my local settings.

My requirements.txt indicates the private library as <package_name> @ https://raw.githubusercontent.com/<gituser>/<repo>/<branch>/dist/<package_name>0.1.11-py3-none-any.whl. Based on the fact that adding an PIP_EXTRA_INDEX_URL in Azure allows the deployment, I am trying to imitate that in my local.settings.json:

{
  "IsEncrypted": false,
  "Values": {
    ...
    "PIP_EXTRA_INDEX_URL": "https://<token>@raw.githubusercontent.com/<gituser>",
    ...
  }
}

However, I get a 404 error when the Azure's pip tries to install from requirements.txt.

Locally, in tasks.json, if I set that env var before I run pip install, the F5 starts working:

{
    "version": "2.0.0",
    "tasks": [
        {
            "type": "func",
            "command": "host start",
            "problemMatcher": "$func-python-watch",
            "isBackground": true,
            "dependsOn": "pip install (functions)"
        },
        {
            "label": "pip install (functions)",
            "type": "shell",
            "osx": {
            ...
            "windows": {
                "command": "$env:PIP_EXTRA_INDEX_URL = 'https://<token>@raw.githubusercontent.com/<gituser>'; ${config:azureFunctions.pythonVenv}\\Scripts\\python -m pip install -r requirements.txt"
            },
            ...
        }
    ]
}

In other words, my F5 is not reading the env var from local.settings.json before the pip install task runs (note that the function itself is properly receiving the env vars as evidenced by successful os.environ[] calls). Also note that locally it does work if I set the env var in tasks.json, which is not ideal. I prefer my local.settings.json to mirror my Application settings on Azure.

Salazaja
  • 101
  • 1
  • 9
  • Are you loading local.settings.json when azure function app starts? You need to load it manually. By default az func is not loading it. Here is an example mentioned: https://stackoverflow.com/questions/27382481/why-does-visual-studio-tell-me-that-the-addjsonfile-method-is-not-defined – MarekB May 11 '22 at 13:09
  • Thanks @MarekB for the reply. No I am not loading local.settings.json manually. Didn't think I needed to since os.environ[] reads it fine in __init__.py. Sorry, I'm not able to draw a parallel between your linked example (C#) and mine (Python). For example, there's a mention of project.json, which my project lacks. In my .vscode folder I have 4 json files, not sure if it's one of those. Could you please describe how I can load local.settings.json? – Salazaja May 11 '22 at 13:45
  • Ah, my bad. I totally ignored the fact that you're using pyhon :D Forgive me, please ignore my above comment. – MarekB May 11 '22 at 13:58

1 Answers1

1

In this issue it has been confirmed that this is expected behavior and that my workaround is valid:

"local.settings.json" is unique to core tools and thus only applies during the func start command. Since "pip install" happen before func start, you would have to set the env var elsewhere (and yes tasks.json is a good place).

Salazaja
  • 101
  • 1
  • 9