Skip to content

Error parsing env variable containing dashes in .env file #887

Closed as not planned

Description

Hello,

Summary

I'm having a bug when using VSCode's terminal to start a flask application because my .env file has a environment variable that starts with dashes.

The problem

When editing my .env file the Python Environment extensions prompted me to use the python.terminal.useEnvFile setting to use the .env files to update my shell's environment, sure, why not? I activated it.

I'm building a flask application with gunicorn and needed to pass configuration flags for gunicorn using the GUNICORN_CMD_ARGS flag. I got an error when trying to run the project with uv:

> uv run --env-file .env gunicorn example_api.main:app
access_log_format                  = %(h)s %(l)s %(u)s %(t)s "%(r)s" %(s)s %(b)s "%(f)s" "%(a)s"
accesslog                          = None
backlog                            = 2048
bind                               = ['ind=0.0.0.0:8080'] <------
ca_certs                           = None
capture_output                     = False
...

As you can see, the bind parameter is wrong, even though my .env file looks like this:

GUNICORN_CMD_ARGS="--bind=0.0.0.0:8080 --workers=1 --forwarded-allow-ips='*' --print-config"

I started thinking it was an issue with uv run when using with its --env-file flag, and even opened an issue for them (astral-sh/uv#16107), because it worked when passing the env variable inline:

> GUNICORN_CMD_ARGS="--bind=0.0.0.0:8080 --workers=1 --forwarded-allow-ips='*' --print-config" uv run --env-file .env gunicorn example_api.main:app
access_log_format                  = %(h)s %(l)s %(u)s %(t)s "%(r)s" %(s)s %(b)s "%(f)s" "%(a)s"
accesslog                          = None
backlog                            = 2048
bind                               = ['0.0.0.0:8080'] <-----
ca_certs                           = None
capture_output                     = False
...

I tried the same commands using another terminal outside of VSCode and it worked as expected, which lead me to remember I had activated the setting some hours before.

The extension was incorrectly parsing the .env file when using a environment variable that starts with dashes.

Another question

The extension is overriding my environment variables even though i'm using the --env-file in the uv run command. Is this the intended behaviour?

Reproducible example

  • Activate python.terminal.useEnvFile first
  • Save the following .env file inside VSCode so the extension notices it changed
GUNICORN_CMD_ARGS="--bind=0.0.0.0:8080 --workers=1 --forwarded-allow-ips='*' --print-config"
  • example_app.py
from flask import Flask
app = Flask(__name__)

@app.get("/")
def main():
    return "ok"
  • pyproject.toml
[project]
name = "example_app"
version = "0.0.1"
requires-python = ">=3.12"
dependencies = ["flask", "gunicorn"]

Run inside a VSCode terminal with python.terminal.useEnvFile activated:

> uv install
> uv run --env-file .env gunicorn example_app:app

Information:

  • uv --version: 0.8.22
  • gunicorn --version: 23.0.0
  • python3 --version: 3.12.8
  • echo $SHELL: zsh 5.8.1
  • ubuntu 22.04
  • code --version: 1.104.2
  • Python Environments: 1.8.0

Activity

  1. eleanorjboyd commented on Oct 3, 2025

    @eleanorjboyd
    Contributor

    Thank you! Will investigate

  2. eleanorjboyd commented on Oct 3, 2025

    @eleanorjboyd
    Contributor

    gave this a try and seeing the env variable look right even when it starts with a dash (also tried it with multiple args with spaces in between).

    If you try to just echo the vars you set, what do you see? Also are you running htis straight from the terminal uv run --env-file .env gunicorn example_app:app? Curious if you need to specify the env-file in the running args given it should already be injected

    Image
  3. github-actions commented on Oct 18, 2025

    @github-actions

    Because we have not heard back with the information we requested, we are closing this issue for now. If you are able to provide the info later on, then we will be happy to re-open this issue to pick up where we left off.

    Happy Coding!

  4. locked as resolved and limited conversation to collaborators on Apr 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions