Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Changed

- The `dotenv` console script is no longer installed with the base package. A
conda/venv `python-dotenv` without `[cli]` was dropping a stub `dotenv` on
`PATH` that hid a working user-level `[cli]` install. Run the CLI with
`python -m dotenv` after `pip install "python-dotenv[cli]"`. ([#683](https://github.com/theskumar/python-dotenv/issues/683))

### Fixed

- An unquoted empty value followed by an inline comment (e.g. `KEY= # comment`) is now parsed as an empty string instead of the comment text by [@Noethix55555] in [#663]
Expand Down
17 changes: 9 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,25 +146,26 @@ production.

## Command-line Interface

A CLI interface `dotenv` is also included, which helps you manipulate the `.env`
file without manually opening it.
Install the `[cli]` extra and run it as a module. The package no longer
installs a `dotenv` console script, so a bare install cannot shadow another
environment's CLI.

```shell
$ pip install "python-dotenv[cli]"
$ dotenv set USER foo
$ dotenv set EMAIL foo@example.org
$ dotenv list
$ python -m dotenv set USER foo
$ python -m dotenv set EMAIL foo@example.org
$ python -m dotenv list
USER=foo
EMAIL=foo@example.org
$ dotenv list --format=json
$ python -m dotenv list --format=json
{
"USER": "foo",
"EMAIL": "foo@example.org"
}
$ dotenv run -- python foo.py
$ python -m dotenv run -- python foo.py
```

Run `dotenv --help` for more information about the options and subcommands.
Run `python -m dotenv --help` for more information about the options and subcommands.

## File format

Expand Down
3 changes: 0 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,6 @@ cli = [
"click>=5.0",
]

[project.scripts]
dotenv = "dotenv.__main__:cli"

[tool.setuptools]
packages = ["dotenv"]
package-dir = {"" = "src"}
Expand Down
2 changes: 1 addition & 1 deletion src/dotenv/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
from .cli import cli

if __name__ == "__main__":
cli()
cli(prog_name="dotenv")
12 changes: 10 additions & 2 deletions tests/test_lib.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import os
import subprocess
import sys
from pathlib import Path
from typing import Sequence

_SRC = str(Path(__file__).resolve().parents[1] / "src")


def run_dotenv(
args: Sequence[str],
Expand All @@ -12,12 +16,16 @@ def run_dotenv(
Run the `dotenv` CLI in a subprocess with the given arguments.
"""

run_env = {**os.environ, **(env or {})}
existing = run_env.get("PYTHONPATH", "")
run_env["PYTHONPATH"] = _SRC if not existing else f"{_SRC}{os.pathsep}{existing}"

process = subprocess.run(
["dotenv", *args],
[sys.executable, "-m", "dotenv", *args],
capture_output=True,
text=True,
cwd=cwd,
env=env,
env=run_env,
)

return process
Expand Down